Skip to content
Myr

csv.rs

This file

Path

src/export/csv.rs

150 lines · 4.5 KiB · Rust

Last changed by

Merge pull request #968 from sharkdp/codex/parameter-metadataDavid Peterbefore adoption05de077

History of this file

Take it

The walk stopped after 200 commits: lines older than ca9e29a point at it.

Fix pipeline!David Peterbefore adoptionca9e29a

lines 1–6why, one step back
1use std::borrow::Cow;
23use csv::WriterBuilder;45use super::Exporter;6use crate::benchmark::benchmark_result::BenchmarkResult;

Add new --sort optionDavid Peterbefore adoptionac617c8

line 7why, one step back
7use crate::options::SortOrder;

Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24

line 8why, one step back
8use crate::quantity::TimeUnit;

Fix pipeline!David Peterbefore adoptionca9e29a

lines 9–15why, one step back
9
10use anyhow::Result;1112#[derive(Default)]13pub struct CsvExporter {}1415impl Exporter for CsvExporter {

Add new --sort optionDavid Peterbefore adoptionac617c8

lines 16–18why, one step back
16 fn serialize(
17 &self,18 results: &[BenchmarkResult],

Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24

line 19why, one step back
19 _unit: Option<TimeUnit>,

Add new --sort optionDavid Peterbefore adoptionac617c8

lines 20–21why, one step back
20 _sort_order: SortOrder,
21 ) -> Result<Vec<u8>> {

Merge pull request #966 from sharkdp/codex/csv-six-decimalsDavid Peterbefore adoption430dc5e

lines 22–23why, one step back
22 const CSV_PRECISION: usize = 6;
23

Fix pipeline!David Peterbefore adoptionca9e29a

lines 24–35why, one step back
24 let mut writer = WriterBuilder::new().from_writer(vec![]);
2526 {27 let mut headers: Vec<Cow<[u8]>> = [28 // The list of times and exit codes cannot be exported to the CSV file - omit them.29 "command", "mean", "stddev", "median", "user", "system", "min", "max",30 ]31 .iter()32 .map(|x| Cow::Borrowed(x.as_bytes()))33 .collect();34 if let Some(res) = results.first() {35 for param_name in res.parameters.keys() {

style: simplify string interpolationHamir Mahalbefore adoptionef12632

line 36why, one step back
36 headers.push(Cow::Owned(format!("parameter_{param_name}").into_bytes()));

Fix pipeline!David Peterbefore adoptionca9e29a

lines 37–52why, one step back
37 }
38 }39 writer.write_record(headers)?;40 }4142 for res in results {43 let mut fields = vec![Cow::Borrowed(res.command.as_bytes())];44 for f in &[45 res.mean,46 res.stddev.unwrap_or(0.0),47 res.median,48 res.user,49 res.system,50 res.min,51 res.max,52 ] {

Merge pull request #966 from sharkdp/codex/csv-six-decimalsDavid Peterbefore adoption430dc5e

line 53why, one step back
53 fields.push(Cow::Owned(format!("{f:.CSV_PRECISION$}").into_bytes()))

Fix pipeline!David Peterbefore adoptionca9e29a

lines 54–55why, one step back
54 }
55 for v in res.parameters.values() {

Merge pull request #968 from sharkdp/codex/parameter-metadataDavid Peterbefore adoption05de077

line 56why, one step back
56 fields.push(Cow::Borrowed(v.value.as_bytes()))

Fix pipeline!David Peterbefore adoptionca9e29a

lines 57–66why, one step back
57 }
58 writer.write_record(fields)?;59 }6061 Ok(writer.into_inner()?)62 }63}6465#[test]66fn test_csv() {

Merge pull request #968 from sharkdp/codex/parameter-metadataDavid Peterbefore adoption05de077

line 67why, one step back
67 use crate::benchmark::benchmark_result::Parameter;

Fix pipeline!David Peterbefore adoptionca9e29a

