Skip to main content

ExportUseCase

Struct ExportUseCase 

Source
pub struct ExportUseCase;
Expand description

Use case for exporting receipts to different formats.

Implementations§

Source§

impl ExportUseCase

Source

pub fn export_run(receipt: &RunReceipt, format: ExportFormat) -> Result<String>

Export a RunReceipt to the specified format.

let receipt = RunReceipt {
    schema: RUN_SCHEMA_V1.to_string(),
    tool: ToolInfo { name: "perfgate".into(), version: "0.1.0".into() },
    run: RunMeta {
        id: "r1".into(),
        started_at: "2024-01-01T00:00:00Z".into(),
        ended_at: "2024-01-01T00:00:01Z".into(),
        host: HostInfo { os: "linux".into(), arch: "x86_64".into(),
            cpu_count: None, memory_bytes: None, hostname_hash: None },
    },
    bench: BenchMeta {
        name: "bench".into(), cwd: None,
        command: vec!["echo".into()], repeat: 1, warmup: 0,
        work_units: None, timeout_ms: None,
    },
    samples: vec![Sample {
        wall_ms: 42, exit_code: 0, warmup: false, timed_out: false,
        cpu_ms: None, page_faults: None, ctx_switches: None,
        max_rss_kb: None, binary_bytes: None, stdout: None, stderr: None,
    }],
    stats: Stats {
        wall_ms: U64Summary { median: 42, min: 42, max: 42 },
        cpu_ms: None, page_faults: None, ctx_switches: None,
        max_rss_kb: None, binary_bytes: None, throughput_per_s: None,
    },
};
let csv = ExportUseCase::export_run(&receipt, ExportFormat::Csv).unwrap();
assert!(csv.contains("bench"));
assert!(csv.contains("42"));
Source

pub fn export_compare( receipt: &CompareReceipt, format: ExportFormat, ) -> Result<String>

Export a CompareReceipt to the specified format.

let receipt = CompareReceipt {
    schema: COMPARE_SCHEMA_V1.to_string(),
    tool: ToolInfo { name: "perfgate".into(), version: "0.1.0".into() },
    bench: BenchMeta {
        name: "bench".into(), cwd: None,
        command: vec!["echo".into()], repeat: 1, warmup: 0,
        work_units: None, timeout_ms: None,
    },
    baseline_ref: CompareRef { path: None, run_id: None },
    current_ref: CompareRef { path: None, run_id: None },
    budgets: BTreeMap::new(),
    deltas: BTreeMap::from([(Metric::WallMs, Delta {
        baseline: 100.0, current: 105.0, ratio: 1.05, pct: 0.05,
        regression: 0.05, statistic: MetricStatistic::Median,
        significance: None, status: MetricStatus::Pass,
    })]),
    verdict: Verdict {
        status: VerdictStatus::Pass,
        counts: VerdictCounts { pass: 1, warn: 0, fail: 0 },
        reasons: vec![],
    },
};
let csv = ExportUseCase::export_compare(&receipt, ExportFormat::Csv).unwrap();
assert!(csv.contains("wall_ms"));
assert!(csv.contains("100"));

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.