Crate cpuprofiler [−] [src]
This crate provides safe bindings to google's cpuprofiler library. This allows us to use statistical sampling to profile sections of code and consume the output in a number of ways using pprof.
In order to use this library you will need to install gperftools. There are instructions in their repository but it's roughly the following:
- Download package from releases
use cpuprofiler::PROFILER; PROFILER.lock().unwrap().start("./my-prof.profile"); // Code you want to sample goes here! PROFILER.lock().unwrap().stop();
The profiler is accessed via the static
We limit access this way to ensure that only one profiler is running at a time -
this is a limitation of the cpuprofiler library.
Static reference to the PROFILER
The state of the profiler