Update tracy

This commit is contained in:
Imbris 2022-05-10 03:28:13 -04:00
parent 2f7678582b
commit a366fc4512
9 changed files with 132 additions and 115 deletions

47
Cargo.lock generated
View File

@ -2069,6 +2069,19 @@ dependencies = [
"byteorder", "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]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.12.4" version = "0.12.4"
@ -3152,6 +3165,19 @@ dependencies = [
"cfg-if 1.0.0", "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]] [[package]]
name = "loupe" name = "loupe"
version = "0.1.3" version = "0.1.3"
@ -4471,9 +4497,9 @@ dependencies = [
[[package]] [[package]]
name = "profiling" name = "profiling"
version = "1.0.5" version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9145ac0af1d93c638c98c40cf7d25665f427b2a44ad0a99b1dccf3e2f25bb987" checksum = "2f61dcf0b917cd75d4521d7343d1ffff3d1583054133c9b5cbea3375c703c40d"
dependencies = [ dependencies = [
"profiling-procmacros", "profiling-procmacros",
"tracy-client", "tracy-client",
@ -4481,9 +4507,9 @@ dependencies = [
[[package]] [[package]]
name = "profiling-procmacros" name = "profiling-procmacros"
version = "1.0.5" version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "151b4774158c69aae073abb06d0cf879c4657966e6f2d7535d9b0e94e85500af" checksum = "98eee3c112f2a6f784b6713fe1d7fb7d6506e066121c0a49371fdb976f72bae5"
dependencies = [ dependencies = [
"quote 1.0.17", "quote 1.0.17",
"syn 1.0.90", "syn 1.0.90",
@ -6242,9 +6268,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-tracy" name = "tracing-tracy"
version = "0.8.0" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773057bb2b440e868776522a0587f732b1125116f12aca0eb37dea48d55ad2cd" checksum = "23a42311a35ed976d72f359de43e9fe028ec9d9f1051c4c52bd05a4f66ff3cbf"
dependencies = [ dependencies = [
"tracing-core", "tracing-core",
"tracing-subscriber", "tracing-subscriber",
@ -6253,19 +6279,20 @@ dependencies = [
[[package]] [[package]]
name = "tracy-client" name = "tracy-client"
version = "0.12.7" version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dffcb26a0c786a0e154afdf21284969ff23759f42f156bcfddddae1a3c2404f2" checksum = "42ebfe7a24c18b5ba86d8920c124b41b942352f863fbe0c84d3d63428fa1860f"
dependencies = [ dependencies = [
"loom",
"once_cell", "once_cell",
"tracy-client-sys", "tracy-client-sys",
] ]
[[package]] [[package]]
name = "tracy-client-sys" name = "tracy-client-sys"
version = "0.16.0" version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6226e4e77f0d46ce7ebb0a4b1daa82790035248b75bbf605b932a1d7b3b22b6d" checksum = "9012b9dfeccaff16e93f5a8b02336125113a80a769902e679d334cbdd4d83f3b"
dependencies = [ dependencies = [
"cc", "cc",
] ]

View File

@ -13,4 +13,4 @@ tracing = { version = "0.1", default-features = false }
directories-next = "2.0" directories-next = "2.0"
# Tracy # Tracy
tracy-client = { version = "0.12.0", optional = true } tracy-client = { version = "0.13.1", optional = true }

View File

@ -4,30 +4,6 @@ pub mod userdata_dir;
pub use userdata_dir::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 // Panic in debug or tests, warn in release
#[macro_export] #[macro_export]
macro_rules! dev_panic { 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 // https://discordapp.com/channels/676678179678715904/676685797524766720/723358438943621151
#[cfg(not(feature = "tracy"))] #[cfg(not(feature = "tracy"))]
#[macro_export] #[macro_export]
@ -83,52 +77,33 @@ macro_rules! span {
}; };
($guard_name:tt, $name:expr) => { ($guard_name:tt, $name:expr) => {
// Directly use `tracy_client` to decrease overhead for better timing // Directly use `tracy_client` to decrease overhead for better timing
let $guard_name = $crate::tracy_client::Span::new( $crate::prof_span_alloc!($guard_name, $name);
$name,
"",
module_path!(),
line!(),
// No callstack since this has significant overhead
0,
);
}; };
($guard_name:tt, $no_tracy_name:expr, $tracy_name:expr) => { ($guard_name:tt, $no_tracy_name:expr, $tracy_name:expr) => {
$crate::span!($guard_name, $tracy_name); $crate::span!($guard_name, $tracy_name);
}; };
} }
#[cfg(feature = "tracy")]
pub struct ProfSpan(pub tracy_client::Span);
#[cfg(not(feature = "tracy"))] #[cfg(not(feature = "tracy"))]
pub struct ProfSpan; pub struct ProfSpan;
/// Like the span macro but only used when profiling and not in regular tracing /// Just implemented so that we dont need to have
/// operations /// #[allow(clippy::drop_non_drop)] everywhere
#[macro_export]
#[cfg(not(feature = "tracy"))] #[cfg(not(feature = "tracy"))]
macro_rules! prof_span { impl Drop for ProfSpan {
($guard_name:tt, $name:expr) => { fn drop(&mut self) {}
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) => {};
} }
#[cfg(feature = "tracy")]
pub struct ProfSpan(pub tracy_client::Span);
/// Like the span macro but only used when profiling and not in regular tracing /// Like the span macro but only used when profiling and not in regular tracing
/// operations /// operations
#[cfg(not(feature = "tracy"))]
#[macro_export] #[macro_export]
#[cfg(feature = "tracy")]
macro_rules! prof_span { macro_rules! prof_span {
($guard_name:tt, $name:expr) => { ($guard_name:tt, $name:expr) => {
let $guard_name = $crate::ProfSpan($crate::tracy_client::Span::new( let $guard_name = $crate::ProfSpan;
$name,
"",
module_path!(),
line!(),
// No callstack since this has significant overhead
0,
));
}; };
// Shorthand for when you want the guard to just be dropped at the end of the scope instead // Shorthand for when you want the guard to just be dropped at the end of the scope instead
// of controlling it manually // of controlling it manually
@ -137,51 +112,58 @@ macro_rules! prof_span {
}; };
} }
/// There's no guard, but really this is actually the guard /// Like the span macro but only used when profiling and not in regular tracing
pub struct GuardlessSpan { /// operations
span: tracing::Span, #[cfg(feature = "tracy")]
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) {}
}
#[macro_export] #[macro_export]
macro_rules! no_guard_span { macro_rules! prof_span {
($level:ident, $name:expr, $($fields:tt)*) => { ($guard_name:tt, $name:expr) => {
GuardlessSpan::new( let $guard_name = $crate::ProfSpan(
tracing::span!(tracing::Level::$level, $name, $($fields)*) // No callstack since this has significant overhead
) $crate::tracy_client::span!($name, 0),
}; );
($level:ident, $name:expr) => {
GuardlessSpan::new(
tracing::span!(tracing::Level::$level, $name)
)
}; };
// Shorthand for when you want the guard to just be dropped at the end of the scope instead
// of controlling it manually
($name:expr) => { ($name:expr) => {
GuardlessSpan::new( $crate::prof_span!(_guard, $name);
tracing::span!(tracing::Level::TRACE, $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::<S>();
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);
}; };
} }

View File

@ -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"]} tracing-subscriber = { version = "0.3.7", default-features = false, features = ["env-filter", "fmt", "time", "ansi", "smallvec", "tracing-log"]}
# Tracy # Tracy
tracing-tracy = { version = "0.8.0", optional = true } tracing-tracy = { version = "0.9.0", optional = true }

View File

@ -98,7 +98,7 @@ impl Queue {
id, id,
name: name.to_owned(), name: name.to_owned(),
task: Box::new(move || { task: Box::new(move || {
common_base::prof_span!(_guard, &name_cloned); common_base::prof_span_alloc!(_guard, &name_cloned);
let execution_start = Instant::now(); let execution_start = Instant::now();
f(); f();
let execution_end = Instant::now(); let execution_end = Instant::now();

View File

@ -32,6 +32,9 @@ lazy_static::lazy_static! {
const TPS: u64 = 30; const TPS: u64 = 30;
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
#[cfg(feature = "tracy")]
common_base::tracy_client::Client::start();
use clap::Parser; use clap::Parser;
let app = ArgvApp::parse(); let app = ArgvApp::parse();
@ -268,7 +271,7 @@ fn main() -> io::Result<()> {
// Wait for the next tick. // Wait for the next tick.
clock.tick(); clock.tick();
#[cfg(feature = "tracy")] #[cfg(feature = "tracy")]
common_base::tracy_client::finish_continuous_frame!(); common_base::tracy_client::frame_mark();
} }
Ok(()) Ok(())

View File

@ -127,7 +127,7 @@ itertools = "0.10.0"
# Tracy # Tracy
tracing = "0.1" 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] [target.'cfg(target_os = "macos")'.dependencies]
dispatch = "0.1.4" dispatch = "0.1.4"

View File

@ -29,6 +29,9 @@ use tracing::{error, info, warn};
use veloren_voxygen::ui::egui::EguiState; use veloren_voxygen::ui::egui::EguiState;
fn main() { fn main() {
#[cfg(feature = "tracy")]
common_base::tracy_client::Client::start();
let userdata_dir = common_base::userdata_dir_workspace!(); let userdata_dir = common_base::userdata_dir_workspace!();
// Determine where Voxygen's logs should go // Determine where Voxygen's logs should go

View File

@ -5,7 +5,7 @@ use crate::{
window::{Event, EventLoop}, window::{Event, EventLoop},
Direction, GlobalState, PlayState, PlayStateResult, Direction, GlobalState, PlayState, PlayStateResult,
}; };
use common_base::{no_guard_span, span, GuardlessSpan}; use common_base::{prof_span, span};
use std::{mem, time::Duration}; use std::{mem, time::Duration};
use tracing::debug; use tracing::debug;
@ -71,7 +71,8 @@ pub fn run(mut global_state: GlobalState, event_loop: EventLoop) {
match event { match event {
winit::event::Event::NewEvents(_) => { 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 => { winit::event::Event::MainEventsCleared => {
event_span.take(); event_span.take();
@ -79,7 +80,8 @@ pub fn run(mut global_state: GlobalState, event_loop: EventLoop) {
if polled_twice { if polled_twice {
handle_main_events_cleared(&mut states, control_flow, &mut global_state); 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; polled_twice = !polled_twice;
}, },
winit::event::Event::WindowEvent { event, .. } => { winit::event::Event::WindowEvent { event, .. } => {
@ -252,7 +254,7 @@ fn handle_main_events_cleared(
global_state.clock.tick(); global_state.clock.tick();
drop(guard); drop(guard);
#[cfg(feature = "tracy")] #[cfg(feature = "tracy")]
common_base::tracy_client::finish_continuous_frame!(); common_base::tracy_client::frame_mark();
// Maintain global state. // Maintain global state.
global_state.maintain(global_state.clock.dt()); global_state.maintain(global_state.clock.dt());