Skip to content
Myr

scheduler.rs

This file

Path

src/benchmark/scheduler.rs

156 lines · 4.2 KiB · Rust

Last changed by

Export selected metrics side by side in CSVDavid Peterbefore adoption067ee70

History of this file

Take it

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

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 1–2why, one step back
1use super::benchmark_result::BenchmarkResult;
2use super::executor::{Executor, MockExecutor, RawExecutor, ShellExecutor};

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

line 3why, one step back
3use super::Benchmark;

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 4why, one step back
4

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

line 5why, one step back
5use crate::command::Commands;

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 6why, one step back
6use crate::export::ExportManager;

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

line 7why, one step back
7use crate::options::{ExecutorKind, Options};

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 8–40why, one step back
8
9use anyhow::Result;1011pub struct Scheduler<'a> {12 commands: &'a Commands<'a>,13 options: &'a Options,14 export_manager: &'a ExportManager,15 results: Vec<BenchmarkResult>,16}1718impl<'a> Scheduler<'a> {19 pub fn new(20 commands: &'a Commands,21 options: &'a Options,22 export_manager: &'a ExportManager,23 ) -> Self {24 Self {25 commands,26 options,27 export_manager,28 results: vec![],29 }30 }3132 pub fn run_benchmarks(&mut self) -> Result<()> {33 let mut executor: Box<dyn Executor> = match self.options.executor_kind {34 ExecutorKind::Raw => Box::new(RawExecutor::new(self.options)),35 ExecutorKind::Mock(ref shell) => Box::new(MockExecutor::new(shell.clone())),36 ExecutorKind::Shell(ref shell) => Box::new(ShellExecutor::new(shell, self.options)),37 };3839 executor.calibrate()?;40

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

lines 41–44why, one step back
41 for (number, cmd) in self.commands.iter().enumerate() {
42 self.results.push(43 Benchmark::new(number, cmd, self.options, &*executor).run(self.results.first())?,44 );

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 45–47why, one step back
45
46 // We export results after each individual benchmark, because47 // we would risk losing them if a later benchmark fails.

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

line 48why, one step back
48 self.export_manager.write_results(&self.results, true)?;

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 49–54why, one step back
49 }
5051 Ok(())52 }5354 pub fn final_export(&self) -> Result<()> {

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

line 55why, one step back
55 self.export_manager.write_results(&self.results, false)

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 56–57why, one step back
56 }
57}

Basic scheduler testDavid Peterbefore adoption0705d6c

lines 58–64why, one step back
58
59#[cfg(test)]60fn generate_results(args: &[&'static str]) -> Result<Vec<BenchmarkResult>> {61 use crate::cli::get_cli_arguments;6263 let args = ["hyperfine", "--debug-mode", "--style=none"]64 .iter()

ClippyDavid Peterbefore adoptionebcf794

line 65why, one step back
65 .chain(args);

Basic scheduler testDavid Peterbefore adoption0705d6c

lines 66–71why, one step back
66 let cli_arguments = get_cli_arguments(args);
67 let mut options = Options::from_cli_arguments(&cli_arguments)?;6869 assert_eq!(options.executor_kind, ExecutorKind::Mock(None));7071 let commands = Commands::from_cli_arguments(&cli_arguments)?;

Export selected metrics side by side in CSVDavid Peterbefore adoption067ee70

line 72why, one step back
72 let export_manager = ExportManager::from_cli_arguments(&cli_arguments, &options.metrics)?;

Basic scheduler testDavid Peterbefore adoption0705d6c

lines 73–83why, one step back
73
74 options.validate_against_command_list(&commands)?;7576 let mut scheduler = Scheduler::new(&commands, &options, &export_manager);7778 scheduler.run_benchmarks()?;79 Ok(scheduler.results)80}8182#[test]83fn scheduler_basic() -> Result<()> {

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

line 84why, one step back
84 insta::assert_yaml_snapshot!(generate_results(&["--runs=2", "sleep 0.123", "sleep 0.456"])?, @"

Basic scheduler testDavid Peterbefore adoption0705d6c

line 85why, one step back
85 - command: sleep 0.123

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

lines 86–89why, one step back
86 measurements:
87 - time_wall_clock:88 value: 0.12389 unit: second

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

lines 90–92why, one step back
90 time_cpu:
91 value: 092 unit: second

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

lines 93–105why, one step back
93 time_user:
94 value: 095 unit: second96 time_system:97 value: 098 unit: second99 memory_peak_resident:100 value: 0101 unit: byte102 exit_code: 0103 - time_wall_clock:104 value: 0.123105 unit: second

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

lines 106–108why, one step back
106 time_cpu:
107 value: 0108 unit: second

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

lines 109–118why, one step back
109 time_user:
110 value: 0111 unit: second112 time_system:113 value: 0114 unit: second115 memory_peak_resident:116 value: 0117 unit: byte118 exit_code: 0

Basic scheduler testDavid Peterbefore adoption0705d6c

line 119why, one step back
119 - command: sleep 0.456

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

lines 120–123why, one step back
120 measurements:
121 - time_wall_clock:122 value: 0.456123 unit: second

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

lines 124–126why, one step back
124 time_cpu:
125 value: 0126 unit: second

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

lines 127–139why, one step back
127 time_user:
128 value: 0129 unit: second130 time_system:131 value: 0132 unit: second133 memory_peak_resident:134 value: 0135 unit: byte136 exit_code: 0137 - time_wall_clock:138 value: 0.456139 unit: second

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

lines 140–142why, one step back
140 time_cpu:
141 value: 0142 unit: second

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

lines 143–152why, one step back
143 time_user:
144 value: 0145 unit: second146 time_system:147 value: 0148 unit: second149 memory_peak_resident:150 value: 0151 unit: byte152 exit_code: 0

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

line 153why, one step back
153 ");

Basic scheduler testDavid Peterbefore adoption0705d6c

lines 154–156why, one step back
154
155 Ok(())156}