Skip to content

Fix empty Totals histogram in --run-count AGGREGATED AVERAGE JSON - #572

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix/json-aggregated-totals-histogram
Oct 13, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix/json-aggregated-totals-histogram

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With --run-count N --json-out-file, the "AGGREGATED AVERAGE RESULTS (N runs)" → "Totals" block reports percentiles from an empty histogram. Count is right, but every percentile is the empty-histogram value and the compressed histogram has no samples. Min Latency/Max Latency are wrong for the same reason. The text table's Totals row in the same section is correct.

On master (--run-count 2 -n 1000 -c 2 -t 2):

table  Totals ... p50 0.04700  p99 0.55100  p99.9 2.41500
JSON   Totals Count 8000  {'p50.00': 0.007, 'p99.00': 0.007, 'p99.90': 0.007}  (empty compressed histogram)

Root cause

The JSON Totals block reads m_totals.latency_histogram. run_stats::aggregate_average() builds m_totals by add()ing the totals that summarize() returns, and those never carry a histogram. The function merges the per-type histograms and m_totals_latency_histogram, but not m_totals.latency_histogram. The table builds its Totals row from the per-type histograms, so it was not affected. #251 fixed the totals histogram in merge() but not in aggregate_average().

Fix

In aggregate_average(), merge each run's m_totals.latency_histogram (the histogram the per-run JSON Totals block uses) next to the per-type histograms. This is a one-line change.

Test

tests/test_hdr_histogram.py::test_aggregated_average_totals_histogram runs --run-count=2 --print-all-runs and decodes the compressed histograms. It checks that the AVERAGE Totals histogram:

  • holds Count samples,
  • equals the merge of the AVERAGE Sets and Gets histograms,
  • equals the merge of the RUN #1 and RUN #2 Totals histograms.

It also checks that the JSON percentiles and Min/Max match exact HDR ranks of that histogram, and that they match the AVERAGE table's Totals row.

Before the fix (origin/master):

FAIL: 0 == 8000                                       (decoded sample count vs Count)
FAIL: ((3, 7), {}) == ((3, 7), {2: 90, 3: 305, ...})  (vs merged Sets+Gets / merged per-run Totals)
FAIL: [0.016, 0.095, 0.447, 3.119] == [0.0, 0.007, 0.007, 0.007]

After the fix, test_hdr_histogram.py passes 3/3, repeated 4 times, and test_cli_validation_run_count.py passes.

Fixes #567

Affected versions: 1.4.0 through 2.5.2 and master. The bug was introduced by fdf704b (#100), which added percentile output.

🤖 Generated with Claude Code


Note

Low Risk
Small, targeted fix to multi-run aggregation output; aligns JSON Totals with existing table behavior and adds regression coverage.

Overview
Fixes AGGREGATED AVERAGE JSON when using --run-count: the "Totals" block had correct Count but wrong percentiles, min/max, and an empty compressed histogram because aggregate_average() never merged each run's m_totals.latency_histogram (the histogram print_json uses for Totals), while per-type histograms were already merged.

run_stats::aggregate_average() now calls hdr_add(m_totals.latency_histogram, i->m_totals.latency_histogram) alongside the existing GET/SET/WAIT merges, with a comment that summarize() leaves the summarized totals histogram empty.

Adds test_aggregated_average_totals_histogram in test_hdr_histogram.py: runs --run-count=2, decodes HDR payloads, and asserts AVERAGE Totals matches merged Sets+Gets and merged per-run Totals, and that JSON percentiles/min/max and the text table Totals row agree.

Reviewed by Cursor Bugbot for commit 480d404. Bugbot is set up for automated code reviews on this repo. Configure here.

With --run-count N, the JSON "AGGREGATED AVERAGE RESULTS" Totals block
prints its percentiles, Min/Max Latency and compressed histogram from
m_totals.latency_histogram. aggregate_average() builds m_totals from the
totals that summarize() returns, which never carry a histogram, so that
histogram stayed empty: Count was right but every percentile was the
empty-histogram value (0.007) and the encoded histogram had no samples.
The text table was correct because it builds its Totals row from the
per-type histograms.

Merge each run's m_totals.latency_histogram, the same histogram the
per-run JSON Totals block uses, alongside the per-type histograms.

Fixes #567

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit ffda218 into master Oct 13, 2026
121 checks passed
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.

--run-count JSON: AGGREGATED AVERAGE Totals percentiles come from an empty histogram

1 participant