Skip to content

Commit

Permalink
bevy_app: add tracing event with tracy.frame_mark (#4320)
Browse files Browse the repository at this point in the history
Currently `tracy` interprets the entire trace as one frame because the marker for frames isn't being recorded.

~~When an event with `tracy.trace_marker=true` is recorded, `tracing-tracy` will mark the frame as finished:
<https://github.com/nagisa/rust_tracy_client/blob/aa0b96b2ae2aee6f3831994f9a3a8c29bcc85fae/tracing-tracy/src/lib.rs#L240>~~

~~Unfortunately this leads to~~
```rs
INFO bevy_app:frame: bevy_app::app: finished frame tracy.frame_mark=true
```
~~being printed every frame (we can't use DEBUG because bevy_log sets `max_release_level_info`.~~

Instead of emitting an event that gets logged every frame, we can depend on tracy-client itself and call `finish_continuous_frame!();`
  • Loading branch information
jakobhellermann committed Apr 8, 2022
1 parent 3756181 commit c12ee81
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = ["game-engines", "graphics", "gui", "rendering"]
[features]
trace = [ "bevy_app/trace", "bevy_ecs/trace", "bevy_log/trace", "bevy_render/trace", "bevy_core_pipeline/trace" ]
trace_chrome = [ "bevy_log/tracing-chrome" ]
trace_tracy = [ "bevy_log/tracing-tracy" ]
trace_tracy = ["bevy_render/tracing-tracy", "bevy_log/tracing-tracy" ]
wgpu_trace = ["bevy_render/wgpu_trace"]
debug_asset_server = ["bevy_asset/debug_asset_server"]

Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ impl Plugin for LogPlugin {
let tracy_layer = tracing_tracy::TracyLayer::new();

let fmt_layer = tracing_subscriber::fmt::Layer::default();
#[cfg(feature = "tracing-tracy")]
let fmt_layer = fmt_layer.with_filter(
tracing_subscriber::filter::Targets::new().with_target("tracy", Level::ERROR),
);

let subscriber = subscriber.with(fmt_layer);

#[cfg(feature = "tracing-chrome")]
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ zlib = ["flate2"]
zstd = ["ruzstd"]

trace = []
tracing-tracy = []
wgpu_trace = ["wgpu/trace"]
ci_limits = []
webgl = ["wgpu/webgl"]
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_render/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ pub fn render_system(world: &mut World) {
if let Some(surface_texture) = texture_view.take_surface_texture() {
surface_texture.present();
}

#[cfg(feature = "tracing-tracy")]
bevy_utils::tracing::event!(
bevy_utils::tracing::Level::INFO,
message = "finished frame",
tracy.frame_mark = true
);
}
}
}
Expand Down

0 comments on commit c12ee81

Please sign in to comment.