Simple profiler scopes for wgpu using timer queries

14 releases (9 breaking)

0.11.0 Jan 26, 2023
0.10.0 Nov 19, 2022
0.9.1 Sep 18, 2022
0.9.0 Jul 10, 2022
0.3.1 Mar 6, 2021

#56 in Graphics APIs

Download history 104/week @ 2022-12-04 95/week @ 2022-12-11 89/week @ 2022-12-18 65/week @ 2022-12-25 71/week @ 2023-01-01 149/week @ 2023-01-08 132/week @ 2023-01-15 152/week @ 2023-01-22 167/week @ 2023-01-29 196/week @ 2023-02-05 88/week @ 2023-02-12 199/week @ 2023-02-19 86/week @ 2023-02-26 111/week @ 2023-03-05 149/week @ 2023-03-12 68/week @ 2023-03-19

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


501 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, queue.get_timestamp_period(), device.features()); // 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

Note that GpuProfiler reads the device features - if your wgpu device doesn't have wgpu::Features::TIMESTAMP_QUERY enabled, it will automatically not attempt to emit any timer queries. Similarly, if wgpu::Features::WRITE_TIMESTAMP_INSIDE_PASSES is not present, no queries will be issued from inside passes.

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(std::path::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.


  • 0.11.0
    • Upgrade to wgpu 0.15
  • 0.10.0
    • Upgrade to wgpu 0.14 and switch to rust 2021 edition, by @Imberflur in #23
  • 0.9.1
    • Better docs #21
    • Fix crash on dropped frame #20, reported by @JCapucho in #19
    • Fix enable_pass_timer/enable_encoder_timer checking wrong features


~565K SLoC