Skip to content

Have the profiler report computed values and warnings in the json too - #9392

Open
abadams wants to merge 6 commits into
abadams/profiler_report_isattyfrom
abadams/profiler_json_output
Open

Have the profiler report computed values and warnings in the json too#9392
abadams wants to merge 6 commits into
abadams/profiler_report_isattyfrom
abadams/profiler_json_output

Conversation

@abadams

@abadams abadams commented Aug 25, 2026

Copy link
Copy Markdown
Member

Agents would rather ingest json than pretty-printed tables. This PR changes the profiler backend to put everything in the json output - not just the raw counters. This mostly means the warnings and the cumulative stats. This PR also makes it clearer in HalideRuntime.h what the denominator is for each counter. Most are summed across runs.

abadams and others added 6 commits August 25, 2026 12:42
The JSON output (HL_PROFILER_JSON_OUTPUT) now includes, per pipeline, a
"warnings" array holding the full text of each performance warning that
fired, and, per Func, the recompute ratio shown in the report's recompute
column. The warning text is the same plain-English message the report
prints, so consumers (LLMs especially) don't have to parse the table. It's
collected into a small growable string per pipeline while the text report
renders it, then emitted in the JSON pass.

Also document, in HalideRuntime.h, how each profiler struct field
aggregates across runs: peaks are maxima, time is summed over billed_runs,
the remaining counters are summed over runs (divide by runs for a per-run
value), the active-threads pair is a ready-made average, and memory_current
is a live snapshot. Several consumers were dividing the wrong fields or not
dividing the counters at all.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The report aggregates each Func's counters with those of its descendants
for its parent rows; expose that same subtree rollup for every counter in
the JSON, so agents consuming the JSON don't have to walk the parent
pointers to reproduce it. Every field is summed, including the memory and
stack peaks (a Func and its descendants can be live at once, so summing is
a pessimistic bound on the subtree's peak footprint).

The subtree rollup is now computed once per pipeline while printing the
report (which needs it anyway) and persisted for the JSON pass, rather than
recomputed. parallel_tasks, which the report latches downward for its
"realized inside N tasks" warning, is computed into a small side array so
the report keeps its latched value while the JSON gets a uniform subtree
sum.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The JSON warnings array only carried the per-Func (numbered) warnings; the
pipeline-level ones the report prints as bullets — too many auto-named
Funcs, too few samples, and expensive frees — were omitted, and the array
wasn't emitted at all unless a per-Func warning also fired.

Emit the pipeline-level warnings too (in the same order as the report), and
build the array whenever any warning fires. The message text is factored
into a shared helper so the report and JSON can't drift.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Per-Func (numbered) warnings were appended to the pipeline's top-level
warnings array. Move them into a "warnings" array on each Func's JSON
entry instead, grouped by canonical id (they fire per canonical Func, so
every instance shows the same set). The top-level array now holds only the
pipeline-level warnings. The JSON escaping is factored into a shared
template helper used by both.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The cumulative subtree rollup summed every counter but kept a separate
downward-latched parallel_tasks just for the report's warning, leaving the
JSON cumulative parallel_tasks a subtree sum. Latch it directly in the
cumulative stats instead, so the report and the JSON see the same value,
and document that parallel_tasks is the odd one out (a latched task count,
not a subtree sum). Drops the separate latched_tasks array.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Abort (halide_abort_if_false) if any of the JSON-side allocations return
  null — the three side arrays, the pipeline-level warnings string, the
  per-Func warnings array and its per-canonical strings, and the persisted
  cumulative copy. A failed small allocation means the system is in a bad
  state, so bailing out immediately beats limping along. Legitimate
  "not built" nulls (a skipped pipeline's cumulative, a pipeline/Func with
  no warnings) are still handled and emit the empty case.
- Bound the cumulative parent-propagation and parallel_tasks latch with
  parent < num_funcs, not just parent >= 0. The tree builder deliberately
  tolerates orphans whose parent points outside the array; without the
  upper bound those would index cum_stats out of range (a pre-existing gap
  that this change had widened to the full counter region).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@alexreinking

Copy link
Copy Markdown
Member

Did you mean to create a stack here?

@abadams

abadams commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

Yes I did. Should be a stack now.

@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.09%. Comparing base (f7d6109) to head (84eb203).

Additional details and impacted files
@@                       Coverage Diff                       @@
##           abadams/profiler_report_isatty    #9392   +/-   ##
===============================================================
  Coverage                           70.09%   70.09%           
===============================================================
  Files                                 261      261           
  Lines                               79362    79362           
  Branches                            19349    19349           
===============================================================
+ Hits                                55628    55632    +4     
- Misses                              17898    17911   +13     
+ Partials                             5836     5819   -17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants