Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions crates/bevy_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ pub struct LogPlugin {
///
/// Please see the `examples/app/log_layers.rs` for a complete example.
pub fmt_layer: fn(app: &mut App) -> Option<BoxedFmtLayer>,

/// Whether to stream events to the Tracy profiler or collector. Only enable
/// this if you actually intend to run the profiler; the enabled Tracy
/// client will buffer events without bound until it finds a profiler or
/// collector to connect to, which results in excessive memory use if you
/// never run the profiler.
#[cfg(feature = "tracing-tracy")]
pub enable_tracy: bool,
}

/// A boxed [`Layer`] that can be used with [`LogPlugin::custom_layer`].
Expand Down Expand Up @@ -288,6 +296,8 @@ impl Default for LogPlugin {
level: Level::INFO,
custom_layer: |_| None,
fmt_layer: |_| None,
#[cfg(feature = "tracing-tracy")]
enable_tracy: true,
}
}
}
Expand Down Expand Up @@ -342,7 +352,11 @@ impl Plugin for LogPlugin {
};

#[cfg(feature = "tracing-tracy")]
let tracy_layer = tracing_tracy::TracyLayer::default();
let tracy_layer = if self.enable_tracy {
Some(tracing_tracy::TracyLayer::default())
} else {
None
};

let fmt_layer = (self.fmt_layer)(app).unwrap_or_else(|| {
// note: the implementation of `Default` reads from the env var NO_COLOR
Expand Down Expand Up @@ -387,7 +401,9 @@ impl Plugin for LogPlugin {
tracing::subscriber::set_global_default(finished_subscriber).is_err();

#[cfg(feature = "tracing-tracy")]
warn!("Tracing with Tracy is active, memory consumption will grow until a client is connected");
if self.enable_tracy {
warn!("Tracing with Tracy is active, memory consumption will grow until a client is connected");
}

match (logger_already_set, subscriber_already_set) {
(true, true) => error!(
Expand Down
5 changes: 1 addition & 4 deletions crates/bevy_render/src/diagnostic/tracy_gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ pub fn new_tracy_gpu_context(
//
// An issue was filed on the wgpu-profiler repository that the function
// is copied from. https://github.com/Wumpf/wgpu-profiler/issues/107
//
// Once the root cause of the issue is located and fixed this should
// probably be moved back to not returning an option?
return None;
}
};

let tracy_client = Client::running().unwrap();
let tracy_client = Client::running()?;
tracy_client
.new_gpu_context(
Some("RenderQueue"),
Expand Down
Loading