Skip to content

gh-154060: Fix the Profile Stats offsets in the profiling binary format docs and a missing flag - #157871

Merged
pablogsal merged 5 commits into
python:mainfrom
maurycy:tachyon-docs-profiling-format
Oct 5, 2026
Merged

pablogsal merged 5 commits into
python:mainfrom
maurycy:tachyon-docs-profiling-format

Conversation

@maurycy

@maurycy maurycy commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

The file layout diagram in:

https://github.com/python/cpython/blob/a64b7ecba4db5480504a1a83ae6e80c81472fe16/InternalDocs/profiling_binary_format.md#file-layout

says that the Profile Stats section is 32 bytes and starts at file_size - 64, while it's 56 bytes and starts at file_size - 88 (56 + 32 = 88).

static_assert(PROFILE_STATS_SIZE == 56,
"PROFILE_STATS_SIZE must remain 56");

static_assert(FILE_FOOTER_SIZE == 32,
"FILE_FOOTER_SIZE must remain 32");

The test:

with open(bin_path, "rb") as file:
data = file.read()
stats = data[-88:-32]
footer = bytearray(data[-32:])
old_stats = stats[:16] + b"TACHSTAT" + struct.pack("=II", 1, 32)
old_data = bytearray(data[:-88] + old_stats + footer)

Even the doc itself says 56 bytes later:

New files can store measured duration, sampling rate, error rate, and missed sample percentage in an optional 56-byte extension immediately before the footer.

Both the diagram and the section is since 7f0ccd6.

While we're at it, adding THREAD_STATUS_MAIN_THREAD flag missed from the docs.

Hardly newsworthy, hardly testable but I think would be nice to backport to 3.15.

https://github.com/python/cpython/pull/154105/changes#diff-43a2fe1b7de3546d9e026fcf3664cdc0c35608385926a09e8038a84598acba30 addresses another issue in the document (Total sample count is now uint64.)

@maurycy

maurycy commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

cc @pablogsal 🖤

@maurycy maurycy changed the title gh-154060: Fix the Profile Stats offsets in the profiling binary format docs gh-154060: Fix the Profile Stats offsets in the profiling binary format docs and a missing flag Sep 20, 2026
Comment thread InternalDocs/profiling_binary_format.md Outdated
@pablogsal pablogsal added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 5, 2026
@pablogsal
pablogsal enabled auto-merge (squash) October 5, 2026 14:06
@pablogsal
pablogsal merged commit 8df2580 into python:main Oct 5, 2026
35 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @maurycy for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 5, 2026

Copy link
Copy Markdown

GH-158855 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 5, 2026
pablogsal added a commit that referenced this pull request Oct 5, 2026
…nary format docs and a missing flag (GH-157871) (#158855)

gh-154060: Fix the `Profile Stats` offsets in the profiling binary format docs and a missing flag (GH-157871)

* correct profile stats size and paddings

* missing flag

* gh-154060: Clarify the main-thread status flag

---------
(cherry picked from commit 8df2580)

Co-authored-by: Maurycy Pawłowski-Wieroński <[email protected]>
Co-authored-by: Pablo Galindo Salgado <[email protected]>
@maurycy
maurycy deleted the tachyon-docs-profiling-format branch October 5, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants