Title: `_remote_debugging`: binary format only `total_samples:u32` · Issue #151292 · python/cpython · GitHub
Open Graph Title: `_remote_debugging`: binary format only `total_samples:u32` · Issue #151292 · python/cpython
X Title: `_remote_debugging`: binary format only `total_samples:u32` · Issue #151292 · python/cpython
Description: Bug report Bug description: The binary format defines total_samples as just u32: cpython/Modules/_remote_debugging/binary_io.h Line 269 in 540b3d0 uint32_t total_samples; cpython/Modules/_remote_debugging/binary_io.h Lines 53 to 54 in 54...
Open Graph Description: Bug report Bug description: The binary format defines total_samples as just u32: cpython/Modules/_remote_debugging/binary_io.h Line 269 in 540b3d0 uint32_t total_samples; cpython/Modules/_remote_de...
X Description: Bug report Bug description: The binary format defines total_samples as just u32: cpython/Modules/_remote_debugging/binary_io.h Line 269 in 540b3d0 uint32_t total_samples; cpython/Modules/_remote_de...
Opengraph URL: https://github.com/python/cpython/issues/151292
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`_remote_debugging`: binary format only `total_samples:u32`","articleBody":"# Bug report\n\n### Bug description:\n\nThe binary format defines `total_samples` as just `u32`:\n\nhttps://github.com/python/cpython/blob/540b3d0a7fa7cd842f064f79b1410cbd6868bffa/Modules/_remote_debugging/binary_io.h#L269\n\nhttps://github.com/python/cpython/blob/540b3d0a7fa7cd842f064f79b1410cbd6868bffa/Modules/_remote_debugging/binary_io.h#L53-L54\n\nThat's not that much... With just 100khz:\n\n| Threads | overflow after... |\n|--------:|------------------:|\n| 1 | ~11.9 h |\n| 4 | ~3.0 h |\n| 10 | ~71 min |\n| 64 | ~11 min |\n\nespecially if we aim for continous profiling of real production systems. But even of macOS, I'm observing ~0.5-1MHz on my `mach_vm_remap` branch already...\n\nTo make matters worse, since #150349 it results in `OverflowError` and the binary file is just corrupted:\n\n```\n2026-06-11T02:03:53.357502000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (vmremap 0bdde7f?) % ls -l /tmp/overflow.bin\n-rw-r--r--@ 1 root wheel 4894411257 Jun 11 01:45 /tmp/overflow.bin\n2026-06-11T02:03:58.920689000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (vmremap 0bdde7f?) % head -c 128 /tmp/overflow.bin | xxd\n00000000: 0000 0000 0000 0000 0000 0000 0000 0000 ................\n00000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................\n00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................\n00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................\n00000040: 28b5 2ffd 0058 5c1d 013a d500 1621 8025 (./..X\\..:...!.%\n00000050: 49d2 0133 3003 331a 3330 3d32 35a9 ccc0 I..30.3.30=25...\n00000060: 3aa9 049c b5d6 b69d d296 3122 4488 0c6d :.........1\"D..m\n00000070: 0148 0150 014f 0946 32bd b931 318c b6de .H.P.O.F2..11...\n```\n\nas the header is written on finalize:\n\nhttps://github.com/python/cpython/blob/540b3d0a7fa7cd842f064f79b1410cbd6868bffa/Modules/_remote_debugging/binary_io_writer.c#L1074\nhttps://github.com/python/cpython/blob/540b3d0a7fa7cd842f064f79b1410cbd6868bffa/Modules/_remote_debugging/binary_io_writer.c#L1196-L1223\n\nTo put aside that `u32` is just too little, we should be graceful here.\n\nOther fields seem to be fine, but need a double check here. I think that rotating files is a stop gap, and we need [chunking](https://github.com/maurycy/cpython/pull/2).\n\n# Reproduction\n\n(as a part of routine stress tests of https://github.com/maurycy/cpython/pull/3)\n\n```bash\n[130] 2026-06-10T23:35:58.225891000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (vmremap 92ad857*?) % sudo ./python.exe -m profiling.sampling run --binary -r 1000khz -d 25000 -o /tmp/overflow.bin --realtime-stats busywork.py\nStats: 647,833.9Hz (1.5µs) Min: 615,379.9Hz Max: 705,712.7Hz N=4294631818 Cache: 100.0% (4294631818+0/1)Traceback (most recent call last):\n File \"\u003cfrozen runpy>\", line 201, in _run_module_as_main\n File \"\u003cfrozen runpy>\", line 87, in _run_code\n File \"/Users/maurycy/src/github.com/maurycy/cpython/Lib/profiling/sampling/__main__.py\", line 65, in \u003cmodule>\n main()\n ~~~~^^\n File \"/Users/maurycy/src/github.com/maurycy/cpython/Lib/profiling/sampling/cli.py\", line 977, in main\n _main()\n ~~~~~^^\n File \"/Users/maurycy/src/github.com/maurycy/cpython/Lib/profiling/sampling/cli.py\", line 1133, in _main\n handler(args)\n ~~~~~~~^^^^^^\n File \"/Users/maurycy/src/github.com/maurycy/cpython/Lib/profiling/sampling/cli.py\", line 1280, in _handle_run\n collector = sample(\n process.pid,\n ...\u003c9 lines>...\n blocking=args.blocking,\n )\n File \"/Users/maurycy/src/github.com/maurycy/cpython/Lib/profiling/sampling/sample.py\", line 504, in sample\n profiler.sample(collector, duration_sec, async_aware=async_aware)\n ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Users/maurycy/src/github.com/maurycy/cpython/Lib/profiling/sampling/sample.py\", line 167, in sample\n raise e from None\n File \"/Users/maurycy/src/github.com/maurycy/cpython/Lib/profiling/sampling/sample.py\", line 155, in sample\n collector.collect(stack_frames)\n ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^\n File \"/Users/maurycy/src/github.com/maurycy/cpython/Lib/profiling/sampling/binary_collector.py\", line 84, in collect\n self._writer.write_sample(stack_frames, timestamp_us)\n ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nOverflowError: too many samples for binary format\n[1] 2026-06-11T01:47:42.249903000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (vmremap cd5a675*?) %\n```\n\n```python\ndef hot_a(n):\n return sum(i * i for i in range(n))\n\n\ndef hot_b(n):\n return sum(i + i for i in range(n))\n\n\ndef worker():\n while True:\n hot_a(6_000_000)\n hot_b(6_000_000)\n\n\nworker()\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-152892\n* gh-153425\n* gh-153436\n* gh-158830\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/maurycy","@type":"Person","name":"maurycy"},"datePublished":"2026-06-11T00:11:56Z","url":"https://github.com/python/cpython/issues/151292"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e600a4f1-3d58-cc8b-82f3-1921af03d477 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC78:EA09B:39F87A8:4CCBC76:6B021B8D |
| html-safe-nonce | 861d2e2fd532bb635bb5c3cf99539bec00f094aa35dc3689057fc947c075ae0e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzc4OkVBMDlCOjM5Rjg3QTg6NENDQkM3Njo2QjAyMUI4RCIsInZpc2l0b3JfaWQiOiIzNDExODYwMzk3NTQ2OTM3MjMwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2bd565d106852d5b99a685da13fdd531ee0224e92e36da393516ceeb77213b68 |
| hovercard-subject-tag | issue:4636019998 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/151292/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f24b1b6148d91c6c53460f55c04d16326c8acbe10b2ddb4e11c6d2de3feaad34/python/cpython/issues/151292 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f24b1b6148d91c6c53460f55c04d16326c8acbe10b2ddb4e11c6d2de3feaad34/python/cpython/issues/151292 |
| og:image:alt | Bug report Bug description: The binary format defines total_samples as just u32: cpython/Modules/_remote_debugging/binary_io.h Line 269 in 540b3d0 uint32_t total_samples; cpython/Modules/_remote_de... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | maurycy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width