[−][src]Crate coarse_prof
coarse-prof
allows you to hierarchically measure the time that blocks in
your program take, enabling you to get an intuition of where most time is
spent. This can be useful for game development, where you have a bunch of
things that need to run in every frame, such as physics, rendering,
networking and so on, and you may wish to identify the hot spots, so that
you know whether and what to optimize.
coarse-prof
's implementation has been inspired by
hprof.
In contrast to hprof
, which resets measurements after each frame, this
library tracks averages over multiple frames. Also, coarse-prof
provides
the macro profile
for profiling a scope, so that
users do not have to assign a name to scope guards.
Example
use std::thread::sleep; use std::time::Duration; use coarse_prof::profile; fn render() { profile!("render"); // So slow! sleep(Duration::from_millis(10)); } // Our game's main loop let num_frames = 100; for i in 0..num_frames { profile!("frame"); // Physics don't run every frame if i % 10 == 0 { profile!("physics"); sleep(Duration::from_millis(2)); { profile!("collisions"); sleep(Duration::from_millis(1)); } } render(); } // Print the profiling results. coarse_prof::write(&mut std::io::stdout()).unwrap();
Example output:
frame: 100.00%, 10.40ms/call @ 96.17Hz
physics: 3.04%, 3.16ms/call @ 9.62Hz
collisions: 33.85%, 1.07ms/call @ 9.62Hz
render: 96.84%, 10.07ms/call @ 96.17Hz
Macros
profile | Use this macro to add the current scope to profiling. In effect, the time taken from entering to leaving the scope will be measured. |
Structs
Guard | A guard that is created when entering a scope and dropped when leaving it. |
Profiler | A |
Constants
PROFILER | Global thread-local instance of the profiler. |
Functions
enter | Manually enter a scope. |
reset | Reset profiling information. |
write | Print profiling scope tree. |