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 fileTake 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 back1use 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 back3use super::Benchmark;Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 4why, one step back4Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 5why, one step back5use crate::command::Commands;Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 6why, one step back6use crate::export::ExportManager;Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 7why, one step back7use crate::options::{ExecutorKind, Options};Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 8–40why, one step back89use 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()?;40Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 41–44why, one step back41 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 back4546 // 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 back48 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 back49 }5051 Ok(())52 }5354 pub fn final_export(&self) -> Result<()> {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 55why, one step back55 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 back56 }57}Basic scheduler testDavid Peterbefore adoption0705d6c
lines 58–64why, one step back5859#[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 back65 .chain(args);Basic scheduler testDavid Peterbefore adoption0705d6c
lines 66–71why, one step back66 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 back72 let export_manager = ExportManager::from_cli_arguments(&cli_arguments, &options.metrics)?;Basic scheduler testDavid Peterbefore adoption0705d6c
lines 73–83why, one step back7374 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 back84 insta::assert_yaml_snapshot!(generate_results(&["--runs=2", "sleep 0.123", "sleep 0.456"])?, @"Basic scheduler testDavid Peterbefore adoption0705d6c
line 85why, one step back85 - command: sleep 0.123Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 86–89why, one step back86 measurements:87 - time_wall_clock:88 value: 0.12389 unit: secondAlternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 90–92why, one step back90 time_cpu:91 value: 092 unit: secondMerge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 93–105why, one step back93 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: secondAlternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 106–108why, one step back106 time_cpu:107 value: 0108 unit: secondMerge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 109–118why, one step back109 time_user:110 value: 0111 unit: second112 time_system:113 value: 0114 unit: second115 memory_peak_resident:116 value: 0117 unit: byte118 exit_code: 0Basic scheduler testDavid Peterbefore adoption0705d6c
line 119why, one step back119 - command: sleep 0.456Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 120–123why, one step back120 measurements:121 - time_wall_clock:122 value: 0.456123 unit: secondAlternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 124–126why, one step back124 time_cpu:125 value: 0126 unit: secondMerge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 127–139why, one step back127 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: secondAlternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 140–142why, one step back140 time_cpu:141 value: 0142 unit: secondMerge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 143–152why, one step back143 time_user:144 value: 0145 unit: second146 time_system:147 value: 0148 unit: second149 memory_peak_resident:150 value: 0151 unit: byte152 exit_code: 0Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 153why, one step back153 ");Basic scheduler testDavid Peterbefore adoption0705d6c
lines 154–156why, one step back154155 Ok(())156}