diff --git a/Cargo.lock b/Cargo.lock index 76c15ad699..39efea9d81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2069,6 +2069,19 @@ dependencies = [ "byteorder", ] +[[package]] +name = "generator" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1d9279ca822891c1a4dae06d185612cf8fc6acfe5dff37781b41297811b12ee" +dependencies = [ + "cc", + "libc", + "log", + "rustversion", + "winapi 0.3.9", +] + [[package]] name = "generic-array" version = "0.12.4" @@ -3152,6 +3165,19 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "loom" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edc5c7d328e32cc4954e8e01193d7f0ef5ab257b5090b70a964e099a36034309" +dependencies = [ + "cfg-if 1.0.0", + "generator", + "scoped-tls", + "tracing", + "tracing-subscriber", +] + [[package]] name = "loupe" version = "0.1.3" @@ -4471,9 +4497,9 @@ dependencies = [ [[package]] name = "profiling" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9145ac0af1d93c638c98c40cf7d25665f427b2a44ad0a99b1dccf3e2f25bb987" +checksum = "2f61dcf0b917cd75d4521d7343d1ffff3d1583054133c9b5cbea3375c703c40d" dependencies = [ "profiling-procmacros", "tracy-client", @@ -4481,9 +4507,9 @@ dependencies = [ [[package]] name = "profiling-procmacros" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "151b4774158c69aae073abb06d0cf879c4657966e6f2d7535d9b0e94e85500af" +checksum = "98eee3c112f2a6f784b6713fe1d7fb7d6506e066121c0a49371fdb976f72bae5" dependencies = [ "quote 1.0.17", "syn 1.0.90", @@ -6242,9 +6268,9 @@ dependencies = [ [[package]] name = "tracing-tracy" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773057bb2b440e868776522a0587f732b1125116f12aca0eb37dea48d55ad2cd" +checksum = "23a42311a35ed976d72f359de43e9fe028ec9d9f1051c4c52bd05a4f66ff3cbf" dependencies = [ "tracing-core", "tracing-subscriber", @@ -6253,19 +6279,20 @@ dependencies = [ [[package]] name = "tracy-client" -version = "0.12.7" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffcb26a0c786a0e154afdf21284969ff23759f42f156bcfddddae1a3c2404f2" +checksum = "42ebfe7a24c18b5ba86d8920c124b41b942352f863fbe0c84d3d63428fa1860f" dependencies = [ + "loom", "once_cell", "tracy-client-sys", ] [[package]] name = "tracy-client-sys" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6226e4e77f0d46ce7ebb0a4b1daa82790035248b75bbf605b932a1d7b3b22b6d" +checksum = "9012b9dfeccaff16e93f5a8b02336125113a80a769902e679d334cbdd4d83f3b" dependencies = [ "cc", ] diff --git a/common/base/Cargo.toml b/common/base/Cargo.toml index 96b3aa3ae8..fc79ae9d20 100644 --- a/common/base/Cargo.toml +++ b/common/base/Cargo.toml @@ -13,4 +13,4 @@ tracing = { version = "0.1", default-features = false } directories-next = "2.0" # Tracy -tracy-client = { version = "0.12.0", optional = true } +tracy-client = { version = "0.13.1", optional = true } diff --git a/common/base/src/lib.rs b/common/base/src/lib.rs index 5c78484061..098d881849 100644 --- a/common/base/src/lib.rs +++ b/common/base/src/lib.rs @@ -4,30 +4,6 @@ pub mod userdata_dir; pub use userdata_dir::userdata_dir; -#[cfg(feature = "tracy")] pub use tracy_client; - -/// Allows downstream crates to conditionally do things based on whether tracy -/// is enabled without having to expose a cargo feature themselves. -pub const TRACY_ENABLED: bool = cfg!(feature = "tracy"); - -#[cfg(not(feature = "tracy"))] -#[macro_export] -macro_rules! plot { - ($name:expr, $value:expr) => { - // type check - let _: f64 = $value; - }; -} -#[cfg(feature = "tracy")] -#[macro_export] -macro_rules! plot { - ($name:expr, $value:expr) => {{ - use $crate::tracy_client::{create_plot, Plot}; - static PLOT: Plot = create_plot!($name); - PLOT.point($value); - }}; -} - // Panic in debug or tests, warn in release #[macro_export] macro_rules! dev_panic { @@ -49,6 +25,24 @@ macro_rules! dev_panic { }; } +#[cfg(feature = "tracy")] pub use tracy_client; + +/// Allows downstream crates to conditionally do things based on whether tracy +/// is enabled without having to expose a cargo feature themselves. +pub const TRACY_ENABLED: bool = cfg!(feature = "tracy"); + +#[cfg(not(feature = "tracy"))] +#[macro_export] +macro_rules! plot { + ($name:expr, $value:expr) => { + // type check + let _: f64 = $value; + }; +} + +#[cfg(feature = "tracy")] +pub use tracy_client::plot; + // https://discordapp.com/channels/676678179678715904/676685797524766720/723358438943621151 #[cfg(not(feature = "tracy"))] #[macro_export] @@ -83,52 +77,33 @@ macro_rules! span { }; ($guard_name:tt, $name:expr) => { // Directly use `tracy_client` to decrease overhead for better timing - let $guard_name = $crate::tracy_client::Span::new( - $name, - "", - module_path!(), - line!(), - // No callstack since this has significant overhead - 0, - ); + $crate::prof_span_alloc!($guard_name, $name); }; ($guard_name:tt, $no_tracy_name:expr, $tracy_name:expr) => { $crate::span!($guard_name, $tracy_name); }; } -#[cfg(feature = "tracy")] -pub struct ProfSpan(pub tracy_client::Span); #[cfg(not(feature = "tracy"))] pub struct ProfSpan; -/// Like the span macro but only used when profiling and not in regular tracing -/// operations -#[macro_export] +/// Just implemented so that we dont need to have +/// #[allow(clippy::drop_non_drop)] everywhere #[cfg(not(feature = "tracy"))] -macro_rules! prof_span { - ($guard_name:tt, $name:expr) => { - let $guard_name = $crate::ProfSpan; - }; - // Shorthand for when you want the guard to just be dropped at the end of the scope instead - // of controlling it manually - ($name:expr) => {}; +impl Drop for ProfSpan { + fn drop(&mut self) {} } +#[cfg(feature = "tracy")] +pub struct ProfSpan(pub tracy_client::Span); + /// Like the span macro but only used when profiling and not in regular tracing /// operations +#[cfg(not(feature = "tracy"))] #[macro_export] -#[cfg(feature = "tracy")] macro_rules! prof_span { ($guard_name:tt, $name:expr) => { - let $guard_name = $crate::ProfSpan($crate::tracy_client::Span::new( - $name, - "", - module_path!(), - line!(), - // No callstack since this has significant overhead - 0, - )); + let $guard_name = $crate::ProfSpan; }; // Shorthand for when you want the guard to just be dropped at the end of the scope instead // of controlling it manually @@ -137,51 +112,58 @@ macro_rules! prof_span { }; } -/// There's no guard, but really this is actually the guard -pub struct GuardlessSpan { - span: tracing::Span, - subscriber: tracing::Dispatch, -} - -impl GuardlessSpan { - pub fn new(span: tracing::Span) -> Self { - let subscriber = tracing::dispatcher::get_default(|d| d.clone()); - if let Some(id) = span.id() { - subscriber.enter(&id) - } - Self { span, subscriber } - } -} - -impl Drop for GuardlessSpan { - fn drop(&mut self) { - if let Some(id) = self.span.id() { - self.subscriber.exit(&id) - } - } -} - -/// Just implemented so that we dont need to have -/// #[allow(clippy::drop_non_drop)] everywhere -impl Drop for ProfSpan { - fn drop(&mut self) {} -} - +/// Like the span macro but only used when profiling and not in regular tracing +/// operations +#[cfg(feature = "tracy")] #[macro_export] -macro_rules! no_guard_span { - ($level:ident, $name:expr, $($fields:tt)*) => { - GuardlessSpan::new( - tracing::span!(tracing::Level::$level, $name, $($fields)*) - ) - }; - ($level:ident, $name:expr) => { - GuardlessSpan::new( - tracing::span!(tracing::Level::$level, $name) - ) +macro_rules! prof_span { + ($guard_name:tt, $name:expr) => { + let $guard_name = $crate::ProfSpan( + // No callstack since this has significant overhead + $crate::tracy_client::span!($name, 0), + ); }; + // Shorthand for when you want the guard to just be dropped at the end of the scope instead + // of controlling it manually ($name:expr) => { - GuardlessSpan::new( - tracing::span!(tracing::Level::TRACE, $name) - ) + $crate::prof_span!(_guard, $name); + }; +} + +/// Like the prof_span macro but this one allocates so it can use strings only +/// known at runtime. +#[cfg(not(feature = "tracy"))] +#[macro_export] +macro_rules! prof_span_alloc { + ($guard_name:tt, $name:expr) => { + let $guard_name = $crate::ProfSpan; + }; + // Shorthand for when you want the guard to just be dropped at the end of the scope instead + // of controlling it manually + ($name:expr) => { + $crate::prof_span!(_guard, $name); + }; +} + +/// Like the prof_span macro but this one allocates so it can use strings only +/// known at runtime. +#[cfg(feature = "tracy")] +#[macro_export] +macro_rules! prof_span_alloc { + ($guard_name:tt, $name:expr) => { + let $guard_name = $crate::ProfSpan({ + struct S; + let type_name = core::any::type_name::(); + let function_name = &type_name[..type_name.len() - 3]; + $crate::tracy_client::Client::running() + .expect("prof_span_alloc! without a running tracy_client::Client") + // No callstack since this has significant overhead + .span_alloc($name, function_name, file!(), line!(), 0) + }); + }; + // Shorthand for when you want the guard to just be dropped at the end of the scope instead + // of controlling it manually + ($name:expr) => { + $crate::prof_span!(_guard, $name); }; } diff --git a/common/frontend/Cargo.toml b/common/frontend/Cargo.toml index 32e5690f4a..e123a8ca7a 100644 --- a/common/frontend/Cargo.toml +++ b/common/frontend/Cargo.toml @@ -19,4 +19,4 @@ tracing-log = "0.1.1" tracing-subscriber = { version = "0.3.7", default-features = false, features = ["env-filter", "fmt", "time", "ansi", "smallvec", "tracing-log"]} # Tracy -tracing-tracy = { version = "0.8.0", optional = true } +tracing-tracy = { version = "0.9.0", optional = true } diff --git a/common/src/slowjob.rs b/common/src/slowjob.rs index a1f613b21e..414d4888f8 100644 --- a/common/src/slowjob.rs +++ b/common/src/slowjob.rs @@ -98,7 +98,7 @@ impl Queue { id, name: name.to_owned(), task: Box::new(move || { - common_base::prof_span!(_guard, &name_cloned); + common_base::prof_span_alloc!(_guard, &name_cloned); let execution_start = Instant::now(); f(); let execution_end = Instant::now(); diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index 8b03b7eb0b..8d1fb66349 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -32,6 +32,9 @@ lazy_static::lazy_static! { const TPS: u64 = 30; fn main() -> io::Result<()> { + #[cfg(feature = "tracy")] + common_base::tracy_client::Client::start(); + use clap::Parser; let app = ArgvApp::parse(); @@ -268,7 +271,7 @@ fn main() -> io::Result<()> { // Wait for the next tick. clock.tick(); #[cfg(feature = "tracy")] - common_base::tracy_client::finish_continuous_frame!(); + common_base::tracy_client::frame_mark(); } Ok(()) diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index a0915f4dbb..6e1e2882cd 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -127,7 +127,7 @@ itertools = "0.10.0" # Tracy tracing = "0.1" -profiling = { version = "1.0.1", default-features = false, optional = true } +profiling = { version = "1.0.6", default-features = false, optional = true } [target.'cfg(target_os = "macos")'.dependencies] dispatch = "0.1.4" diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 1deb42e272..f7e57e9a9b 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -29,6 +29,9 @@ use tracing::{error, info, warn}; use veloren_voxygen::ui::egui::EguiState; fn main() { + #[cfg(feature = "tracy")] + common_base::tracy_client::Client::start(); + let userdata_dir = common_base::userdata_dir_workspace!(); // Determine where Voxygen's logs should go diff --git a/voxygen/src/run.rs b/voxygen/src/run.rs index ffdac0905a..a3d57ce4f4 100644 --- a/voxygen/src/run.rs +++ b/voxygen/src/run.rs @@ -5,7 +5,7 @@ use crate::{ window::{Event, EventLoop}, Direction, GlobalState, PlayState, PlayStateResult, }; -use common_base::{no_guard_span, span, GuardlessSpan}; +use common_base::{prof_span, span}; use std::{mem, time::Duration}; use tracing::debug; @@ -71,7 +71,8 @@ pub fn run(mut global_state: GlobalState, event_loop: EventLoop) { match event { winit::event::Event::NewEvents(_) => { - event_span = Some(no_guard_span!("Process Events")); + prof_span!(span, "Process Events"); + event_span = Some(span); }, winit::event::Event::MainEventsCleared => { event_span.take(); @@ -79,7 +80,8 @@ pub fn run(mut global_state: GlobalState, event_loop: EventLoop) { if polled_twice { handle_main_events_cleared(&mut states, control_flow, &mut global_state); } - poll_span = Some(no_guard_span!("Poll Winit")); + prof_span!(span, "Poll Winit"); + poll_span = Some(span); polled_twice = !polled_twice; }, winit::event::Event::WindowEvent { event, .. } => { @@ -252,7 +254,7 @@ fn handle_main_events_cleared( global_state.clock.tick(); drop(guard); #[cfg(feature = "tracy")] - common_base::tracy_client::finish_continuous_frame!(); + common_base::tracy_client::frame_mark(); // Maintain global state. global_state.maintain(global_state.clock.dt());