Skip to content

feat: skip Python runtime objects in callgrind#122

Merged
not-matthias merged 1 commit into
masterfrom
cod-2654-flamegraph-doesnt-work-on-valgrind
May 14, 2026
Merged

feat: skip Python runtime objects in callgrind#122
not-matthias merged 1 commit into
masterfrom
cod-2654-flamegraph-doesnt-work-on-valgrind

Conversation

@not-matthias
Copy link
Copy Markdown
Member

@not-matthias not-matthias commented May 14, 2026

No description provided.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 14, 2026

Merging this PR will not alter performance

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 21 improved benchmarks
❌ 24 (👁 24) regressed benchmarks
✅ 232 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_recursive_fibo_20 5.5 ms 5.4 ms +2.43%
WallTime test_combination_sum[candidates0-8] 12 µs 11.4 µs +5.25%
👁 WallTime test_multiprocessing_map[1000] 58.8 ms 60.7 ms -3.12%
👁 WallTime test_color[graph0-3] 30.1 µs 31.4 µs -4%
👁 WallTime test_open_close_fd[100] 882.8 µs 919.1 µs -3.94%
WallTime test_fs_write[1000] 18.7 µs 18 µs +4.15%
👁 WallTime test_tcp_connection[1.1.1.1-53] 1.1 ms 1.1 ms -4.32%
WallTime test_n_queens_solve[board0] 11.1 ms 10.9 ms +2.29%
👁 WallTime test_open_knight_tour[1] 4.3 µs 4.4 µs -2.26%
👁 WallTime test_noop_lambda_decorated 1.3 µs 1.3 µs -2.59%
👁 WallTime test_multiprocessing_map[10000] 89.9 ms 108.8 ms -17.36%
WallTime test_match_word_pattern[aba-GraphTreesGraph] 109.7 µs 106.6 µs +2.92%
WallTime test_hamilton_cycle[graph0] 26.1 µs 25.4 µs +2.82%
👁 WallTime test_generate_all_combinations[5-4] 10.1 µs 10.6 µs -5%
WallTime test_sum_of_squares[sum_of_squares_sum_comprehension_product] 198.5 µs 192.9 µs +2.93%
WallTime test_fs_write[10000] 44.6 µs 41.8 µs +6.62%
👁 WallTime test_tcp_connection[google.com-443] 1.2 ms 1.2 ms -3.64%
WallTime test_fs_read[1000] 878.4 ns 850.2 ns +3.31%
WallTime test_hostname_resolution[google.com] 397.4 µs 388.6 µs +2.26%
👁 WallTime test_process_creation[cat /dev/null] 5.3 ms 5.4 ms -2%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing cod-2654-flamegraph-doesnt-work-on-valgrind (3bbabe4) with master (d4d9dc6)

Open in CodSpeed

@not-matthias not-matthias marked this pull request as ready for review May 14, 2026 18:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a Callgrind/Valgrind client-request hook so CodSpeed can instruct Callgrind to ignore Python runtime object files (libpython + the python executable), reducing noise in Callgrind-derived flamegraphs.

Changes:

  • Add a new C-extension method callgrind_add_obj_skip(bytes_path) that issues a custom Valgrind client request.
  • Add Python helpers to resolve and register object-file paths (including realpath) for skipping.
  • Invoke the skip logic during InstrumentHooks initialization to hide Python runtime frames by default.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c Exposes a new C-extension entrypoint that emits a Callgrind client request to skip an object file by path.
src/pytest_codspeed/instruments/hooks/__init__.py Adds Python wrappers to call the extension and automatically skip libpython + the Python executable in Callgrind.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c
Comment thread src/pytest_codspeed/instruments/hooks/__init__.py
Copy link
Copy Markdown
Contributor

@GuillaumeLagrange GuillaumeLagrange left a comment

Choose a reason for hiding this comment

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

OLGTM, trusting you on how we retrieve the skipped path from python runtime

Comment thread src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c
Adds a callgrind_add_obj_skip C extension function that emits the
Valgrind client request VG_USERREQ__ADD_OBJ_SKIP (0x43540006), and a
callgrind_skip_python_runtime() helper that skips libpython and the
python executable. Called from InstrumentHooks.__init__ so Python runtime
frames stop polluting the callgrind flamegraph (COD-2654).
Comment thread src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c
Copy link
Copy Markdown
Contributor

@GuillaumeLagrange GuillaumeLagrange left a comment

Choose a reason for hiding this comment

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

lgtm, discussed the callgrind.h and let's keep it this way temporarily

@not-matthias not-matthias force-pushed the cod-2654-flamegraph-doesnt-work-on-valgrind branch from d7b50b1 to 3bbabe4 Compare May 14, 2026 18:57
@not-matthias not-matthias merged commit 3bbabe4 into master May 14, 2026
63 checks passed
@not-matthias not-matthias deleted the cod-2654-flamegraph-doesnt-work-on-valgrind branch May 14, 2026 19:28
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.

4 participants