Skip to content
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 19 commits into from
Feb 12, 2023
Merged

feat(bench): Add JSON reporter for "deno bench" subcommand #17595

merged 19 commits into from
Feb 12, 2023

Conversation

Lurk
Copy link
Contributor

@Lurk Lurk commented Jan 30, 2023

Initial discussion in #14385

In this pull request:

New --json flag to bench subcommand.

time unit: nanoseconds.

Output format example:

[
  {
    "runtime": "Deno/1.28.3 x86_64-apple-darwin",
    "cpu": "Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz",
    "origin": "file:///Users/serhiy.barhamon/tmp/deno/test_ffi/tests/bench.js",
    "group": null,
    "name": "Deno.UnsafePointerView#getUint32",
    "baseline": false,
    "result": {
      "ok": {
        "n": 49,
        "min": 1251.9348,
        "max": 1441.2696,
        "avg": 1308.7523755102038,
        "p75": 1324.1055,
        "p99": 1441.2696,
        "p995": 1441.2696,
        "p999": 1441.2696
      }
    }
  },
  {
    "runtime": "Deno/1.28.3 x86_64-apple-darwin",
    "cpu": "Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz",
    "origin": "file:///Users/serhiy.barhamon/tmp/deno/test_ffi/tests/bench.js",
    "group": null,
    "name": "nop()",
    "baseline": false,
    "result": {
      "failed": {
        "name": "Error",
        "message": "test",
        "stack": "Error: test\n    at file:///Users/serhiy.barhamon/tmp/deno/test_ffi/tests/bench.js:241:11/n    at benchMeasure (deno:cli/js/40_testing.js:898:9)\n    at runBench (deno:cli/js/40_testing.js:1009:27)\n    at runBenchmarks (deno:cli/js/40_testing.js:1146:33)",
        "cause": null,
        "exceptionMessage": "Uncaught Error: test",
        "frames": [
          {
            "typeName": null,
            "functionName": null,
            "methodName": null,
            "fileName": "file:///Users/serhiy.barhamon/tmp/deno/test_ffi/tests/bench.js",
            "lineNumber": 241,
            "columnNumber": 11,
            "evalOrigin": null,
            "isToplevel": true,
            "isEval": false,
            "isNative": false,
            "isConstructor": false,
            "isAsync": false,
            "isPromiseAll": false,
            "promiseIndex": null
          },
          {
            "typeName": null,
            "functionName": "benchMeasure",
            "methodName": null,
            "fileName": "deno:cli/js/40_testing.js",
            "lineNumber": 898,
            "columnNumber": 9,
            "evalOrigin": null,
            "isToplevel": true,
            "isEval": false,
            "isNative": false,
            "isConstructor": false,
            "isAsync": false,
            "isPromiseAll": false,
            "promiseIndex": null
          },
          {
            "typeName": null,
            "functionName": "runBench",
            "methodName": null,
            "fileName": "deno:cli/js/40_testing.js",
            "lineNumber": 1009,
            "columnNumber": 27,
            "evalOrigin": null,
            "isToplevel": true,
            "isEval": false,
            "isNative": false,
            "isConstructor": false,
            "isAsync": false,
            "isPromiseAll": false,
            "promiseIndex": null
          },
          {
            "typeName": null,
            "functionName": "runBenchmarks",
            "methodName": null,
            "fileName": "deno:cli/js/40_testing.js",
            "lineNumber": 1146,
            "columnNumber": 33,
            "evalOrigin": null,
            "isToplevel": true,
            "isEval": false,
            "isNative": false,
            "isConstructor": false,
            "isAsync": false,
            "isPromiseAll": false,
            "promiseIndex": null
          }
        ],
        "sourceLine": "    throw new Error(\"test\");",
        "sourceLineFrameIndex": 0,
        "aggregated": null
      }
    }
]

Serhiy Barhamon added 3 commits December 14, 2022 20:52
Added the `json` flag, copypasted ConsoleReporter to JsonReporter and shuffled code arround
output format:
```
[
  {
    "runtime": "Deno/1.28.3 x86_64-apple-darwin",
    "cpu": "Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz",
    "origin": "file:///Users/serhiy.barhamon/tmp/deno/test_ffi/tests/bench.js",
    "group": null,
    "name": "Deno.UnsafePointerView#getUint32",
    "baseline": false,
    "result": {
      "ok": {
        "n": 49,
        "min": 1251.9348,
        "max": 1441.2696,
        "avg": 1308.7523755102038,
        "p75": 1324.1055,
        "p99": 1441.2696,
        "p995": 1441.2696,
        "p999": 1441.2696
      }
    }
  }
]
```
time unit: nanoseconds
@CLAassistant
Copy link

CLAassistant commented Jan 30, 2023

CLA assistant check
All committers have signed the CLA.

@Lurk Lurk changed the title feat(bench): Add JSON reporter for "deno bench" subcommand [WIP] feat(bench): Add JSON reporter for "deno bench" subcommand Jan 30, 2023
@Lurk Lurk changed the title [WIP] feat(bench): Add JSON reporter for "deno bench" subcommand feat(bench): Add JSON reporter for "deno bench" subcommand Jan 31, 2023
@Lurk
Copy link
Contributor Author

Lurk commented Jan 31, 2023

I think I am done.
I don't like how the failed result looks, but I also do not have any better Idea.

@bartlomieju bartlomieju added this to the 1.31 milestone Feb 2, 2023
Copy link
Collaborator

@aapoalas aapoalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the output format, LGTM. Core team should probably chime in on if the output format should be a flat list like it is now, or a structured object that aligns a bit more with the semantics of the bench command.

@@ -123,6 +132,74 @@ pub trait BenchReporter {
fn report_result(&mut self, desc: &BenchDescription, result: &BenchResult);
}

#[derive(Debug, Serialize)]
struct JsonReporterResult {
Copy link
Collaborator

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:

{
  "runtime": "...",
  "cpu": "...",
  "groups": [
    {
      "name": null,
      "results": [
        {
          "name": "nop()",
          "origin": "file.js",
          "baseline": false,
          "result": { "ok": { } }
        }
      ]
    }
  ]
}


fn report_result(&mut self, desc: &BenchDescription, result: &BenchResult) {
self.0.push(JsonReporterResult::new(
desc.origin.clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc JSON output uses location.filename (together with location.line and location.col, and the error stack uses fileName. Maybe align with either or?

@Lurk
Copy link
Contributor Author

Lurk commented Feb 11, 2023

@aapoalas On the output format.
I choose a flat structure because IMO that will be a usual way to consume results:

  • Run bench on CI
  • Save results to the Elastic/Prometheus/etc
  • Query that data to build charts/send alerts/etc

A flat structure is much better in use cases like that.

But I am ready to change it if my assumptions are wrong.

.arg(
Arg::new("json")
.long("json")
.help("Output benchmark result in JSON format")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add UNSTABLE: to the help string for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -751,6 +758,10 @@ and report results to standard output:

deno bench src/fetch_bench.ts src/signal_bench.ts

Output benchmark result in JSON format:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really needed I think, the --help will print out the individual args either way so this will just be redundant information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@aapoalas
Copy link
Collaborator

@aapoalas On the output format. I choose a flat structure because IMO that will be a usual way to consume results:

  • Run bench on CI
  • Save results to the Elastic/Prometheus/etc
  • Query that data to build charts/send alerts/etc

A flat structure is much better in use cases like that.

But I am ready to change it if my assumptions are wrong.

Sounds like a good enough reason to go with your choice format. I kind of would expect the workflow to go otherwise the same but with some processing step between running and saving to a database, where massaging would be done and at that point it might be useful to have the data already eg. grouped up so the massaging wouldn't need to start with a "divide into groups" step.

@aapoalas aapoalas enabled auto-merge (squash) February 12, 2023 17:16
Copy link
Collaborator

@aapoalas aapoalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We can iterate on the exact format down the line.

@aapoalas aapoalas merged commit fc843d0 into denoland:main Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants