main.rs
This file
Path
src/main.rs
102 lines · 3.4 KiB · Rust
Last changed by
Add --env for benchmark environment overridesDavid Peterbefore adoption6dddb02
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–6why, one step back1#![cfg_attr(2 all(windows, feature = "windows_process_extensions_main_thread_handle"),3 feature(windows_process_extensions_main_thread_handle)4)]56use std::env;Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
line 7why, one step back7use std::io::{self, Write};Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 8–11why, one step back89use benchmark::scheduler::Scheduler;10use cli::get_cli_arguments;11use command::Commands;Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
line 12why, one step back12use error::ConsoleOutputError;Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 13why, one step back13use export::ExportManager;Require an explicit shell choice for shell operatorsDavid Peterbefore adoption6cb7bb0
line 14why, one step back14use options::{ExecutorKind, Options};Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 15why, one step back15Require an explicit shell choice for shell operatorsDavid Peterbefore adoption6cb7bb0
line 16why, one step back16use anyhow::{bail, Result};Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 17–23why, one step back17use colored::*;1819pub mod benchmark;20pub mod cli;21pub mod command;22pub mod error;23pub mod export;Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 24why, one step back24pub mod metric;Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 25–28why, one step back25pub mod options;26pub mod outlier_detection;27pub mod output;28pub mod parameter;Merge pull request #967 from sharkdp/codex/quantity-formattingDavid Peterbefore adoptiona6c3010
line 29why, one step back29pub mod quantity;Require an explicit shell choice for shell operatorsDavid Peterbefore adoption6cb7bb0
line 30why, one step back30pub mod shell_syntax;Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 31–39why, one step back31pub mod timer;32pub mod util;3334fn run() -> Result<()> {35 // Enabled ANSI colors on Windows 1036 #[cfg(windows)]37 colored::control::set_virtual_terminal(true).unwrap();3839 let cli_arguments = get_cli_arguments(env::args_os());Multiple output policiesDavid Peterbefore adoption99d24b7
line 40why, one step back40 let mut options = Options::from_cli_arguments(&cli_arguments)?;Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 41why, one step back41 let commands = Commands::from_cli_arguments(&cli_arguments)?;Merge pull request #950 from Likio3000/codex/preserve-exports-on-invalid-optionsDavid Peterbefore adoptiond3d67fc
line 42why, one step back42 options.validate_against_command_list(&commands)?;Require an explicit shell choice for shell operatorsDavid Peterbefore adoption6cb7bb0
lines 43–49why, one step back4344 if matches!(options.executor_kind, ExecutorKind::Raw)45 && !cli_arguments.get_flag("no-shell")46 && cli_arguments.get_one::<String>("shell").is_none()47 {48 for command in commands.iter() {49 let command_line = command.get_command_line();Add --env for benchmark environment overridesDavid Peterbefore adoption6dddb02
lines 50–57why, one step back50 if shell_syntax::starts_with_assignment(&command_line) {51 bail!(52 "Cannot run '{command_line}' directly because it starts with a variable assignment.\n\53 Use the --env option to set environment variables, for example:\n\n \54 hyperfine --env 'OMP_NUM_THREADS=8 CFLAGS=\"-O3 -march=native\"' 'my_command'\n\n\55 Alternatively, use -S / --shell=default to run the command in a shell."56 );57 }Require an explicit shell choice for shell operatorsDavid Peterbefore adoption6cb7bb0
lines 58–71why, one step back58 if let Some(operator) = shell_syntax::first_unquoted_operator(&command_line) {59 bail!(60 concat!(61 "Command '{command_line}' contains unquoted shell syntax ('{operator}').\n",62 "Explicitly choose how to execute it:\n",63 " -S / --shell=default Interpret shell syntax.\n",64 " -N / --shell=none Run directly, passing '{operator}' as a literal argument.",65 ),66 command_line = command_line,67 operator = operator,68 );69 }70 }71 }Merge pull request #950 from Likio3000/codex/preserve-exports-on-invalid-optionsDavid Peterbefore adoptiond3d67fc
line 72why, one step back72Export selected metrics side by side in CSVDavid Peterbefore adoption067ee70
line 73why, one step back73 let export_manager = ExportManager::from_cli_arguments(&cli_arguments, &options.metrics)?;Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 74–81why, one step back7475 let mut scheduler = Scheduler::new(&commands, &options, &export_manager);76 scheduler.run_benchmarks()?;77 scheduler.final_export()?;7879 Ok(())80}81Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
lines 82–87why, one step back82fn caused_by_broken_console_pipe(error: &anyhow::Error) -> bool {83 error84 .downcast_ref::<ConsoleOutputError>()85 .is_some_and(|e| e.0.kind() == io::ErrorKind::BrokenPipe)86}87Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 88–91why, one step back88fn main() {89 match run() {90 Ok(_) => {}91 Err(e) => {Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
lines 92–98why, one step back92 // Exit quietly when a reader stops consuming console output early.93 if caused_by_broken_console_pipe(&e) {94 std::process::exit(0);95 }96 // The write to stderr can itself fail if stderr is closed; the97 // error message cannot be shown in that case anyway.98 let _ = writeln!(io::stderr(), "{} {:#}", "Error:".red(), e);Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 99–102why, one step back99 std::process::exit(1);100 }101 }102}