Skip to main content

cu_profiler_core/
metadata.rs

1//! Run-level metadata attached to every report and baseline record.
2
3use serde::{Deserialize, Serialize};
4
5/// Which execution backend produced a measurement.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "kebab-case")]
8pub enum BackendKind {
9    /// Replayed from recorded logs (deterministic; used for tests and `inspect`).
10    Recorded,
11    /// `solana-program-test` in-process runtime.
12    ProgramTest,
13    /// `BanksClient` against a test validator.
14    BanksClient,
15    /// `mollusk-svm` harness (real compute-unit metering of an SBF program).
16    Mollusk,
17    /// RPC `simulateTransaction` (designed, not implemented in v1).
18    RpcSimulation,
19}
20
21impl BackendKind {
22    /// Stable lowercase identifier.
23    #[must_use]
24    pub fn as_str(self) -> &'static str {
25        match self {
26            Self::Recorded => "recorded",
27            Self::ProgramTest => "program-test",
28            Self::BanksClient => "banks-client",
29            Self::Mollusk => "mollusk",
30            Self::RpcSimulation => "rpc-simulation",
31        }
32    }
33}
34
35/// Whether instrumentation markers were active during a run.
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
37#[serde(rename_all = "kebab-case")]
38pub enum InstrumentationMode {
39    /// No profiler markers expected.
40    Off,
41    /// Profiler markers expected and parsed.
42    On,
43}
44
45/// Metadata describing the environment a report was generated in.
46#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
47pub struct RunMetadata {
48    /// Version of `cu-profiler` that produced the report.
49    pub profiler_version: String,
50    /// Backend used.
51    pub backend: BackendKind,
52    /// Instrumentation mode.
53    pub instrumentation: InstrumentationMode,
54    /// Git commit, if discoverable.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub git_commit: Option<String>,
57    /// Solana/Agave crate versions, if known.
58    #[serde(default, skip_serializing_if = "Vec::is_empty")]
59    pub solana_versions: Vec<String>,
60    /// RFC3339 timestamp, if the caller chose to stamp one.
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub generated_at: Option<String>,
63}
64
65impl RunMetadata {
66    /// Metadata for a recorded-logs run with the given profiler version.
67    #[must_use]
68    pub fn recorded(profiler_version: impl Into<String>) -> Self {
69        Self {
70            profiler_version: profiler_version.into(),
71            backend: BackendKind::Recorded,
72            instrumentation: InstrumentationMode::Off,
73            git_commit: None,
74            solana_versions: Vec::new(),
75            generated_at: None,
76        }
77    }
78}