Skip to content

Commit

Permalink
Merge pull request #1963 from s7tya/improve-compare-cmd-ui
Browse files Browse the repository at this point in the history
Improve compare cmd UI
  • Loading branch information
Kobzol committed Aug 14, 2024
2 parents d619e6c + 9325e6d commit aa77f26
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 13 deletions.
111 changes: 107 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions collector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tabled = { version = "0.14.0", features = ["ansi-str"] }
humansize = "2.1.3"
regex = "1.7.1"
analyzeme = "12.0.0"
inquire = "0.7.5"

benchlib = { path = "benchlib" }

Expand Down
17 changes: 13 additions & 4 deletions collector/src/bin/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,15 @@ enum Commands {
#[command(flatten)]
db: DbOption,

/// Metric used to compare artifacts.
#[arg(long)]
metric: Option<database::metric::Metric>,

/// The name of the base artifact to be compared.
base: String,
base: Option<String>,

/// The name of the modified artifact to be compared.
modified: String,
modified: Option<String>,
},
}

Expand Down Expand Up @@ -1200,11 +1204,16 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
println!("Data of artifact {name} were removed");
Ok(0)
}
Commands::BenchCmp { db, base, modified } => {
Commands::BenchCmp {
db,
base,
modified,
metric,
} => {
let pool = Pool::open(&db.db);
let rt = build_async_runtime();
let conn = rt.block_on(pool.connection());
rt.block_on(compare_artifacts(conn, base, modified))?;
rt.block_on(compare_artifacts(conn, metric, base, modified))?;
Ok(0)
}
}
Expand Down
89 changes: 84 additions & 5 deletions collector/src/compare.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{str::FromStr, sync::Arc};

use database::{
metric::Metric,
Expand All @@ -7,16 +7,95 @@ use database::{
};
use tabled::{Table, Tabled};

static ALL_METRICS: &[Metric] = &[
Metric::InstructionsUser,
Metric::Cycles,
Metric::WallTime,
Metric::MaxRSS,
Metric::LinkedArtifactSize,
Metric::AssemblyFileSize,
Metric::BranchMisses,
Metric::CacheMisses,
Metric::CodegenUnitLlvmIrCount,
Metric::CodegenUnitSize,
Metric::ContextSwitches,
Metric::CpuClock,
Metric::CpuClockUser,
Metric::CrateMetadataSize,
Metric::CyclesUser,
Metric::DepGraphSize,
Metric::DocByteSize,
Metric::DwoFileSize,
Metric::Faults,
Metric::FaultsUser,
Metric::LlvmBitcodeSize,
Metric::LlvmIrSize,
Metric::ObjectFileSize,
Metric::QueryCacheSize,
Metric::TaskClock,
Metric::TaskClockUser,
Metric::WorkProductIndexSize,
];

/// Compare 2 artifacts and print the result.
pub async fn compare_artifacts(
mut conn: Box<dyn Connection>,
base: String,
modified: String,
metric: Option<Metric>,
base: Option<String>,
modified: Option<String>,
) -> anyhow::Result<()> {
let index = database::Index::load(&mut *conn).await;

let query = CompileBenchmarkQuery::default()
.metric(database::selector::Selector::One(Metric::InstructionsUser));
let metric = match metric {
Some(v) => v,
None => {
let metric_str = inquire::Select::new(
"Choose metric:",
ALL_METRICS.iter().map(|m| m.as_str()).collect::<Vec<_>>(),
)
.prompt()?;
Metric::from_str(metric_str).map_err(|e| anyhow::anyhow!(e))?
}
};

let mut aids = index.artifacts().map(str::to_string).collect::<Vec<_>>();
if aids.len() < 2 {
return Err(anyhow::anyhow!(
"There are not enough artifacts to compare, at least two are needed"
));
}

let select_artifact_id = |name: &str, aids: &Vec<String>| {
anyhow::Ok(
inquire::Select::new(
&format!("Choose {} artifact to compare:", name),
aids.clone(),
)
.prompt()?,
)
};

let base = match base {
Some(v) => v,
None => select_artifact_id("base", &aids)?.to_string(),
};
aids.retain(|id| id != &base);
let modified = if aids.len() == 1 {
let new_modified = aids[0].clone();
println!(
"Only 1 artifact remains, automatically selecting: {}",
new_modified
);

new_modified
} else {
match modified {
Some(v) => v,
None => select_artifact_id("modified", &aids)?.to_string(),
}
};

let query = CompileBenchmarkQuery::default().metric(database::selector::Selector::One(metric));
let resp = query
.execute(
&mut *conn,
Expand Down

0 comments on commit aa77f26

Please sign in to comment.