Skip to content

Latest commit

 

History

History
313 lines (283 loc) · 13.5 KB

json.md

File metadata and controls

313 lines (283 loc) · 13.5 KB

Read Duel's report as JSON

To read Duel's results from a program, such as a dashboard, a bot, or a script that tracks benchmarks over time, write its report as JSON with --json:

duel --json tmp/duel.json

The JSON report has the same results as the Markdown report, and more of each: every timing's ratio, interval and verdict, each version's medians an iteration, and every count. A relative path is relative to where duel runs, and Duel makes the file's directory if it needs to. Each run replaces the file.

Duel writes the report whatever the outcome: a comparison that passed or failed, nothing to compare, or a comparison that couldn't run. It writes nothing when the command line isn't valid, such as an unknown option, and nothing for duel clean, --version, or duel init, which aren't comparisons. So a missing report means that duel didn't get as far as comparing, or crashed.

Versions of the schema

The report's schema key is the version of its schema, now 2. A new key can appear in any release without a new version, so ignore the keys that you don't know. Any other change, such as a key removed or renamed, or a value that means something else, comes with a new version. Check schema before you read the rest, and stop if it isn't one that you know.

The report uses only plain JSON types: objects, arrays, strings, numbers, true, false, and null. Numbers are numbers, never strings. A key that doesn't apply, such as a skipped benchmark's iterations, is null, not missing, so every object of a kind has the same keys.

An example

A run that found one regression, abridged to two benchmarks:

{
  "schema": 2,
  "duel_version": "0.3.1",
  "status": "failed",
  "exit": 1,
  "passed_anyway": null,
  "message": null,
  "settings": {
    "confidence": 0.99,
    "limit": 1.02,
    "filter": "",
    "jobs": 4,
    "processes": 8,
    "timeout": 60.0,
    "warm": null,
    "force": false
  },
  "seconds": 14.2,
  "baseline": {
    "ref": "origin/main",
    "commit": "3f9c2a1d5e8b7c6a4f3e2d1c0b9a8f7e6d5c4b3a",
    "root": "/home/runner/work/my_parser/.3f9c2a1b",
    "ruby": "ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]"
  },
  "candidate": {
    "commit": "8e4d0b7f1a2c3e4d5b6a7f8e9d0c1b2a3f4e5d6c",
    "uncommitted_changes": false,
    "root": "/home/runner/work/my_parser/my_parser",
    "ruby": "ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]"
  },
  "plugins": [],
  "benchmarks": [
    {
      "name": "parse: a large document",
      "verdict": "regressed",
      "passed": false,
      "regressed": ["instructions", "cpu", "allocations"],
      "iterations": 9,
      "seconds": 3.1,
      "confirmations": 3,
      "timed": {
        "instructions": {
          "ratio": 1.071,
          "interval": [1.069, 1.073],
          "limit": 1.01,
          "pairs": 16,
          "processes": 8,
          "verdict": "slower",
          "baseline": 1521000.0,
          "candidate": 1629000.0,
          "unit": null,
          "plural": null,
          "across": true
        },
        "cpu": {
          "ratio": 1.081,
          "interval": [1.062, 1.097],
          "limit": 1.02,
          "pairs": 16,
          "processes": 8,
          "verdict": "slower",
          "baseline": 112400.0,
          "candidate": 121500.0,
          "unit": "ns",
          "plural": "ns",
          "across": true
        }
      },
      "counted": {
        "allocations": {
          "baseline": 5790.0,
          "candidate": 5791.0,
          "unit": null,
          "plural": null,
          "verdict": "more"
        }
      },
      "peak_memory": null,
      "details": {},
      "explanation": [
        "instructions: 1.521e+06 → 1.629e+06 an iteration (1.07x)",
        "cpu: 112.4µs → 121.5µs an iteration (1.08x)",
        "allocations: 5790 → 5791 an iteration",
        "where the extra CPU went (as a share of the baseline's: in each frame itself, and with what it called):",
        "   +6.8%   +7.1%  MyParser::Lexer#next_token"
      ],
      "error": null,
      "skipped": null
    },
    {
      "name": "parse: an empty document",
      "verdict": "same",
      "passed": true,
      "regressed": [],
      "iterations": 2400,
      "seconds": 0.8,
      "confirmations": 0,
      "timed": {
        "cpu": {
          "ratio": 1.002,
          "interval": [0.994, 1.009],
          "limit": 1.02,
          "pairs": 16,
          "processes": 8,
          "verdict": "same",
          "baseline": 410.5,
          "candidate": 411.2,
          "unit": "ns",
          "plural": "ns",
          "across": true
        }
      },
      "counted": {
        "allocations": {
          "baseline": 3.0,
          "candidate": 3.0,
          "unit": null,
          "plural": null,
          "verdict": "same"
        }
      },
      "peak_memory": null,
      "details": {},
      "explanation": [],
      "error": null,
      "skipped": null
    }
  ],
  "across": {
    "cpu": {
      "ratio": 1.004,
      "interval": [0.998, 1.012],
      "limit": 1.005,
      "benchmarks": 12,
      "processes": 8,
      "verdict": "unsettled",
      "confirmed": false
    }
  },
  "cut_short": null
}

