bevy_datasize is a library for tracking memory usage in Bevy apps.

Overview

bevy_datasize

Tests

bevy_datasize 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.

Docs

Rustdocs for the main branch can be found here

Examples

Basic Usage

The following example demonstrates how to show the memory usage of all loaded Images:

use bevy::prelude::*;
use bevy_datasize::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(DefaultMemoryUsagePlugins)
        .add_system(print_image_usage)
        .run();
}

fn print_image_usage(memory_usage: Res
   ) {
    
   let MemoryStats {
        count,
        total_stack_bytes,
        total_heap_bytes,
    } 
   = memory_usage.
   get_stats
   ::
   ().
   unwrap();

    
   println!(
   "Image count: {count}");
    
   println!(
   "Total stack usage: {total_stack_bytes} bytes");
    
   println!(
   "Total heap usage: {total_heap_bytes} bytes");
}
  

Custom Data Types

The following example demonstrates how to track memory usage for a custom Component type when using minimal plugins:

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::
   ()
        .
   add_system(print_custom_usage)
        .
   run();
}


   fn 
   print_custom_usage(memory_usage: Res
   
    ) {
    
    let MemoryStats {
        count,
        total_stack_bytes,
        total_heap_bytes,
    } 
    = memory_usage.
    get_stats
    ::
    
     ().
     unwrap();

    
     println!(
     "MyComponent count: {count}");
    
     println!(
     "MyComponent total stack usage: {total_stack_bytes} bytes");
    
     println!(
     "MyComponent total heap usage: {total_heap_bytes} bytes");
}
    
   
  

More

See the examples directory for more examples.

Optional Features

bevy_datasize can be configured very granularly to only pull in the parts of bevy that you need for your app.

Default features

This gives you support for all of the Bevy-internal data types that bevy_datasize supports:

[dependencies]
bevy_datasize = "0.0.1"

Minimal features

This gives you support for only your own custom datatypes:

[dependencies]
bevy_datasize = { version = "0.0.1", default-features = false }

Other configurations

This, for example, gives you support for all rendering resources:

[dependencies]
bevy_datasize = { version = "0.0.1", default-features = false, features = ["render"] }

Or just for Image assets:

[dependencies]
bevy_datasize = { version = "0.0.1", default-features = false, features = ["image"] }

See the Cargo.toml to see all the available features.

Feature Checklist

This crate is still in development. Everybody loves checklists!

Main functionality features

  • Tracking custom types
  • Retrieving memory usage statistics from a resource
  • Throttling the statistics gathering
  • Hooking memory usage statistics up to Diagnostics
  • Categories / category hierarchy
  • Visual debugging and/or integration with bevy_inspector_egui

Supported Bevy types

So far, the following types have built-in support for memory tracking:

  • Types in bevy::audio
    • Audio
    • AudioSource1
  • Types in bevy::render
    • Mesh
    • GpuMesh
    • Image
    • GpuImage
    • Shader1
    • RenderGraph
    • TextureCache1
    • ComponentUniforms
    • VisibleEntities
    • ComputedVisibility
    • Visibility
    • ExtractedView
  • Types in bevy::gltf
    • Gltf
    • GltfMesh
    • GltfNode
    • GltfPrimitive
  • Types in bevy::pbr
    • StandardMaterial
    • GpuStandardMaterial
    • MeshUniform
    • MeshViewBindGroup
    • AmbientLight
    • Clusters
    • CubemapVisibleEntities
    • DirectionalLight
    • ExtractedAmbientLight
    • ExtractedClusterConfig
    • ExtractedClustersPointLights
    • ExtractedDirectionalLight
    • ExtractedPointLight
    • GpuDirectionalLight
    • GpuLights
    • GpuPointLight
    • GpuPointLights
    • PointLight
    • ShadowView
    • ViewClusterBindings
    • ViewLightEntities
    • ViewLightsUniformOffset
    • ViewShadowBindings
    • VisiblePointLights
    • Wireframe
  • Types in bevy::scene
    • Scene
    • DynamicScene
  • Types in bevy::sprite
    • Sprite
    • SpriteBatch
    • TextureAtlasSprite
    • TextureAtlas
    • ColorMaterial
    • GpuColorMaterial
    • ExtractedSprites
    • Mesh2dUniform
    • Mesh2dViewBindGroup
  • Types in bevy::transform
    • Transform
    • GlobalTransform
    • Children
    • Parent
    • PreviousParent
  • Types in bevy::text
    • Font1
    • FontAtlasSet
    • Text
    • Text2dSize
  • Types in bevy::ui
    • CalculatedClip
    • CalculatedSize
    • ExtractedUiNodes
    • Node
    • Style
    • UiBatch
    • UiImage

License

Licensed under either of

at your option.

Copyright Ben Reeves 2022

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Footnotes

  1. It may not be possible to estimate the size of this type. 2 3 4

You might also like...
dua (- Disk Usage Analyzer) is a tool to conveniently learn about the usage of disk space of a given directory

dua (- Disk Usage Analyzer) is a tool to conveniently learn about the usage of disk space of a given directory. It's parallel by default and will max

Allocscope  -  a memory tracking tool
Allocscope - a memory tracking tool

allocscope a memory tracking tool allocscope is a tool for tracking down where the most egregiously large allocations are occurring in a C, C++ or Rus

Library and proc macro to analyze memory usage of data structures in rust.
Library and proc macro to analyze memory usage of data structures in rust.

Allocative: memory profiler for Rust This crate implements a lightweight memory profiler which allows object traversal and memory size introspection.

