Struct Profiler

Source
pub struct Profiler { /* private fields */ }
Expand description

The Profiler

The Profiler gives access to the gperftools library. By storing the state of the profiler and limiting access we make the FFI safer.

Implementations§

Source§

impl Profiler

Source

pub fn state(&self) -> ProfilerState

Returns the profiler state

§Examples
use gperftools::profiler::PROFILER;

println!("{}", PROFILER.lock().unwrap().state());
Source

pub fn start<T>(&mut self, fname: T) -> Result<(), Error>
where T: Into<Vec<u8>>,

Start the profiler

Will begin sampling once this function has been called and will not stop until the stop function has been called.

This function takes as an argument a filename. The filename must be both valid Utf8 and a valid CString.

§Failures
  • The profiler is currently Active.
  • fname is not a valid CString.
  • fname is not valid Utf8.
  • fname is not a file.
  • The user does not have write access to the file.
  • An internal failure from the gperftools library.
Examples found in repository?
examples/primes.rs (line 47)
41fn main() {
42    let prime_numbers = prepare_prime_numbers();
43
44    gperftools_static::PROFILER
45        .lock()
46        .unwrap()
47        .start("/tmp/prime.target")
48        .unwrap();
49
50    let mut v = 0;
51    for i in 2..50000 {
52        if is_prime_number(i, &prime_numbers) {
53            v += 1;
54        }
55    }
56
57    gperftools_static::PROFILER.lock().unwrap().stop().unwrap();
58
59    println!("Prime numbers: {}", v);
60}
Source

pub fn stop(&mut self) -> Result<(), Error>

Stop the profiler.

This will stop the profiler if it Active and return an error otherwise.

§Failures
  • The profiler is NotActive.
Examples found in repository?
examples/primes.rs (line 57)
41fn main() {
42    let prime_numbers = prepare_prime_numbers();
43
44    gperftools_static::PROFILER
45        .lock()
46        .unwrap()
47        .start("/tmp/prime.target")
48        .unwrap();
49
50    let mut v = 0;
51    for i in 2..50000 {
52        if is_prime_number(i, &prime_numbers) {
53            v += 1;
54        }
55    }
56
57    gperftools_static::PROFILER.lock().unwrap().stop().unwrap();
58
59    println!("Prime numbers: {}", v);
60}

Trait Implementations§

Source§

impl Debug for Profiler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.