Skip to content

Commit

Permalink
Add sub-adapters to comment ID
Browse files Browse the repository at this point in the history
  • Loading branch information
epompeii committed Jan 27, 2025
1 parent 3801c5f commit 1c6ea0d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
28 changes: 25 additions & 3 deletions lib/bencher_comment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,22 @@ pub struct ReportComment {
benchmark_count: usize,
missing_threshold: HashSet<Measure>,
json_report: JsonReport,
sub_adapter: SubAdapter,
source: String,
}

pub struct SubAdapter {
pub build_time: bool,
pub file_size: bool,
}

impl ReportComment {
pub fn new(console_url: Url, json_report: JsonReport, source: String) -> Self {
pub fn new(
console_url: Url,
json_report: JsonReport,
sub_adapter: SubAdapter,
source: String,
) -> Self {
Self {
console_url,
project_slug: json_report.project.slug.clone(),
Expand All @@ -43,6 +54,7 @@ impl ReportComment {
benchmark_count: json_report.results.iter().map(Vec::len).sum(),
missing_threshold: Measure::missing_threshold(&json_report),
json_report,
sub_adapter,
source,
}
}
Expand Down Expand Up @@ -543,10 +555,20 @@ impl ReportComment {
let id = id.map_or_else(
|| {
format!(
"{branch}/{testbed}/{adapter}",
"{branch}/{testbed}/{adapter}{build_time}{file_size}",
branch = self.json_report.branch.slug,
testbed = self.json_report.testbed.slug,
adapter = self.json_report.adapter
adapter = self.json_report.adapter,
build_time = if self.sub_adapter.build_time {
"-build_time"
} else {
""
},
file_size = if self.sub_adapter.file_size {
"-file_size"
} else {
""
},
)
},
ToString::to_string,
Expand Down
17 changes: 10 additions & 7 deletions services/cli/src/bencher/sub/project/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ mod error;
mod fold;
mod format;
pub mod runner;
mod sub_adapter;
pub mod thresholds;

use branch::Branch;
use ci::Ci;
pub use error::RunError;
use format::Format;
use runner::Runner;
use sub_adapter::SubAdapter;
use thresholds::Thresholds;

use crate::bencher::SubCmd;
Expand All @@ -37,6 +39,7 @@ pub struct Run {
branch: Branch,
testbed: NameId,
adapter: Adapter,
sub_adapter: SubAdapter,
average: Option<JsonAverage>,
iter: usize,
fold: Option<JsonFold>,
Expand Down Expand Up @@ -80,6 +83,7 @@ impl TryFrom<CliRun> for Run {
branch: branch.try_into().map_err(RunError::Branch)?,
testbed,
adapter: adapter.into(),
sub_adapter: (&cmd).into(),
average: average.map(Into::into),
iter,
fold: fold.map(Into::into),
Expand Down Expand Up @@ -206,13 +210,12 @@ impl Run {
.get_console_url()
.await
.map_err(RunError::ConsoleUrl)?;
let report_comment = ReportComment::new(
console_url,
json_report,
self.ci
.as_ref()
.map_or_else(|| "cli".to_owned(), Ci::source),
);
let source = self
.ci
.as_ref()
.map_or_else(|| "cli".to_owned(), Ci::source);
let report_comment =
ReportComment::new(console_url, json_report, self.sub_adapter.into(), source);

let report_str = match self.format {
Format::Human => report_comment.human(),
Expand Down
32 changes: 32 additions & 0 deletions services/cli/src/bencher/sub/project/run/sub_adapter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::parser::project::run::CliRunCommand;

#[derive(Debug, Clone, Copy)]
pub struct SubAdapter {
build_time: bool,
file_size: bool,
}

impl From<&CliRunCommand> for SubAdapter {
fn from(cmd: &CliRunCommand) -> Self {
Self {
build_time: cmd.build_time,
file_size: cmd
.file_size
.as_ref()
.is_some_and(|paths| !paths.is_empty()),
}
}
}

impl From<SubAdapter> for bencher_comment::SubAdapter {
fn from(sub_adapter: SubAdapter) -> Self {
let SubAdapter {
build_time,
file_size,
} = sub_adapter;
Self {
build_time,
file_size,
}
}
}

0 comments on commit 1c6ea0d

Please sign in to comment.