Skip to content
Myr

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 file

Take 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 back
1use std::collections::BTreeMap;

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 2why, one step back
2

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 3why, one step back
3use serde::Serialize;

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 4–7why, one step back
4use 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 back
8use crate::metric::{Metric, MetricSelection, Stats};

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 9–11why, one step back
9
10use anyhow::Result;11

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 12–17why, one step back
12mod 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 back
18struct HyperfineSummary<'a> {

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 19–20why, one step back
19 schema_version: u32,
20 metadata: &'a Metadata,

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 21why, one step back
21 primary_metric: &'static str,

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 22why, one step back
22 results: Vec<JsonBenchmarkResult<'a>>,

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 23–24why, one step back
23}
24

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 25–28why, one step back
25#[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 back
29 summary: BTreeMap<&'static str, StatisticalSummary>,

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 30–33why, one step back
30}
3132#[derive(Serialize)]33struct StatisticalSummary {

Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0

lines 34–35why, one step back
34 #[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 back
36 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 back
45 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 back
58 }

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 59–61why, one step back
59 }
60}61

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 62why, one step back
62#[derive(Default)]

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 63–65why, one step back
63pub 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 back
66
67impl Exporter for JsonExporter {

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 68why, one step back
68 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 back
69 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 back
72 primary_metric: primary.metric.name(),

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 73–74why, one step back
73 results: results
74 .iter()

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 75why, one step back
75 .map(|result| JsonBenchmarkResult {

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 76why, one step back
76 result,

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 77–85why, one step back
77 summary: Metric::ALL
78 .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 back
86 })
87 .collect(),

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 88–90why, one step back
88 })?;
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 back
91 }
92}