pub struct Profiler { /* private fields */ }Expand description
The Profiler struct is used to trace events.
The events will be stored on disk, if the profiler instance is dropped.
Implementations§
Source§impl Profiler
impl Profiler
Sourcepub fn from_path(path: impl Into<PathBuf>) -> Result<Self, Box<dyn Error>>
pub fn from_path(path: impl Into<PathBuf>) -> Result<Self, Box<dyn Error>>
Creates a new Profiler with the given path.
The profiling results will be stored at <path>.events, <path>.strings, etc.
§Errors
The method will fail if the path does not exist or some other error occurrs while initializing the profiler.
Sourcepub fn from_name(name: impl AsRef<str>) -> Result<Self, Box<dyn Error>>
pub fn from_name(name: impl AsRef<str>) -> Result<Self, Box<dyn Error>>
Creates a new Profiler from a given application name.
The profiling results will be stored at ./trace/<name>-<pid>.events, etc.
§Errors
The method will fail if the path does not exist or some other error occurrs while initializing the profiler.
Sourcepub fn enable(&self)
pub fn enable(&self)
Sourcepub fn disable(&self)
pub fn disable(&self)
Disables the Profiler.
This method will make the profiler stop recording any new events but will still write all stored results to disk if dropped.
Sourcepub fn trace(&self, category: &str, label: &str) -> Guard<'_>
pub fn trace(&self, category: &str, label: &str) -> Guard<'_>
Starts profiling an event with the given category and label.
Examples found in repository?
20fn parse_expression(profiler: &Profiler, input: &str) -> Result<Expr, &'static str> {
21 // We will trace the `parse_expression` function using this.
22 let _p = profiler.trace("parsing", "expression");
23
24 input
25 .parse::<i64>()
26 .map(|num| Expr::Number(num))
27 .or_else(|_| {
28 if input.chars().all(char::is_alphabetic) {
29 Ok(Expr::Identifier(input.to_string()))
30 } else {
31 Err("invalid identifier")
32 }
33 })
34 .map_err(|_| "invalid expression")
35}