lines 68–72why, one step back
68 use std::collections::BTreeMap;
69 let exporter = CsvExporter::default();7071 let results = vec![72 BenchmarkResult {

Simplify CSV testsDavid Peterbefore adoption0d2e3a4

lines 73–74why, one step back
73 command: String::from("command_a"),
74 command_with_unused_parameters: String::from("command_a"),

Fix pipeline!David Peterbefore adoptionca9e29a

lines 75–82why, one step back
75 mean: 1.0,
76 stddev: Some(2.0),77 median: 1.0,78 user: 3.0,79 system: 4.0,80 min: 5.0,81 max: 6.0,82 times: Some(vec![7.0, 8.0, 9.0]),

Initial work on tracking memory usageDavid Peterbefore adoption6556b2b

line 83why, one step back
83 memory_usage_byte: None,

Fix pipeline!David Peterbefore adoptionca9e29a

lines 84–86why, one step back
84 exit_codes: vec![Some(0), Some(0), Some(0)],
85 parameters: {86 let mut params = BTreeMap::new();

Merge pull request #968 from sharkdp/codex/parameter-metadataDavid Peterbefore adoption05de077

lines 87–100why, one step back
87 params.insert(
88 "foo".into(),89 Parameter {90 value: "one".into(),91 is_unused: false,92 },93 );94 params.insert(95 "bar".into(),96 Parameter {97 value: "two".into(),98 is_unused: false,99 },100 );

Fix pipeline!David Peterbefore adoptionca9e29a

lines 101–104why, one step back
101 params
102 },103 },104 BenchmarkResult {

Simplify CSV testsDavid Peterbefore adoption0d2e3a4

lines 105–106why, one step back
105 command: String::from("command_b"),
106 command_with_unused_parameters: String::from("command_b"),

Fix pipeline!David Peterbefore adoptionca9e29a

lines 107–114why, one step back
107 mean: 11.0,
108 stddev: Some(12.0),109 median: 11.0,110 user: 13.0,111 system: 14.0,112 min: 15.0,113 max: 16.5,114 times: Some(vec![17.0, 18.0, 19.0]),

Initial work on tracking memory usageDavid Peterbefore adoption6556b2b

line 115why, one step back
115 memory_usage_byte: None,

Fix pipeline!David Peterbefore adoptionca9e29a

lines 116–118why, one step back
116 exit_codes: vec![Some(0), Some(0), Some(0)],
117 parameters: {118 let mut params = BTreeMap::new();

Merge pull request #968 from sharkdp/codex/parameter-metadataDavid Peterbefore adoption05de077

lines 119–132why, one step back
119 params.insert(
120 "foo".into(),121 Parameter {122 value: "one".into(),123 is_unused: false,124 },125 );126 params.insert(127 "bar".into(),128 Parameter {129 value: "seven".into(),130 is_unused: false,131 },132 );

Fix pipeline!David Peterbefore adoptionca9e29a

lines 133–136why, one step back
133 params
134 },135 },136 ];

Move more tests to instaDavid Peterbefore adoptionda399ab

lines 137–138why, one step back
137
138 let actual = String::from_utf8(

Add new --sort optionDavid Peterbefore adoptionac617c8

line 139why, one step back
139 exporter

Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24

line 140why, one step back
140 .serialize(&results, Some(TimeUnit::Second), SortOrder::Command)

Add new --sort optionDavid Peterbefore adoptionac617c8

lines 141–143why, one step back
141 .unwrap(),
142 )143 .unwrap();

Fix pipeline!David Peterbefore adoptionca9e29a

line 144why, one step back
144

Move more tests to instaDavid Peterbefore adoptionda399ab

lines 145–146why, one step back
145 insta::assert_snapshot!(actual, @r#"
146 command,mean,stddev,median,user,system,min,max,parameter_bar,parameter_foo

Merge pull request #966 from sharkdp/codex/csv-six-decimalsDavid Peterbefore adoption430dc5e

lines 147–148why, one step back
147 command_a,1.000000,2.000000,1.000000,3.000000,4.000000,5.000000,6.000000,two,one
148 command_b,11.000000,12.000000,11.000000,13.000000,14.000000,15.000000,16.500000,seven,one

Move more tests to instaDavid Peterbefore adoptionda399ab

line 149why, one step back
149 "#);

Fix pipeline!David Peterbefore adoptionca9e29a

line 150why, one step back
150}