evobench_tools/run/sub_command/
list_all.rs1use std::{borrow::Cow, io::stdout, time::SystemTime};
2
3use anyhow::Result;
4
5use crate::output_table::terminal::{TerminalTable, TerminalTableOpts};
6use crate::output_table::{CellValue, OutputTable, OutputTableTitle};
7use crate::run::config::ShareableConfig;
8use crate::{
9 run::{
10 config::BenchmarkingCommand,
11 insert_jobs::open_already_inserted,
12 key::{BenchmarkingJobParameters, RunParameters},
13 sub_command::list::TARGET_NAME_WIDTH,
14 },
15 serde_types::date_and_time::system_time_to_rfc3339,
16};
17
18#[derive(Debug, Clone, clap::Args)]
19pub struct ListAllOpts {
20 #[clap(flatten)]
21 terminal_table_opts: TerminalTableOpts,
22}
23
24impl ListAllOpts {
25 pub fn run(self, shareable_config: &ShareableConfig) -> Result<()> {
26 let Self {
27 terminal_table_opts,
28 } = self;
29
30 let already_inserted = open_already_inserted(&shareable_config.global_app_state_dir)?;
31
32 let mut flat_jobs: Vec<(BenchmarkingJobParameters, SystemTime)> = Vec::new();
33 for job in already_inserted
34 .keys(false, None)?
35 .map(|hash| -> Result<_> {
36 let hash = hash?;
37 Ok(already_inserted.get(&hash)?)
38 })
39 .filter_map(|r| r.transpose())
40 {
41 let (params, insertion_times) = job?;
42 for t in insertion_times {
43 flat_jobs.push((params.clone(), t));
44 }
45 }
46 flat_jobs.sort_by_key(|v| v.1);
47 let mut table = TerminalTable::new(
48 &[38, 43, TARGET_NAME_WIDTH],
49 terminal_table_opts,
50 stdout().lock(),
51 );
52 table.write_title_row(
53 &[
54 OutputTableTitle {
55 text: Cow::Borrowed("Insertion time"),
56 span: 1,
57 anchor_name: None,
58 },
59 OutputTableTitle {
60 text: Cow::Borrowed("Commit id"),
61 span: 1,
62 anchor_name: None,
63 },
64 OutputTableTitle {
65 text: Cow::Borrowed("Target name"),
66 span: 1,
67 anchor_name: None,
68 },
69 OutputTableTitle {
70 text: Cow::Borrowed("Custom parameters"),
71 span: 1,
72 anchor_name: None,
73 },
74 ],
75 None,
76 )?;
77 for (params, insertion_time) in flat_jobs {
78 let t = system_time_to_rfc3339(insertion_time, None);
79 let BenchmarkingJobParameters {
80 run_parameters,
81 command,
82 } = params;
83 let RunParameters {
84 commit_id,
85 custom_parameters,
86 } = &*run_parameters;
87 let BenchmarkingCommand {
88 target_name,
89 subdir: _,
90 command: _,
91 arguments: _,
92 pre_exec_bash_code: _,
93 } = &*command;
94
95 let values: &[&dyn CellValue] = &[
96 &t,
97 &commit_id.to_string(),
98 &target_name.as_str(),
99 &custom_parameters.to_string(),
100 ];
101 table.write_data_row(values, None)?;
102 }
103 drop(table.finish()?);
104 Ok(())
105 }
106}