A run with nothing to compare has the same keys, with nothing compared:

{
  "schema": 2,
  "duel_version": "0.3.1",
  "status": "nothing_to_compare",
  "exit": 0,
  "passed_anyway": null,
  "message": "duel: lib, ext, duel, .duel.rb unchanged since the baseline, so there's nothing to compare (--force to anyway)",
  "settings": {"confidence": 0.99, "limit": 1.02, "filter": "", "jobs": 4, "processes": 8, "timeout": 60.0, "warm": null, "force": false},
  "seconds": null,
  "baseline": null,
  "candidate": null,
  "plugins": [],
  "benchmarks": [],
  "across": {},
  "cut_short": null
}

For example, to list the benchmarks that regressed, with jq:

jq -r '.benchmarks[] | select(.verdict == "regressed") | .name' tmp/duel.json

The report

Key What it is
schema The schema's version: 2.
duel_version The version of Duel that wrote the report.
status What the comparison found: "passed", "failed", "nothing_to_compare", or "error" (Duel couldn't compare).
exit The exit status of duel: 0 for passed, nothing to compare, or failed but passed anyway (see passed_anyway), 1 for failed, 2 for an error, and 3 for failed but only warned (on GitLab CI, where only a merge request fails).
passed_anyway Why a run that failed passed anyway: "accept_label", where the pull request's label accepted the regression (see c.accept_label), or "fail_on", where only a pull request fails (see c.fail_on). Otherwise null.
message What Duel said, for nothing to compare or an error, such as "duel: no release tag (v*) before HEAD to compare against". Otherwise null.
settings The settings that the run used (see below).
seconds How long the comparison took. null without a comparison.
baseline, candidate The two versions (see below). null without a comparison.
plugins The names of the plugins in use, such as ["rails", "activerecord"].
benchmarks Every benchmark compared, in the order Duel found them (see below).
across The verdicts across the board, by metric (see below).
cut_short What the run left undone when it reached its time limit (--time-limit): {"unmeasured": [names], "unconfirmed": [names], "across": true or false}. unmeasured are the benchmarks that it didn't measure, which are errors. unconfirmed are those that it judged without measuring them again as often as it usually does, and across is whether it judged across the board without measuring every benchmark again. null for a run that finished within its limit.

A run fails when a benchmark regressed, a benchmark failed, or a metric was slower across the board and confirmed ("confirmed": true).

Settings

Key What it is
confidence The confidence of each interval, such as 0.99.
limit The ratio above which a timing is slower (--limit). A metric can have its own limit, which its timings show.
filter The regular expression that picked the benchmarks (--filter), as source. "" matches every one.
jobs Benchmarks measured at once (--jobs), or fewer, where that many wouldn't fit in the memory available.
processes Worker processes for each version (--processes), or fewer, where even one benchmark's wouldn't fit in the memory available.
timeout The seconds that a worker may take to load or to answer (--timeout).
time_limit The seconds that a run measures for, at most (--time-limit).
warm The seconds of warm-up for each benchmark (--warm), or null for the default: until steady, for up to as long as the Ruby takes.
force Whether --force was given.

The versions

Key What it is
ref The baseline's git ref: the one --base named, the release tag for --base last-release, or the main branch, such as "origin/main", by default, where the baseline is the commit where HEAD left that branch. null for a baseline directory.
commit The full hash of the commit compared. null for a baseline directory, or for a candidate outside a git repository.
uncommitted_changes The candidate only: whether what Duel watches (c.watch, the benchmarks, and the rest that a change must touch to be compared: see Configure Duel) has changes that aren't committed. null outside a git repository.
root The tree that was compared, as an absolute path.
ruby The version's Ruby, as its RUBY_DESCRIPTION.

Benchmarks

Key What it is
name The benchmark's name.
verdict "regressed", "error", "unsettled" (a timing too close to its limit to settle), "faster", "changed" (a count changed), "skipped", or "same", as in the Markdown report's table.
passed Whether it regressed on nothing and didn't fail.
regressed The metrics that it regressed on, in every measurement, such as ["cpu", "allocations"]. Peak memory is "peak_memory".
iterations The iterations in each sample. null for a benchmark that failed or was skipped.
seconds How long its first measurement took. null for a benchmark that failed or was skipped.
confirmations How many times it was measured again, from scratch, because it looked worse.
timed Its timings, by metric (see below).
counted Its counts, by metric (see below).
peak_memory Each version's peak memory, as {"baseline": bytes, "candidate": bytes, "unit": "B", "verdict": "more" or "same"}, for a benchmark that measures it: "more" by more than Duel tolerates. Otherwise null.
details What metrics said of the last samples, by metric and then by version, such as {"allocations": {"baseline": "2 String", "candidate": "3 String"}}.
explanation For a regression, the lines that explain it, as the terminal report and the Markdown report show them. Otherwise [].
error Why it failed, with any backtrace. Otherwise null.
skipped Why it was skipped, such as a benchmark that isn't on the baseline. Otherwise null.

Each timing in timed, such as cpu:

Key What it is
ratio The candidate's ratio to the baseline: the median of every candidate worker's median over every baseline worker's, or with processes null, the median of the paired ratios. Above 1 is the candidate slower.
interval The confidence interval for that ratio, as [low, high].
limit The ratio above which it's slower.
pairs The pairs of samples measured.
processes The worker processes of each version that the interval is over, or null where it's over the pairs: for a process benchmark, or with fewer workers than the interval takes (see How it works).
verdict "slower", "faster", "same", or "unsettled" (too close to the limit to settle).
baseline, candidate Each version's median for one iteration, in unit.
unit, plural The metric's unit, singular and plural, such as "ns", or null for a plain number.
across Whether it counts across the board.

Each count in counted, such as allocations:

Key What it is
baseline, candidate Each version's fewest for one iteration, in unit.
unit, plural The metric's unit, singular and plural, such as "query" and "queries", or null for a plain number.
verdict "more" (worse: more than the metric tolerates), "fewer", or "same" (or more, within what the metric tolerates).

Across the board

Each metric in across, such as cpu:

Key What it is
ratio The median of every benchmark's ratio, or where they were judged by process, the ratio of the candidate's workers to the baseline's over every benchmark.
interval The confidence interval for that ratio, as [low, high], or null with too few benchmarks to tell.
limit The ratio above which it's slower across the board.
benchmarks The benchmarks that it's from.
processes The worker processes of each version that the interval is over, or null where it's over the benchmarks.
verdict "slower", "faster", "same", or "unsettled".
confirmed Whether it was slower again when every benchmark was measured a second time, which fails the run.