1 | //! This module provides an extension trait which allows in-process profilers |
2 | //! to be hooked into the `--profile-time` argument at compile-time. Users of |
3 | //! out-of-process profilers such as perf don't need to do anything special. |
4 | |
5 | use std::path::Path; |
6 | |
7 | /// Extension trait for external crates to implement which provides start/stop |
8 | /// hooks when profiling (but not when benchmarking) functions. |
9 | pub trait Profiler { |
10 | /// This function is called when Criterion.rs starts profiling a particular |
11 | /// benchmark. It provides the stringified benchmark ID and |
12 | /// a path to a directory where the profiler can store its data. |
13 | fn start_profiling(&mut self, benchmark_id: &str, benchmark_dir: &Path); |
14 | |
15 | /// This function is called after Criterion.rs stops profiling a particular |
16 | /// benchmark. The benchmark ID and directory are the same as in the call |
17 | /// to `start`, provided for convenience. |
18 | fn stop_profiling(&mut self, benchmark_id: &str, benchmark_dir: &Path); |
19 | } |
20 | |
21 | /// Dummy profiler implementation, representing cases where the profiler is |
22 | /// an external process (eg. perftools, etc.) which do not require start/stop |
23 | /// hooks. This implementation does nothing and is used as the default. |
24 | pub struct ExternalProfiler; |
25 | impl Profiler for ExternalProfiler { |
26 | fn start_profiling(&mut self, _benchmark_id: &str, _benchmark_dir: &Path) {} |
27 | fn stop_profiling(&mut self, _benchmark_id: &str, _benchmark_dir: &Path) {} |
28 | } |
29 | |