Skip to main content

cu_profiler_core/backend/
mod.rs

1//! Execution backends.
2//!
3//! A backend turns a [`Scenario`] into raw logs. v1 ships a fully-working
4//! [`RecordedLogsBackend`] (deterministic, used for tests, fixtures and the
5//! `inspect` command) and *skeleton* live backends whose interfaces are defined
6//! but which return [`crate::Error::BackendUnimplemented`] until wired to
7//! `solana-program-test` / `BanksClient`.
8
9mod banks_client;
10mod program_test;
11mod recorded;
12
13pub use banks_client::BanksClientBackend;
14pub use program_test::ProgramTestBackend;
15pub use recorded::RecordedLogsBackend;
16
17use crate::Result;
18use crate::metadata::BackendKind;
19use crate::scenario::Scenario;
20
21/// The raw result of executing a scenario.
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct SimulationOutput {
24    /// Program logs, one entry per line.
25    pub logs: Vec<String>,
26    /// Whether the transaction succeeded.
27    pub success: bool,
28}
29
30impl SimulationOutput {
31    /// A successful output from the given logs.
32    #[must_use]
33    pub fn success(logs: Vec<String>) -> Self {
34        Self {
35            logs,
36            success: true,
37        }
38    }
39}
40
41/// Anything that can execute a scenario and return logs.
42pub trait ExecutionBackend {
43    /// Which kind of backend this is (recorded in report metadata).
44    fn kind(&self) -> BackendKind;
45
46    /// Execute `scenario`, returning its raw logs.
47    ///
48    /// # Errors
49    /// Returns [`crate::Error::Simulation`] on execution failure, or
50    /// [`crate::Error::BackendUnimplemented`] for skeleton backends.
51    fn run(&self, scenario: &Scenario) -> Result<SimulationOutput>;
52}