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
impl Profiler
Sourcepub fn state(&self) -> ProfilerState
pub fn state(&self) -> ProfilerState
Returns the profiler state
§Examples
use gperftools::profiler::PROFILER;
println!("{}", PROFILER.lock().unwrap().state());Sourcepub fn start<T>(&mut self, fname: T) -> Result<(), Error>
pub fn start<T>(&mut self, fname: T) -> Result<(), Error>
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. fnameis not a validCString.fnameis not valid Utf8.fnameis 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}Sourcepub fn stop(&mut self) -> Result<(), Error>
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§
Auto Trait Implementations§
impl Freeze for Profiler
impl RefUnwindSafe for Profiler
impl Send for Profiler
impl Sync for Profiler
impl Unpin for Profiler
impl UnwindSafe for Profiler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more