Skip to content

Add nautilus-profiling plugin for runtime performance analysis - #244

Open
PhilippGrulich wants to merge 1 commit into
mainfrom
claude/nautilus-profiling-plugin-AGwCD
Open

Add nautilus-profiling plugin for runtime performance analysis#244
PhilippGrulich wants to merge 1 commit into
mainfrom
claude/nautilus-profiling-plugin-AGwCD

Conversation

@PhilippGrulich

Copy link
Copy Markdown
Member

New plugin that provides cross-backend function profiling for Nautilus:

  • ProfiledFunction wrapper with zero overhead when profiling inactive
  • Thread-local call stacks and ring buffers for lock-free hot path
  • Chrome Trace Format export (viewable in Perfetto/chrome://tracing)
  • Folded stacks export (for Brendan Gregg's flamegraph.pl)
  • Perf map writer (/tmp/perf-.map) for JIT symbol resolution
  • Sampling support to reduce overhead for high-frequency calls
  • Optional CPU cycle collection via rdtsc (x86)

https://claude.ai/code/session_01SLkb9NXtrjb4QAkiUTTMf9

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracing Benchmark

Details
Benchmark suite Current: 2fccf55 Previous: 735a59d Ratio
e2e_tiered_bc_to_mlir 54.7671 us (± 12.073) 44.7721 us (± 16.4703) 1.22
e2e_single_mlir 8.216 ms (± 195.965) 9.16088 ms (± 188.959) 0.90
ir_add 683.408 ns (± 125.492) 557.603 ns (± 33.4202) 1.23
ir_ifThenElse 1.53666 us (± 203.108) 1.35697 us (± 125.581) 1.13
ir_deeplyNestedIfElse 3.53577 us (± 533.464) 3.25431 us (± 120.92) 1.09
ir_loop 1.6294 us (± 199.26) 1.48915 us (± 149.204) 1.09
ir_ifInsideLoop 2.96122 us (± 442.026) 2.71554 us (± 269.14) 1.09
ir_loopDirectCall 1.75895 us (± 200.625) 1.53102 us (± 46.9752) 1.15
ir_pointerLoop 2.04121 us (± 241.925) 1.97107 us (± 430.214) 1.04
ir_staticLoop 1.385 us (± 186.946) 1.21683 us (± 80.1593) 1.14
ir_fibonacci 1.74644 us (± 190.629) 1.57054 us (± 100.473) 1.11
ir_gcd 1.4915 us (± 261.968) 1.30244 us (± 80.1681) 1.15
ir_nestedIf10 7.80092 us (± 759.417) 7.07715 us (± 494.947) 1.10
ir_nestedIf100 90.2452 us (± 5.46478) 94.1299 us (± 6.63792) 0.96
ir_chainedIf10 12.5194 us (± 995.477) 11.6931 us (± 684.358) 1.07
ir_chainedIf100 180.376 us (± 8.65112) 178.212 us (± 10.231) 1.01
ssa_add 198.299 ns (± 21.9527) 178.589 ns (± 8.61098) 1.11
ssa_ifThenElse 494.836 ns (± 65.537) 432.511 ns (± 24.8694) 1.14
ssa_deeplyNestedIfElse 1.24183 us (± 138.063) 1.12092 us (± 62.1812) 1.11
ssa_loop 532.229 ns (± 62.3371) 454.465 ns (± 22.6714) 1.17
ssa_ifInsideLoop 949.79 ns (± 111.829) 914.873 ns (± 156.953) 1.04
ssa_loopDirectCall 525.267 ns (± 51.9665) 463.089 ns (± 27.2138) 1.13
ssa_pointerLoop 615.26 ns (± 61.8665) 554.161 ns (± 36.2962) 1.11
ssa_staticLoop 486.748 ns (± 67.996) 430.496 ns (± 17.6849) 1.13
ssa_fibonacci 548.787 ns (± 72.4053) 475.635 ns (± 26.8476) 1.15
ssa_gcd 472.001 ns (± 44.8091) 422.707 ns (± 24.5879) 1.12
comp_mlir_add 8.16241 ms (± 141.623) 9.42323 ms (± 413.446) 0.87
comp_mlir_ifThenElse 8.78392 ms (± 179.918) 10.0186 ms (± 356.845) 0.88
comp_mlir_deeplyNestedIfElse 7.82057 ms (± 279.79) 9.30722 ms (± 253.08) 0.84
comp_mlir_loop 9.89583 ms (± 221.832) 11.6633 ms (± 259.204) 0.85
comp_mlir_ifInsideLoop 31.5907 ms (± 537.955) 33.8733 ms (± 651.356) 0.93
comp_mlir_loopDirectCall 14.5314 ms (± 279.57) 16.3832 ms (± 447.685) 0.89
comp_mlir_pointerLoop 30.7105 ms (± 521.05) 32.7066 ms (± 451.19) 0.94
comp_mlir_staticLoop 7.75208 ms (± 161.867) 8.53315 ms (± 175.692) 0.91
comp_mlir_fibonacci 13.2057 ms (± 225.043) 14.6574 ms (± 312.126) 0.90
comp_mlir_gcd 12.1243 ms (± 231.481) 13.9072 ms (± 1.1126) 0.87
comp_mlir_nestedIf10 14.2804 ms (± 585.905) 14.7447 ms (± 361.456) 0.97
comp_mlir_nestedIf100 27.774 ms (± 416.369) 29.0962 ms (± 380.159) 0.95
comp_mlir_chainedIf10 12.4629 ms (± 292.477) 14.0527 ms (± 1.03727) 0.89
comp_mlir_chainedIf100 23.2097 ms (± 597.686) 24.8764 ms (± 347.559) 0.93
comp_cpp_add 25.0594 ms (± 550.437) 28.8601 ms (± 464.566) 0.87
comp_cpp_ifThenElse 25.8434 ms (± 634.298) 29.4161 ms (± 503.621) 0.88
comp_cpp_deeplyNestedIfElse 26.8055 ms (± 652.32) 30.3349 ms (± 470.032) 0.88
comp_cpp_loop 26.3085 ms (± 785.009) 29.5386 ms (± 452.283) 0.89
comp_cpp_ifInsideLoop 27.1847 ms (± 710.565) 30.6408 ms (± 1.1838) 0.89
comp_cpp_loopDirectCall 26.7895 ms (± 880.228) 29.968 ms (± 534.834) 0.89
comp_cpp_pointerLoop 26.2453 ms (± 567.182) 30.0626 ms (± 649.42) 0.87
comp_cpp_staticLoop 26.3035 ms (± 1.09779) 29.3365 ms (± 625) 0.90
comp_cpp_fibonacci 26.1082 ms (± 617.409) 30.3049 ms (± 1.0683) 0.86
comp_cpp_gcd 25.7528 ms (± 634.316) 30.1386 ms (± 655.731) 0.85
comp_cpp_nestedIf10 28.9192 ms (± 664.198) 33.1127 ms (± 1.59488) 0.87
comp_cpp_nestedIf100 62.9123 ms (± 1.60961) 66.1697 ms (± 1.99571) 0.95
comp_cpp_chainedIf10 31.7168 ms (± 544.477) 35.0051 ms (± 569.074) 0.91
comp_cpp_chainedIf100 92.52 ms (± 936.298) 95.6542 ms (± 1.27066) 0.97
comp_bc_add 14.5435 us (± 2.21486) 14.4189 us (± 2.37199) 1.01
comp_bc_ifThenElse 18.7079 us (± 3.37375) 16.7978 us (± 3.7847) 1.11
comp_bc_deeplyNestedIfElse 23.3502 us (± 4.11475) 20.1859 us (± 4.35147) 1.16
comp_bc_loop 18.5939 us (± 3.35349) 16.8307 us (± 3.90376) 1.10
comp_bc_ifInsideLoop 21.316 us (± 3.50596) 18.9231 us (± 3.849) 1.13
comp_bc_loopDirectCall 19.2566 us (± 3.68133) 17.0217 us (± 3.51388) 1.13
comp_bc_pointerLoop 20.6824 us (± 4.86347) 18.0283 us (± 4.01563) 1.15
comp_bc_staticLoop 16.9912 us (± 2.82385) 16.5494 us (± 3.68146) 1.03
comp_bc_fibonacci 18.7936 us (± 3.33194) 17.0462 us (± 3.76914) 1.10
comp_bc_gcd 19.3061 us (± 5.00465) 15.9395 us (± 2.47334) 1.21
comp_bc_nestedIf10 35.9529 us (± 4.75701) 31.0134 us (± 4.42009) 1.16
comp_bc_nestedIf100 201.857 us (± 10.1483) 191.712 us (± 9.52673) 1.05
comp_bc_chainedIf10 52.5269 us (± 8.73991) 43.141 us (± 8.89736) 1.22
comp_bc_chainedIf100 311.203 us (± 14.6285) 309.419 us (± 12.6364) 1.01
comp_asmjit_add 21.3213 us (± 4.7054) 17.5231 us (± 5.7044) 1.22
comp_asmjit_ifThenElse 33.0105 us (± 4.40255) 26.185 us (± 5.62526) 1.26
comp_asmjit_deeplyNestedIfElse 57.2958 us (± 10.4535) 47.5287 us (± 10.7073) 1.21
comp_asmjit_loop 35.9778 us (± 5.8488) 28.2969 us (± 6.06829) 1.27
comp_asmjit_ifInsideLoop 57.4703 us (± 10.2007) 47.413 us (± 12.3118) 1.21
comp_asmjit_loopDirectCall 65.6188 us (± 16.4463) 30.9936 us (± 6.48682) 2.12
comp_asmjit_pointerLoop 48.2705 us (± 9.42333) 33.2829 us (± 5.89897) 1.45
comp_asmjit_staticLoop 28.4792 us (± 5.07002) 23.4582 us (± 4.88987) 1.21
comp_asmjit_fibonacci 43.1285 us (± 8.03749) 30.2905 us (± 5.68839) 1.42
comp_asmjit_gcd 34.4759 us (± 4.84178) 28.1555 us (± 6.13342) 1.22
comp_asmjit_nestedIf10 103.171 us (± 11.6038) 96.044 us (± 15.4869) 1.07
comp_asmjit_nestedIf100 1.03411 ms (± 40.8132) 1.04677 ms (± 51.1612) 0.99
comp_asmjit_chainedIf10 154.8 us (± 15.8851) 148.825 us (± 16.3448) 1.04
comp_asmjit_chainedIf100 2.14084 ms (± 27.6337) 2.19743 ms (± 43.3502) 0.97
exec_mlir_add 11.0682 ns (± 1.01233) 11.1087 ns (± 0.853075) 1.00
exec_mlir_fibonacci 14.2285 us (± 1.40998) 18.7581 us (± 2.52184) 0.76
exec_mlir_sum 557.915 us (± 34.7983) 565.098 us (± 56.3939) 0.99
exec_cpp_add 4.78506 ns (± 0.919231) 4.67595 ns (± 1.06637) 1.02
exec_cpp_fibonacci 97.0579 us (± 9.67916) 109.488 us (± 8.76714) 0.89
exec_cpp_sum 36.0829 ms (± 857.458) 23.5994 ms (± 113.601) 1.53
exec_bc_add 45.6111 ns (± 7.86091) 44.5227 ns (± 6.90048) 1.02
exec_bc_fibonacci 787.658 us (± 14.7907) 626.695 us (± 14.1954) 1.26
exec_bc_sum 168.61 ms (± 263.39) 143.596 ms (± 1.5291) 1.17
exec_asmjit_add 3.5426 ns (± 0.433836) 3.16976 ns (± 0.210314) 1.12
exec_asmjit_fibonacci 20.6619 us (± 1.74046) 22.4194 us (± 2.2047) 0.92
exec_asmjit_sum 4.84839 ms (± 24.9235) 5.28048 ms (± 29.4129) 0.92
exec_bc_add_noRegAlloc 43.8871 ns (± 4.30266) 43.4498 ns (± 2.08094) 1.01
exec_bc_add_regAlloc 44.6625 ns (± 6.27319) 43.0869 ns (± 1.60579) 1.04
exec_bc_fibonacci_noRegAlloc 787.423 us (± 16.4042) 631.805 us (± 12.0476) 1.25
exec_bc_fibonacci_regAlloc 788.138 us (± 12.4609) 626.084 us (± 11.7745) 1.26
exec_bc_sum_noRegAlloc 168.646 ms (± 1.10532) 144.361 ms (± 7.34656) 1.17
exec_bc_sum_regAlloc 168.925 ms (± 1.62293) 143.149 ms (± 1.08876) 1.18
tiered_compile_addOne 53.2616 us (± 13.052) 43.1655 us (± 15.6613) 1.23
single_compile_mlir_addOne 6.53973 ms (± 837.363) 7.30884 ms (± 250.756) 0.89
single_compile_cpp_addOne 25.7984 ms (± 668.839) 29.3191 ms (± 604.247) 0.88
single_compile_bc_addOne 55.4063 us (± 12.5207) 47.631 us (± 23.1615) 1.16
tiered_compile_sumLoop 74.7299 us (± 10.0684) 60.9415 us (± 18.3227) 1.23
single_compile_mlir_sumLoop 8.54146 ms (± 298.643) 9.44764 ms (± 302.585) 0.90
single_compile_cpp_sumLoop 25.9572 ms (± 858.66) 30.3033 ms (± 749.906) 0.86
single_compile_bc_sumLoop 77.0379 us (± 13.5931) 62.316 us (± 18.6408) 1.24
exec_bc_addOne 37.5175 ns (± 7.47004) 35.8115 ns (± 3.14464) 1.05
exec_mlir_addOne 289.423 ns (± 12.719) 318.969 ns (± 13.122) 0.91
exec_cpp_addOne 4.11486 ns (± 0.937765) 4.15126 ns (± 0.438887) 0.99
exec_interpreted_addOne 41.4778 ns (± 4.22045) 38.4164 ns (± 1.75957) 1.08
trace_add 2.40625 us (± 247.496) 2.06394 us (± 181.932) 1.17
completing_trace_add 2.42015 us (± 314.091) 2.09441 us (± 173.694) 1.16
trace_ifThenElse 9.05026 us (± 1.39162) 7.82154 us (± 1.27749) 1.16
completing_trace_ifThenElse 4.79966 us (± 734.403) 4.15494 us (± 494.679) 1.16
trace_deeplyNestedIfElse 26.8847 us (± 3.47424) 23.5052 us (± 3.7184) 1.14
completing_trace_deeplyNestedIfElse 13.2808 us (± 1.7771) 11.5912 us (± 1.68569) 1.15
trace_loop 9.11383 us (± 1.43192) 7.70984 us (± 1.09486) 1.18
completing_trace_loop 4.9523 us (± 763.863) 4.27197 us (± 452.073) 1.16
trace_ifInsideLoop 17.7908 us (± 2.97482) 15.3213 us (± 2.10195) 1.16
completing_trace_ifInsideLoop 8.94958 us (± 1.76726) 7.73302 us (± 938.568) 1.16
trace_loopDirectCall 9.1779 us (± 1.41379) 7.80253 us (± 1.15647) 1.18
completing_trace_loopDirectCall 5.06418 us (± 889.091) 4.2795 us (± 509.818) 1.18
trace_pointerLoop 14.7854 us (± 2.63526) 12.6363 us (± 2.33328) 1.17
completing_trace_pointerLoop 10.9273 us (± 1.61604) 8.99261 us (± 1.44436) 1.22
trace_staticLoop 7.84281 us (± 1.07616) 7.04359 us (± 755.434) 1.11
completing_trace_staticLoop 8.02091 us (± 1.07411) 7.09734 us (± 735.226) 1.13
trace_fibonacci 10.726 us (± 1.9064) 9.02193 us (± 1.46526) 1.19
completing_trace_fibonacci 6.68872 us (± 1.09886) 5.49339 us (± 665.791) 1.22
trace_gcd 8.36616 us (± 1.34929) 8.90115 us (± 2.65556) 0.94
completing_trace_gcd 4.1841 us (± 538.403) 3.57162 us (± 411.759) 1.17
trace_nestedIf10 39.7454 us (± 7.88893) 36.5071 us (± 7.32195) 1.09
completing_trace_nestedIf10 40.5467 us (± 7.91072) 36.8142 us (± 7.18954) 1.10
trace_nestedIf100 1.35962 ms (± 64.4087) 1.56252 ms (± 247.341) 0.87
completing_trace_nestedIf100 1.37936 ms (± 55.947) 1.4543 ms (± 35.5561) 0.95
trace_chainedIf10 100.314 us (± 10.0364) 92.2442 us (± 11.1303) 1.09
completing_trace_chainedIf10 51.8227 us (± 9.51509) 46.815 us (± 8.88196) 1.11
trace_chainedIf100 4.43399 ms (± 49.7087) 4.4846 ms (± 225.461) 0.99
completing_trace_chainedIf100 2.30073 ms (± 104.487) 2.19662 ms (± 55.2405) 1.05

This comment was automatically generated by workflow using github-action-benchmark.

@PhilippGrulich
PhilippGrulich force-pushed the claude/nautilus-profiling-plugin-AGwCD branch 4 times, most recently from 9f18d08 to 728157f Compare April 19, 2026 07:06
Introduces a `plugins/profiling/` plugin that auto-instruments every
compiled function with wall-clock timing and (on Linux) hardware
performance-counter sampling via `perf_event_open`.

Plugin pass infrastructure:
- `nautilus::compiler::ir::IRPass` (in `compiler/ir/passes/IRPass.hpp`)
  is now the single base class for both built-in and plugin passes;
  `nautilus::IRPass` is a friendly alias for plugin code.
- `JITCompiler::addIRPass(unique_ptr<IRPass>)` is part of the abstract
  interface. `LegacyCompiler` stores plugin passes as `shared_ptr` and
  appends them to the same `IRPassManager` that runs built-in passes,
  so plugin passes share dump/verify/statistics handling.
- `TieredJITCompiler::addIRPass` delegates to its inner `LegacyCompiler`
  — plugin passes now work in both tier-0 and tier-1 (replacing the
  previous "TieredJITCompiler does not support plugin IR passes" throw).
- `IRPassManager::addPass` switched to `shared_ptr<IRPass>`; built-in
  callers pass `make_shared<...>` (refcount=1, semantically equivalent
  to unique_ptr), plugin passes flow through unchanged.
- `NautilusEngine::addIRPass()` is the public entry point; defined
  out-of-line in `Engine.cpp` so the public header keeps `IRPass`
  forward-declared and `NautilusModule` stays a pure function registry.

Profiling plugin:
- `ProfilingIRPass` walks every `FunctionOperation` and emits
  `ProfileRegion::runtimeStart` / `runtimeStop` proxy calls at entry
  and every return site.
- `Profiler` / `ProfileRegion` provide thread-safe accounting for call
  counts, total/min/max latency and up to four HW event counters; the
  profiler reports to stdout or Chrome-trace JSON on destruction.
- `Profiler::enableForEngine(engine)` is the user-facing entry point —
  installs the IR pass on the engine so every subsequent module the
  engine compiles is instrumented automatically.
- Example (`DemoProfilingPlugin.cpp`) and full test suite
  (`ProfilingTest.cpp`, 10 cases / 1039 assertions) covering timing,
  multi-function modules, and the Linux perf-counter paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@PhilippGrulich
PhilippGrulich force-pushed the claude/nautilus-profiling-plugin-AGwCD branch from 728157f to 2fccf55 Compare April 19, 2026 19:36
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.

1 participant