-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(bench): Add JSON reporter for "deno bench" subcommand #17595
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ad337d3
#14385 WIP
be96e7e
Merge branch 'denoland:main' into main
cc3a05b
#14385 benchmark json output
92e8ae9
Merge branch 'main' into main
1d7be61
#14385 fix merge conflict mess
f3fccf1
Merge branch 'denoland:main' into main
a06b5e1
Fix tests
e8499b6
make clippy happy
e65cbec
Merge branch 'main' into main
b06c993
Merge branch 'main' into main
cae37e6
Merge branch 'main' into main
905f428
Merge branch 'main' into main
45ab517
Merge branch 'main' into main
f0c90c1
Merge branch 'main' into main
302a979
Merge branch 'main' into main
149b97a
Merge branch 'main' into main
0dae393
Merge branch 'main' into main
c7e9729
fix doc args
622daf0
Merge branch 'main' into main
aapoalas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ use crate::args::BenchOptions; | |
use crate::args::CliOptions; | ||
use crate::args::TypeCheckMode; | ||
use crate::colors; | ||
use crate::display::write_json_to_stdout; | ||
use crate::graph_util::graph_valid_with_cli_options; | ||
use crate::ops; | ||
use crate::proc_state::ProcState; | ||
|
@@ -13,6 +14,7 @@ use crate::util::file_watcher; | |
use crate::util::file_watcher::ResolutionResult; | ||
use crate::util::fs::collect_specifiers; | ||
use crate::util::path::is_supported_ext; | ||
use crate::version::get_user_agent; | ||
use crate::worker::create_main_worker_for_test_or_bench; | ||
|
||
use deno_core::error::generic_error; | ||
|
@@ -41,6 +43,7 @@ use tokio::sync::mpsc::UnboundedSender; | |
#[derive(Debug, Clone)] | ||
struct BenchSpecifierOptions { | ||
filter: TestFilter, | ||
json: bool, | ||
} | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq, Deserialize)] | ||
|
@@ -62,7 +65,7 @@ pub enum BenchEvent { | |
Result(usize, BenchResult), | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize)] | ||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum BenchResult { | ||
Ok(BenchStats), | ||
|
@@ -109,7 +112,13 @@ impl BenchReport { | |
} | ||
} | ||
|
||
fn create_reporter(show_output: bool) -> Box<dyn BenchReporter + Send> { | ||
fn create_reporter( | ||
show_output: bool, | ||
json: bool, | ||
) -> Box<dyn BenchReporter + Send> { | ||
if json { | ||
return Box::new(JsonReporter::new()); | ||
} | ||
Box::new(ConsoleReporter::new(show_output)) | ||
} | ||
|
||
|
@@ -123,6 +132,74 @@ pub trait BenchReporter { | |
fn report_result(&mut self, desc: &BenchDescription, result: &BenchResult); | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
struct JsonReporterResult { | ||
runtime: String, | ||
cpu: String, | ||
origin: String, | ||
group: Option<String>, | ||
name: String, | ||
baseline: bool, | ||
result: BenchResult, | ||
} | ||
|
||
impl JsonReporterResult { | ||
fn new( | ||
origin: String, | ||
group: Option<String>, | ||
name: String, | ||
baseline: bool, | ||
result: BenchResult, | ||
) -> Self { | ||
Self { | ||
runtime: format!("{} {}", get_user_agent(), env!("TARGET")), | ||
cpu: mitata::cpu::name(), | ||
origin, | ||
group, | ||
name, | ||
baseline, | ||
result, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
struct JsonReporter(Vec<JsonReporterResult>); | ||
impl JsonReporter { | ||
fn new() -> Self { | ||
Self(vec![]) | ||
} | ||
} | ||
|
||
impl BenchReporter for JsonReporter { | ||
fn report_group_summary(&mut self) {} | ||
#[cold] | ||
fn report_plan(&mut self, _plan: &BenchPlan) {} | ||
|
||
fn report_end(&mut self, _report: &BenchReport) { | ||
match write_json_to_stdout(self) { | ||
Ok(_) => (), | ||
Err(e) => println!("{e}"), | ||
} | ||
} | ||
|
||
fn report_register(&mut self, _desc: &BenchDescription) {} | ||
|
||
fn report_wait(&mut self, _desc: &BenchDescription) {} | ||
|
||
fn report_output(&mut self, _output: &str) {} | ||
|
||
fn report_result(&mut self, desc: &BenchDescription, result: &BenchResult) { | ||
self.0.push(JsonReporterResult::new( | ||
desc.origin.clone(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doc JSON output uses |
||
desc.group.clone(), | ||
desc.name.clone(), | ||
desc.baseline, | ||
result.clone(), | ||
)); | ||
} | ||
} | ||
|
||
struct ConsoleReporter { | ||
name: String, | ||
show_output: bool, | ||
|
@@ -376,12 +453,14 @@ async fn bench_specifiers( | |
|
||
let (sender, mut receiver) = unbounded_channel::<BenchEvent>(); | ||
|
||
let option_for_handles = options.clone(); | ||
|
||
let join_handles = specifiers.into_iter().map(move |specifier| { | ||
let ps = ps.clone(); | ||
let permissions = permissions.clone(); | ||
let specifier = specifier; | ||
let sender = sender.clone(); | ||
let options = options.clone(); | ||
let options = option_for_handles.clone(); | ||
|
||
tokio::task::spawn_blocking(move || { | ||
let future = bench_specifier(ps, permissions, specifier, sender, options); | ||
|
@@ -398,7 +477,8 @@ async fn bench_specifiers( | |
tokio::task::spawn(async move { | ||
let mut used_only = false; | ||
let mut report = BenchReport::new(); | ||
let mut reporter = create_reporter(log_level != Some(Level::Error)); | ||
let mut reporter = | ||
create_reporter(log_level != Some(Level::Error), options.json); | ||
let mut benches = IndexMap::new(); | ||
|
||
while let Some(event) = receiver.recv().await { | ||
|
@@ -509,6 +589,7 @@ pub async fn run_benchmarks( | |
specifiers, | ||
BenchSpecifierOptions { | ||
filter: TestFilter::from_flag(&bench_options.filter), | ||
json: bench_options.json, | ||
}, | ||
) | ||
.await?; | ||
|
@@ -658,6 +739,7 @@ pub async fn run_benchmarks_with_watch( | |
specifiers, | ||
BenchSpecifierOptions { | ||
filter: TestFilter::from_flag(&bench_options.filter), | ||
json: bench_options.json, | ||
}, | ||
) | ||
.await?; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshedding: I would perhaps split up the formatting a bit; now each result field includes the runtime and CPU information, and groups are only an entry in the result data and not actually groups as the name might suggest.
I might rather go with something like: