hydro_deploy/rust_crate/
tracing_options.rs

1#![allow(clippy::too_many_arguments, reason = "buildstructor")]
2#![allow(
3    unexpected_cfgs,
4    reason = "https://github.com/BrynCooke/buildstructor/issues/192"
5)]
6
7use std::borrow::Cow;
8use std::path::PathBuf;
9
10use inferno::collapse::dtrace::Options as DtraceOptions;
11use inferno::collapse::perf::Options as PerfOptions;
12
13type FlamegraphOptions = inferno::flamegraph::Options<'static>;
14
15/// `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>;
20
21#[derive(Clone, buildstructor::Builder)]
22#[non_exhaustive] // Prevent direct construction.
23pub struct TracingOptions {
24    /// Samples per second.
25    pub frequency: u32,
26
27    /// Output filename for `samply`. Example: `my_worker.profile`.
28    pub samply_outfile: Option<PathBuf>,
29
30    /// Output filename for the raw data emitted by `perf record`. Example: `my_worker.perf.data`.
31    pub perf_raw_outfile: Option<PathBuf>,
32
33    // /// 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.
36    pub fold_outfile: Option<PathBuf>,
37    pub fold_dtrace_options: Option<DtraceOptions>,
38    pub fold_perf_options: Option<PerfOptions>,
39    /// If set, what to write the output flamegraph SVG file to.
40    pub 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.
42    pub flamegraph_options: Option<fn() -> FlamegraphOptions>,
43
44    /// 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`].
49    pub setup_command: Option<CowStr>,
50}
51
52pub 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'";