mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
feat(bench): change --json output format (#17888)
Closes https://github.com/denoland/deno/issues/17775
This commit is contained in:
parent
b15f9e60a0
commit
d5f053dabf
3 changed files with 69 additions and 28 deletions
|
@ -178,6 +178,12 @@ itest!(bench_with_malformed_config {
|
|||
output: "bench/collect_with_malformed_config.out",
|
||||
});
|
||||
|
||||
itest!(json_output {
|
||||
args: "bench --json bench/pass.ts",
|
||||
exit_code: 0,
|
||||
output: "bench/pass.json.out",
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn recursive_permissions_pledge() {
|
||||
let output = util::deno_cmd()
|
||||
|
|
28
cli/tests/testdata/bench/pass.json.out
vendored
Normal file
28
cli/tests/testdata/bench/pass.json.out
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
Check file:///[WILDCARD]testdata/bench/pass.ts
|
||||
{
|
||||
"runtime": "Deno/[WILDCARD]",
|
||||
"cpu": "[WILDCARD]",
|
||||
"benches": [
|
||||
{
|
||||
"origin": "file:///[WILDCARD]testdata/bench/pass.ts",
|
||||
"group": null,
|
||||
"name": "bench0",
|
||||
"baseline": false,
|
||||
"results": [
|
||||
{
|
||||
"ok": {
|
||||
"n": [WILDCARD],
|
||||
"min": [WILDCARD],
|
||||
"max": [WILDCARD],
|
||||
"avg": [WILDCARD],
|
||||
"p75": [WILDCARD],
|
||||
"p99": [WILDCARD],
|
||||
"p995": [WILDCARD],
|
||||
"p999": [WILDCARD]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
[WILDCARD]
|
||||
]
|
||||
}
|
|
@ -133,41 +133,37 @@ pub trait BenchReporter {
|
|||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct JsonReporterResult {
|
||||
struct JsonReporterOutput {
|
||||
runtime: String,
|
||||
cpu: String,
|
||||
origin: String,
|
||||
group: Option<String>,
|
||||
name: String,
|
||||
baseline: bool,
|
||||
result: BenchResult,
|
||||
benches: Vec<JsonReporterBench>,
|
||||
}
|
||||
|
||||
impl JsonReporterResult {
|
||||
fn new(
|
||||
origin: String,
|
||||
group: Option<String>,
|
||||
name: String,
|
||||
baseline: bool,
|
||||
result: BenchResult,
|
||||
) -> Self {
|
||||
impl Default for JsonReporterOutput {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
runtime: format!("{} {}", get_user_agent(), env!("TARGET")),
|
||||
cpu: mitata::cpu::name(),
|
||||
origin,
|
||||
group,
|
||||
name,
|
||||
baseline,
|
||||
result,
|
||||
benches: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct JsonReporter(Vec<JsonReporterResult>);
|
||||
struct JsonReporterBench {
|
||||
origin: String,
|
||||
group: Option<String>,
|
||||
name: String,
|
||||
baseline: bool,
|
||||
results: Vec<BenchResult>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct JsonReporter(JsonReporterOutput);
|
||||
|
||||
impl JsonReporter {
|
||||
fn new() -> Self {
|
||||
Self(vec![])
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,13 +186,24 @@ impl BenchReporter for JsonReporter {
|
|||
fn report_output(&mut self, _output: &str) {}
|
||||
|
||||
fn report_result(&mut self, desc: &BenchDescription, result: &BenchResult) {
|
||||
self.0.push(JsonReporterResult::new(
|
||||
desc.origin.clone(),
|
||||
desc.group.clone(),
|
||||
desc.name.clone(),
|
||||
desc.baseline,
|
||||
result.clone(),
|
||||
));
|
||||
let maybe_bench = self.0.benches.iter_mut().find(|bench| {
|
||||
bench.origin == desc.origin
|
||||
&& bench.group == desc.group
|
||||
&& bench.name == desc.name
|
||||
&& bench.baseline == desc.baseline
|
||||
});
|
||||
|
||||
if let Some(bench) = maybe_bench {
|
||||
bench.results.push(result.clone());
|
||||
} else {
|
||||
self.0.benches.push(JsonReporterBench {
|
||||
origin: desc.origin.clone(),
|
||||
group: desc.group.clone(),
|
||||
name: desc.name.clone(),
|
||||
baseline: desc.baseline,
|
||||
results: vec![result.clone()],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue