main.rs
This file
Path
src/main.rs
72 lines · 1.9 KiB · Rust
Last changed by
Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
History of this fileTake it
1#![cfg_attr(2 all(windows, feature = "windows_process_extensions_main_thread_handle"),3 feature(windows_process_extensions_main_thread_handle)4)]56use std::env;7use std::io::{self, Write};89use benchmark::scheduler::Scheduler;10use cli::get_cli_arguments;11use command::Commands;12use error::ConsoleOutputError;13use export::ExportManager;14use options::Options;1516use anyhow::Result;17use colored::*;1819pub mod benchmark;20pub mod cli;21pub mod command;22pub mod error;23pub mod export;24pub mod metric;25pub mod options;26pub mod outlier_detection;27pub mod output;28pub mod parameter;29pub mod quantity;30pub mod timer;31pub mod util;3233fn run() -> Result<()> {34 // Enabled ANSI colors on Windows 1035 #[cfg(windows)]36 colored::control::set_virtual_terminal(true).unwrap();3738 let cli_arguments = get_cli_arguments(env::args_os());39 let mut options = Options::from_cli_arguments(&cli_arguments)?;40 let commands = Commands::from_cli_arguments(&cli_arguments)?;41 options.validate_against_command_list(&commands)?;4243 let export_manager = ExportManager::from_cli_arguments(&cli_arguments, options.metrics[0])?;4445 let mut scheduler = Scheduler::new(&commands, &options, &export_manager);46 scheduler.run_benchmarks()?;47 scheduler.final_export()?;4849 Ok(())50}5152fn caused_by_broken_console_pipe(error: &anyhow::Error) -> bool {53 error54 .downcast_ref::<ConsoleOutputError>()55 .is_some_and(|e| e.0.kind() == io::ErrorKind::BrokenPipe)56}5758fn main() {59 match run() {60 Ok(_) => {}61 Err(e) => {62 // Exit quietly when a reader stops consuming console output early.63 if caused_by_broken_console_pipe(&e) {64 std::process::exit(0);65 }66 // The write to stderr can itself fail if stderr is closed; the67 // error message cannot be shown in that case anyway.68 let _ = writeln!(io::stderr(), "{} {:#}", "Error:".red(), e);69 std::process::exit(1);70 }71 }72}