Module profiler

Source
Expand description

Cpu Profiler

This crate provides safe bindings to google’s gperftools library. This allows us to use statistical sampling to profile sections of code and consume the output in a number of ways using pprof.

§Installation

In order to use this library you will need to install gperftools. There are instructions in their repository but it’s roughly the following:

  1. Download package from releases
  2. Run ./configure
  3. Run make install

There may be some other dependencies for your system - these are explained well in their INSTALL document. For example libunwind (> 0.99.0) is required for 64 bit systems.

§Usage

use gperftools::profiler::PROFILER;

PROFILER.lock().unwrap().start("./my-profile.prof");
// Code you want to sample goes here!
PROFILER.lock().unwrap().stop();

The profiler is accessed via the static PROFILER: Mutex<Profiler>. We limit access this way to ensure that only one profiler is running at a time - this is a limitation of the gperftools library.

Structs§

PROFILER
Static reference to the PROFILER
Profiler
The Profiler