Simple profiler scopes for wgpu using timer queries

10 releases (6 breaking)

0.8.0 Dec 18, 2021
0.7.0 Oct 8, 2021
0.6.1 Sep 5, 2021
0.6.0 Aug 22, 2021
0.2.1 Feb 27, 2021

#54 in Graphics APIs

Download history 179/week @ 2022-03-11 204/week @ 2022-03-18 195/week @ 2022-03-25 263/week @ 2022-04-01 290/week @ 2022-04-08 239/week @ 2022-04-15 1065/week @ 2022-04-22 842/week @ 2022-04-29 207/week @ 2022-05-06 249/week @ 2022-05-13 92/week @ 2022-05-20 119/week @ 2022-05-27 129/week @ 2022-06-03 61/week @ 2022-06-10 141/week @ 2022-06-17 95/week @ 2022-06-24

443 downloads per month
Used in 9 crates (4 directly)


497 lines



Simple profiler scopes for wgpu using timer queries


  • Easy to use profiler scopes
    • Allows nesting!
    • Can be disabled by runtime flag
    • Additionally generates debug markers
  • Internally creates pools of timer queries automatically
    • Does not need to know in advance how many queries/profiling scopes are needed
    • Caches up profiler-frames until results are available
      • No stalling of the device at any time!
  • Many profiler instances can live side by side
  • chrome trace flamegraph json export


  • Better error messages
  • Disable via feature flag

How to use

Create a new profiler object:

use wgpu_profiler::{wgpu_profiler, GpuProfiler};
// ...
let mut profiler = GpuProfiler::new(4, adapter.get_timestamp_period()); // buffer up to 4 frames

Using scopes is easiest with the macro:

wgpu_profiler!("name of your scope", &mut profiler, &mut encoder, &device, {
  // wgpu commands go here

Unless you disable timer scoping (wgpu_profile will still emit debug scopes), your wgpu device needs wgpu::Features::TIMESTAMP_QUERY enabled.

Wgpu-profiler needs to insert buffer copy commands, so when you're done with an encoder and won't do any more profiling scopes on it, you need to resolve the queries:

profiler.resolve_queries(&mut encoder);

And finally, to end a profiling frame, call end_frame. This does a few checks and will let you know of something is off!


Retrieving the oldest available frame and writing it out to a chrome trace file.

if let Some(profiling_data) = profiler.process_finished_frame() {
    // You usually want to write to disk only under some condition, e.g. press of a key or button
    wgpu_profiler::chrometrace::write_chrometrace(Path::new("mytrace.json"), profiling_data);

To get a look of it in action, check out the example project!


Licensed under either of

at your option.


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.


~98K SLoC