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
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,8 @@ syn = { version = "2.0.101", features = ["full", "extra-traits"] }
quote = "1.0.40"
serde = { version = "1.0.225", default-features = false }
serde_json = "1.0.145"

# Profiling profile: release optimizations with debug info for demangled backtraces.
[profile.profiling]
inherits = "release"
debug = 1
4 changes: 4 additions & 0 deletions sparse_strips/vello_cpu/examples/winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ publish = false
[lints]
workspace = true

[features]
dhat-heap = ["dep:dhat"]

[dependencies]
winit = { workspace = true }
vello_common = { workspace = true }
vello_cpu = { workspace = true, features = ["multithreading"] }
vello_example_scenes = { workspace = true, features = ["cpu"] }
softbuffer = "0.4.6"
dhat = { version = "0.3.3", optional = true }
30 changes: 30 additions & 0 deletions sparse_strips/vello_cpu/examples/winit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,33 @@ This example uses multi-threaded CPU rendering. The number of threads used is de

For better performance, always run with the `--release` flag.

## Heap Profiling with DHAT

This example supports heap profiling using the [dhat](https://docs.rs/dhat) crate. This is useful for analyzing memory allocation patterns and identifying allocation hotspots.

### Running with Heap Profiling

```sh
cargo run -p vello_cpu_winit --profile profiling --features dhat-heap
```

The program will run slower than normal due to allocation tracking.

When you exit the application, you'll see a summary like:

```
dhat: Total: 1,256 bytes in 6 blocks
dhat: At t-gmax: 1,256 bytes in 6 blocks
dhat: At t-end: 1,256 bytes in 6 blocks
dhat: The data has been saved to dhat-heap.json, and is viewable with dhat/dh_view.html
```

### Viewing Results

Open the generated `dhat-heap.json` file in [DHAT's online viewer](https://nnethercote.github.io/dh_view/dh_view.html) to explore:

- Total allocations and their call sites
- Peak heap usage (t-gmax)
- Memory still allocated at exit (t-end)
- Allocation hotspots with full backtraces

7 changes: 7 additions & 0 deletions sparse_strips/vello_cpu/examples/winit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
reason = "truncation has no appreciable impact in this demo"
)]

#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;

#[cfg(not(target_arch = "wasm32"))]
use std::env;
use std::num::NonZeroU32;
Expand Down Expand Up @@ -55,6 +59,9 @@ struct App {
}

fn main() {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();

#[cfg(not(target_arch = "wasm32"))]
let (scenes, start_scene_index) = {
let mut start_scene_index = 0;
Expand Down