Skip to content

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

Open
abadams wants to merge 3 commits into
mainfrom
abadams/jit_profile_state_access
Open

A better way to get profiler state from JIT#9423
abadams wants to merge 3 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 5.45455% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.88%. Comparing base (d9debf9) to head (bba9eb4).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/Pipeline.cpp 5.45% 51 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9423      +/-   ##
==========================================
- Coverage   69.95%   69.88%   -0.08%     
==========================================
  Files         261      261              
  Lines       79402    79455      +53     
  Branches    19360    19375      +15     
==========================================
- Hits        55546    55525      -21     
- Misses      17932    18007      +75     
+ Partials     5924     5923       -1     

☔ 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