Skip to content

Commit 882c86e

Browse files
authored
add a feature for memory tracing with tracy (#8272)
# Objective - Expose a feature for tracing with Tracy to profile memory (https://docs.rs/tracy-client/0.15.2/tracy_client/struct.ProfiledAllocator.html) - This is a separate feature than just tracing as it can have an additional cost <img width="1912" alt="Screenshot 2023-03-30 at 08 39 49" src="https://user-images.githubusercontent.com/8672791/228985566-dd62fff8-1cbf-4f59-8a10-80c796daba0c.png">
1 parent 43d7184 commit 882c86e

File tree

5 files changed

+12
-0
lines changed

5 files changed

+12
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ trace_chrome = ["trace", "bevy_internal/trace_chrome"]
108108
# Tracing support, exposing a port for Tracy
109109
trace_tracy = ["trace", "bevy_internal/trace_tracy"]
110110

111+
# Tracing support, with memory profiling, exposing a port for Tracy
112+
trace_tracy_memory = ["trace", "bevy_internal/trace_tracy", "bevy_internal/trace_tracy_memory"]
113+
111114
# Tracing support
112115
trace = ["bevy_internal/trace"]
113116

crates/bevy_internal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ trace = [
2121
]
2222
trace_chrome = [ "bevy_log/tracing-chrome" ]
2323
trace_tracy = ["bevy_render?/tracing-tracy", "bevy_log/tracing-tracy" ]
24+
trace_tracy_memory = ["bevy_log/trace_tracy_memory"]
2425
wgpu_trace = ["bevy_render/wgpu_trace"]
2526
debug_asset_server = ["bevy_asset/debug_asset_server"]
2627
detailed_trace = ["bevy_utils/detailed_trace"]

crates/bevy_log/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ keywords = ["bevy"]
1010

1111
[features]
1212
trace = [ "tracing-error" ]
13+
trace_tracy_memory = ["dep:tracy-client"]
1314

1415
[dependencies]
1516
bevy_app = { path = "../bevy_app", version = "0.11.0-dev" }
@@ -21,6 +22,7 @@ tracing-chrome = { version = "0.7.0", optional = true }
2122
tracing-tracy = { version = "0.10.0", optional = true }
2223
tracing-log = "0.1.2"
2324
tracing-error = { version = "0.2.0", optional = true }
25+
tracy-client = { version = "0.15", optional = true }
2426

2527
[target.'cfg(target_os = "android")'.dependencies]
2628
android_log-sys = "0.2.0"

crates/bevy_log/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ use std::panic;
1818
#[cfg(target_os = "android")]
1919
mod android_tracing;
2020

21+
#[cfg(feature = "trace_tracy_memory")]
22+
#[global_allocator]
23+
static GLOBAL: tracy_client::ProfiledAllocator<std::alloc::System> =
24+
tracy_client::ProfiledAllocator::new(std::alloc::System, 100);
25+
2126
pub mod prelude {
2227
//! The Bevy Log Prelude.
2328
#[doc(hidden)]

docs/cargo_features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The default feature set enables most of the expected features of a game engine,
6767
|trace|Tracing support|
6868
|trace_chrome|Tracing support, saving a file in Chrome Tracing format|
6969
|trace_tracy|Tracing support, exposing a port for Tracy|
70+
|trace_tracy_memory|Tracing support, with memory profiling, exposing a port for Tracy|
7071
|wav|WAV audio format support|
7172
|wayland|Wayland display server support|
7273
|webp|WebP image format support|

0 commit comments

Comments
 (0)