UnravelSports repository to display Football/Soccer tracking data in 3D using Rust & Bevy
UnravelSports repository to display Football/Soccer tracking data in 3D using Rust & Bevy

Introduction This project is a proof-of-concept by UnravelSports to show football/soccer data in 3D using the Rust programming language and the Bevy g

a library for generating bevy_rapier2d colliders, for bevy apps, from images with transparency
a library for generating bevy_rapier2d colliders, for bevy apps, from images with transparency

bevy_rapier_collider_gen a library for generating bevy_rapier2d colliders, for bevy apps, from images with transparency example to see this in action

Traits for inspecting memory usage of Rust types

memuse This crate contains traits for measuring the dynamic memory usage of Rust types. About Memory-tracking is a common activity in large applicatio

Very minimalist tmux status bar that displays used memory and CPU usage.
Very minimalist tmux status bar that displays used memory and CPU usage.

woot-bar Ultra minimalist status bar that displays used memory and CPU usage woot-bar is made for tmux but it is compatible with anything that eats st

A CLI tool which can help you automatically kill process of your choice. Useful for freeing up memory and CPU usage!
A CLI tool which can help you automatically kill process of your choice. Useful for freeing up memory and CPU usage!

Quickiller There are always programs such as chrome that keep eating up your resources even when closed! The only way to prevent this is to kill all o

Memory usage monitor for process trees

gotta-watch-em-all Executes a process with given arguments and monitors, logs when memory usage grows to a new peak. Example: cargo run -- cargo -- bu

Rust-port of spotify/annoy as a wrapper for Approximate Nearest Neighbors in C++/Python optimized for memory usage.

Rust-port of spotify/annoy as a wrapper for Approximate Nearest Neighbors in C++/Python optimized for memory usage.

Rust-port of spotify/annoy as a wrapper for Approximate Nearest Neighbors in C++/Python optimized for memory usage.

Fareast This library is a rust port of spotify/annoy , currently only index serving is supported. It also provides FFI bindings for jvm, dotnet and da

A place to start when building webgl apps in Bevy. Use this to avoid writing the boilerplate.

Template Bevy project with WebGL enabled Prerequisites cargo install cargo-make Build and serve WASM version Set your local ip address in Makefile.to

Sub-pixel precision light spot rendering library for astronomy and video tracking applications.

Planetarium Sub-pixel precision light spot rendering library for astronomy and video tracking applications. Example usage use planetarium::{Canvas, Sp

Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.
Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.

Description Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLit

A small utility for tracking the change in opening and closing of issues in a GitHub repo

A small utility for tracking the change in opening and closing of issues in a GitHub repo. This tool can be used to build visualizations for issue triage over time with the hope of motivating closing more issues than are opened.

global allocator that provides hooks for tracking allocation events

tracking-allocator A GlobalAlloc-compatible allocator implementation that provides the ability to track allocation events. examples As allocators are

Bartib is an easy to use time tracking tool for the command line.

Bartib is an easy to use time tracking tool for the command line. It saves a log of all tracked activities as a plaintext file and allows you to create flexible reports.

A realtime flight tracking program for our Software Engineering 300 class at ERAU
A realtime flight tracking program for our Software Engineering 300 class at ERAU

Flight Tracking ERAU SE300 Description Software that allows for weather and plane tracking to facilitate the user in looking at plane paths. Many peop

A VtubeStudio plugin that allows iFacialMocap to stream data to the app, enabling full apple ARkit facial tracking to be used for 2D Vtuber models.

facelink_rs A VtubeStudio plugin that allows iFacialMocap to stream data to the app, enabling full apple ARkit facial tracking to be used for 2D Vtube

Cross-platform library for reading/writing memory in other processes for Rust

vmemory Rust library for reading/writing memory in other processes for Windows, macOS, Linux, and in the future potentially, BSD variants. Rationale A

Jason Johnson 26 Nov 7, 2022
Rust library to interract with memory written in rust

memory-rs Rust library to interract with memory written in rust It comes with: Pattern scanner (Return address for a pattern given). A pattern example

Alex 1 Jan 13, 2022
Memory hacking library for windows

Memory hacking library for windows

Sara Wahib 4 Apr 11, 2022
memory-mapped registers for x86_64 systems

regmap some well-known and known-to-be-good computer architectures, such as the Microchip PIC product line, or many of the AVR processor family, were

iximeow 31 Dec 6, 2022
MiniDump a process in memory with rust

safetydump Rust in-memory MiniDump implementation. Features ntdll!NtGetNextProcess to obtain a handle for the desired ProcessId as opposed to kernel32

null 26 Oct 11, 2022
In-memory, non stateful and session based code sharing application.

interviewer In-memory, non stateful and session based code sharing application. Test it here: interviewer.taras.lol Note: it's deployed to render auto

2pac 7 Aug 16, 2021
A cross-platform and safe Rust API to create and manage memory mappings in the virtual address space of the calling process.

mmap-rs A cross-platform and safe Rust API to create and manage memory mappings in the virtual address space of the calling process. This crate can be

S.J.R. van Schaik 19 Oct 23, 2022
A memory efficient syntax tree for language developers

This crate provides a tree structure which always is contiguously stored and manipulated in memory. It provides similar APIs as rowan and is intended to be an efficient replacement for it (read more below).

John-John Tedro 21 Dec 15, 2022
Compile-time checked Builder pattern derive macro with zero-memory overhead

Compile-time checked Builder pattern derive macro with zero-memory overhead This is very much a work-in-progress. PRs welcome to bring this to product

Esteban Kuber 214 Dec 29, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022