Skip to content

A better way to get profiler state from JIT - #9423

Merged
abadams merged 8 commits into
mainfrom
abadams/jit_profile_state_access
Sep 16, 2026
Merged

abadams merged 8 commits into
mainfrom
abadams/jit_profile_state_access

Conversation

@abadams

@abadams abadams commented Sep 2, 2026

Copy link
Copy Markdown
Member

This PR takes the scoped profiler helper from f21bac0 and expands it into an object that lets you access profiler state from JIT-land programmatically. This is used to clean up the memory profiler test, which currently has a nasty hack to snapshot profiler state.

abadams and others added 3 commits September 2, 2026 10:27
Pipeline::realize on a Target with the Profile feature reports and then
resets the profiler after every run, so there was no way to read the
profiler's statistics programmatically without hooking a trace event
and snapshotting the running instance before the reset.

ProfilerScope holds a Pipeline (or the Pipeline behind a Func) and,
while alive, stops realize from reporting and resetting. Statistics
accumulate across every run in the scope and can be read via
pipeline_stats() and func_stats(). The last scope to be destroyed for a
pipeline prints the report and resets, as an unscoped realize would.

The lookup walks the profiler's pipeline list comparing names by string,
because halide_profiler_get_pipeline_state compares by pointer and so
only works from inside the JIT module.

The memory profiler test now uses this instead of the trace-event hook.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GaAM5BTGYrrWUxTZ18Aya8
hl.ProfilerScope wraps a Pipeline or Func and works as a context
manager; leaving the with-block reports and resets the profiler.
pipeline_stats() and func_stats() return Python-owned snapshots
(ProfilerPipelineStats, ProfilerFuncStats) so they remain valid after
the scope exits. Also exposes the halide_profiler_func_kind enum as
ProfilerFuncKind.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GaAM5BTGYrrWUxTZ18Aya8
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GaAM5BTGYrrWUxTZ18Aya8
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 3.63636% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.02%. Comparing base (4c5525c) to head (3001fe9).

Files with missing lines Patch % Lines
src/Pipeline.cpp 3.63% 51 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9423      +/-   ##
==========================================
- Coverage   70.12%   70.02%   -0.10%     
==========================================
  Files         261      261              
  Lines       79818    79871      +53     
  Branches    19445    19460      +15     
==========================================
- Hits        55972    55933      -39     
- Misses      17991    18043      +52     
- Partials     5855     5895      +40     

☔ 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.

abadams and others added 3 commits September 11, 2026 05:00
Pipeline::realize on a Target with the Profile feature reports and then
resets the profiler after every run, so there was no way to read the
profiler's statistics programmatically without hooking a trace event
and snapshotting the running instance before the reset.

ProfilerScope holds a Pipeline (or the Pipeline behind a Func) and,
while alive, stops realize from reporting and resetting. Statistics
accumulate across every run in the scope and can be read via
pipeline_stats() and func_stats(). The last scope to be destroyed for a
pipeline prints the report and resets, as an unscoped realize would.

The lookup walks the profiler's pipeline list comparing names by string,
because halide_profiler_get_pipeline_state compares by pointer and so
only works from inside the JIT module.

The memory profiler test now uses this instead of the trace-event hook.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GaAM5BTGYrrWUxTZ18Aya8
hl.ProfilerScope wraps a Pipeline or Func and works as a context
manager; leaving the with-block reports and resets the profiler.
pipeline_stats() and func_stats() return Python-owned snapshots
(ProfilerPipelineStats, ProfilerFuncStats) so they remain valid after
the scope exits. Also exposes the halide_profiler_func_kind enum as
ProfilerFuncKind.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GaAM5BTGYrrWUxTZ18Aya8
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GaAM5BTGYrrWUxTZ18Aya8
@alexreinking
alexreinking force-pushed the abadams/jit_profile_state_access branch from bba9eb4 to b5c165e Compare September 11, 2026 09:00
@abadams
abadams merged commit ff06008 into main Sep 16, 2026
28 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.

2 participants