pprof/
lib.rs

1// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
2
3//! pprof-rs is an integrated profiler for rust program.
4//!
5//! This crate provides a programable interface to start/stop/report a profiler
6//! dynamically. With the help of this crate, you can easily integrate a
7//! profiler into your rust program in a modern, convenient way.
8//!
9//! A sample usage is:
10//!
11//! ```rust
12//! let guard = pprof::ProfilerGuard::new(100).unwrap();
13//! ```
14//!
15//! Then you can read report from the guard:
16//!
17//! ```rust
18//! # let guard = pprof::ProfilerGuard::new(100).unwrap();
19//!if let Ok(report) = guard.report().build() {
20//!    println!("report: {:?}", &report);
21//!};
22//! ```
23//!
24//! More configuration can be passed through `ProfilerGuardBuilder`:
25//!
26//! ```rust
27//! let guard = pprof::ProfilerGuardBuilder::default().frequency(1000).blocklist(&["libc", "libgcc", "pthread", "vdso"]).build().unwrap();
28//! ```
29//!
30//! The frequency means the sampler frequency, and the `blocklist` means the
31//! profiler will ignore the sample whose first frame is from library containing
32//! these strings.
33//!
34//! Skipping `libc`, `libgcc` and `libpthread` could be a solution to the
35//! possible deadlock inside the `_Unwind_Backtrace`, and keep the signal
36//! safety. The dwarf information in "vdso" is incorrect in some distributions,
37//! so it's also suggested to skip it.
38//!
39//! You can find more details in
40//! [README.md](https://github.com/tikv/pprof-rs/blob/master/README.md)
41
42/// Define the MAX supported stack depth. TODO: make this variable mutable.
43pub const MAX_DEPTH: usize = 128;
44
45/// Define the MAX supported thread name length. TODO: make this variable mutable.
46pub const MAX_THREAD_NAME: usize = 16;
47
48mod addr_validate;
49
50mod backtrace;
51mod collector;
52mod error;
53mod frames;
54mod profiler;
55mod report;
56mod timer;
57
58pub use self::addr_validate::validate;
59pub use self::collector::{Collector, HashCounter};
60pub use self::error::{Error, Result};
61pub use self::frames::{Frames, Symbol};
62pub use self::profiler::{ProfilerGuard, ProfilerGuardBuilder};
63pub use self::report::{Report, ReportBuilder, UnresolvedReport};
64
65#[cfg(feature = "flamegraph")]
66pub use inferno::flamegraph;
67
68#[allow(clippy::all)]
69#[cfg(all(feature = "prost-codec", not(feature = "protobuf-codec")))]
70pub mod protos {
71    pub use prost::Message;
72
73    include!(concat!(
74        env!("CARGO_MANIFEST_DIR"),
75        "/proto/perftools.profiles.rs"
76    ));
77}
78
79#[cfg(feature = "protobuf-codec")]
80pub mod protos {
81    pub use protobuf::Message;
82
83    include!(concat!(env!("OUT_DIR"), "/mod.rs"));
84
85    pub use self::profile::*;
86}
87
88#[cfg(feature = "criterion")]
89pub mod criterion;