Crate bevy_datasize[−][src]
Expand description
This is a library for tracking memory usage in Bevy apps.
bevy_datasize
uses the DataSize
trait from the datasize
crate to
estimate the runtime memory usage of any components, resources, or assets
that are registered with the MemoryUsagePlugin
.
The DataSize
trait can be derived for your own custom types, and you can
inject custom estimators for third party types that do not implement
DataSize
. See the datasize
docs for more info on that.
Example
use bevy::prelude::*;
use bevy_datasize::prelude::*;
#[derive(Component, DataSize)]
struct MyComponent {
data: Vec<u8>,
}
fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_plugin(MemoryUsagePlugin)
.register_sized_component::<MyComponent>()
.add_system(print_datasize)
.run();
}
fn print_datasize(memory_usage: Res<MemoryUsage>) {
let MemoryStats {
count,
total_stack_bytes,
total_heap_bytes,
} = memory_usage.get_stats::<MyComponent>().unwrap();
println!("MyComponent count: {count}");
println!("MyComponent total stack usage: {total_stack_bytes} bytes");
println!("MyComponent total heap usage: {total_heap_bytes} bytes");
}
Re-exports
pub use datasize;
Modules
Extension traits for [App
].
Support for Bevy’s built-in types.
Heap size estimators.
Systems used by this library.
Structs
Configuration for the MemoryUsagePlugin
.
Memory usage statistics for a single data type.
Stores memory usage statistics for registered data types.
Adds memory usage tracking to Bevy apps.
Traits
Indicates that a type knows how to approximate its memory usage.
Indicates that a type can estimate the heap usage of values of type T
.
[App
] extension methods to register DataSize
types for memory usage
tracking.
Derive Macros
Automatically derive the DataSize
trait for a type.