json.rs
This file
Path
src/export/json.rs
92 lines · 2.4 KiB · Rust
Last changed by
Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
History of this fileTake it
The walk stopped after 200 commits: lines older than ab5ae5f point at it.
Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1why, one step back1use std::collections::BTreeMap;Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 2why, one step back2Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 3why, one step back3use serde::Serialize;Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 4–7why, one step back4use serde_json::to_vec_pretty;56use super::Exporter;7use crate::benchmark::benchmark_result::BenchmarkResult;Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 8why, one step back8use crate::metric::{Metric, MetricSelection, Stats};Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 9–11why, one step back910use anyhow::Result;11Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 12–17why, one step back12mod metadata;13use metadata::Metadata;1415const JSON_SCHEMA_VERSION: u32 = 2;1617#[derive(Serialize)]Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 18why, one step back18struct HyperfineSummary<'a> {Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 19–20why, one step back19 schema_version: u32,20 metadata: &'a Metadata,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 21why, one step back21 primary_metric: &'static str,Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 22why, one step back22 results: Vec<JsonBenchmarkResult<'a>>,Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 23–24why, one step back23}24Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 25–28why, one step back25#[derive(Serialize)]26struct JsonBenchmarkResult<'a> {27 #[serde(flatten)]28 result: &'a BenchmarkResult,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 29why, one step back29 summary: BTreeMap<&'static str, StatisticalSummary>,Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 30–33why, one step back30}3132#[derive(Serialize)]33struct StatisticalSummary {Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0
lines 34–35why, one step back34 #[serde(skip_serializing_if = "Option::is_none")]35 unit: Option<&'static str>,Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 36–44why, one step back36 count: usize,37 mean: f64,38 stddev: Option<f64>,39 median: f64,40 min: f64,41 max: f64,42}4344impl StatisticalSummary {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 45–57why, one step back45 fn new(metric: Metric, stats: Stats) -> Self {46 Self {47 unit: match metric.base_unit().symbol {48 "s" => Some("second"),49 "B" => Some("byte"),50 _ => None,51 },52 count: stats.count,53 mean: stats.mean,54 stddev: stats.stddev,55 median: stats.median,56 min: stats.min,57 max: stats.max,Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0
line 58why, one step back58 }Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 59–61why, one step back59 }60}61Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 62why, one step back62#[derive(Default)]Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 63–65why, one step back63pub struct JsonExporter {64 metadata: Metadata,65}Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 66–67why, one step back6667impl Exporter for JsonExporter {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 68why, one step back68 fn serialize(&self, results: &[BenchmarkResult], primary: MetricSelection) -> Result<Vec<u8>> {Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 69–71why, one step back69 let mut output = to_vec_pretty(&HyperfineSummary {70 schema_version: JSON_SCHEMA_VERSION,71 metadata: &self.metadata,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 72why, one step back72 primary_metric: primary.metric.name(),Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 73–74why, one step back73 results: results74 .iter()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 75why, one step back75 .map(|result| JsonBenchmarkResult {Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 76why, one step back76 result,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 77–85why, one step back77 summary: Metric::ALL78 .iter()79 .copied()80 .filter_map(|metric| {81 metric.summarize(&result.measurements).map(|stats| {82 (metric.name(), StatisticalSummary::new(metric, stats))83 })84 })85 .collect(),Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 86–87why, one step back86 })87 .collect(),Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 88–90why, one step back88 })?;89 output.push(b'\n');90 Ok(output)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 91–92why, one step back91 }92}