1#![allow(clippy::too_many_arguments, reason = "buildstructor")]
2#![allow(
3 unexpected_cfgs,
4 reason = "https://github.com/BrynCooke/buildstructor/issues/192"
5)]
67use std::borrow::Cow;
8use std::path::PathBuf;
910use inferno::collapse::dtrace::Options as DtraceOptions;
11use inferno::collapse::perf::Options as PerfOptions;
1213type FlamegraphOptions = inferno::flamegraph::Options<'static>;
1415/// `Cow<'static, str>`.
16///
17/// `buildstructor` doesn't support `Into<_>` for types with parameters (like `Cow<'static, str>`),
18/// so we trick it by defining a type alias.
19pub type CowStr = Cow<'static, str>;
2021#[derive(Clone, buildstructor::Builder)]
22#[non_exhaustive] // Prevent direct construction.
23pub struct TracingOptions {
24/// Samples per second.
25pub frequency: u32,
2627/// Output filename for `samply`. Example: `my_worker.profile`.
28pub samply_outfile: Option<PathBuf>,
2930/// Output filename for the raw data emitted by `perf record`. Example: `my_worker.perf.data`.
31pub perf_raw_outfile: Option<PathBuf>,
3233// /// Output filename for `perf script -i <`[`Self::perf_raw_outfile`]`>`. Example: `my_worker.perf`.
34 // pub perf_script_outfile: Option<PathBuf>,
35/// If set, what the write the folded output to.
36pub fold_outfile: Option<PathBuf>,
37pub fold_dtrace_options: Option<DtraceOptions>,
38pub fold_perf_options: Option<PerfOptions>,
39/// If set, what to write the output flamegraph SVG file to.
40pub flamegraph_outfile: Option<PathBuf>,
41// This type is super annoying and isn't `clone` and has a lifetime... so wrap in fn pointer for now.
42pub flamegraph_options: Option<fn() -> FlamegraphOptions>,
4344/// Command to setup tracing before running the command, i.e. to install `perf` or set kernel flags.
45 ///
46 /// NOTE: Currently is only run for remote/cloud ssh hosts, not local hosts.
47 ///
48 /// Example: see [`DEBIAN_PERF_SETUP_COMMAND`].
49pub setup_command: Option<CowStr>,
50}
5152pub const DEBIAN_PERF_SETUP_COMMAND: &str = "sudo sh -c 'apt update && apt install -y linux-perf binutils && echo -1 > /proc/sys/kernel/perf_event_paranoid && echo 0 > /proc/sys/kernel/kptr_restrict'";