diff --git a/Cargo.toml b/Cargo.toml index 6ecad24599612..d102648889072 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ bevy_pbr2 = ["bevy_internal/bevy_pbr2"] bevy_gltf2 = ["bevy_internal/bevy_gltf2"] trace_chrome = ["bevy_internal/trace_chrome"] +trace_tracy = ["bevy_internal/trace_tracy"] trace = ["bevy_internal/trace"] wgpu_trace = ["bevy_internal/wgpu_trace"] diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 8f7a1d2c2dd9e..2a4b7de8f4234 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -17,6 +17,7 @@ categories = ["game-engines", "graphics", "gui", "rendering"] wgpu_trace = ["bevy_wgpu/trace"] trace = [ "bevy_app/trace", "bevy_ecs/trace" ] trace_chrome = [ "bevy_log/tracing-chrome" ] +trace_tracy = [ "bevy_log/tracing-tracy" ] # Image format support for texture loading (PNG and HDR are enabled by default) hdr = ["bevy_render/hdr", "bevy_render2/hdr" ] diff --git a/crates/bevy_log/Cargo.toml b/crates/bevy_log/Cargo.toml index 0dee0feab4a3f..0ff2d865993d2 100644 --- a/crates/bevy_log/Cargo.toml +++ b/crates/bevy_log/Cargo.toml @@ -17,8 +17,9 @@ keywords = ["bevy"] bevy_app = { path = "../bevy_app", version = "0.5.0" } bevy_utils = { path = "../bevy_utils", version = "0.5.0" } -tracing-subscriber = {version = "0.2.15", features = ["registry"]} -tracing-chrome = { version = "0.3.0", optional = true } +tracing-subscriber = {version = "0.2.22", features = ["registry"]} +tracing-chrome = { version = "0.3.1", optional = true } +tracing-tracy = { version = "0.7.0", optional = true } tracing-log = "0.1.2" [target.'cfg(target_os = "android")'.dependencies] diff --git a/crates/bevy_log/src/lib.rs b/crates/bevy_log/src/lib.rs index 3b3761b71db49..7fd9372c734e4 100644 --- a/crates/bevy_log/src/lib.rs +++ b/crates/bevy_log/src/lib.rs @@ -95,10 +95,8 @@ impl Plugin for LogPlugin { #[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))] { - let fmt_layer = tracing_subscriber::fmt::Layer::default(); - let subscriber = subscriber.with(fmt_layer); #[cfg(feature = "tracing-chrome")] - { + let chrome_layer = { let (chrome_layer, guard) = tracing_chrome::ChromeLayerBuilder::new() .name_fn(Box::new(|event_or_span| match event_or_span { tracing_chrome::EventOrSpan::Event(event) => event.metadata().name().into(), @@ -114,16 +112,22 @@ impl Plugin for LogPlugin { })) .build(); app.world.insert_non_send(guard); - let subscriber = subscriber.with(chrome_layer); - bevy_utils::tracing::subscriber::set_global_default(subscriber) - .expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins"); - } + chrome_layer + }; + + #[cfg(feature = "tracing-tracy")] + let tracy_layer = tracing_tracy::TracyLayer::new(); + + let fmt_layer = tracing_subscriber::fmt::Layer::default(); + let subscriber = subscriber.with(fmt_layer); + + #[cfg(feature = "tracing-chrome")] + let subscriber = subscriber.with(chrome_layer); + #[cfg(feature = "tracing-tracy")] + let subscriber = subscriber.with(tracy_layer); - #[cfg(not(feature = "tracing-chrome"))] - { - bevy_utils::tracing::subscriber::set_global_default(subscriber) - .expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins"); - } + bevy_utils::tracing::subscriber::set_global_default(subscriber) + .expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins"); } #[cfg(target_arch = "wasm32")] diff --git a/docs/cargo_features.md b/docs/cargo_features.md index fd23282e7556f..5e3c5f3214c82 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -23,6 +23,7 @@ |dynamic|Forces bevy to be dynamically linked, which improves iterative compile times.| |trace|Enables system tracing (useful in tandem with a feature like trace_chrome).| |trace_chrome|Enables [tracing-chrome](https://github.com/thoren-d/tracing-chrome) as bevy_log output. This allows you to visualize system execution.| +|trace_tracy|Enables [Tracy](https://github.com/wolfpld/tracy) as bevy_log output. This allows `Tracy` to connect to and capture profiling data as well as visualize system execution in real-time, present statistics about system execution times, and more.| |wgpu_trace|For tracing wgpu.| |dds|DDS picture format support.| |tga|TGA picture format support.|