Skip to content

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

Open
maurycy wants to merge 2 commits into
python:mainfrom
maurycy:tachyon-docs-profiling-format
Open

maurycy wants to merge 2 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
| 2 | THREAD_STATUS_UNKNOWN | Thread state could not be determined |
| 3 | THREAD_STATUS_GIL_REQUESTED | Thread is waiting to acquire the GIL |
| 4 | THREAD_STATUS_HAS_EXCEPTION | Thread has a pending exception |
| 5 | THREAD_STATUS_MAIN_THREAD | Thread is the process's main thread |

@maurycy maurycy Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
| 5 | THREAD_STATUS_MAIN_THREAD | Thread is the process's main thread |
| 5 | THREAD_STATUS_MAIN_THREAD | Thread is the interpreter's main thread |

Very formally speaking I think that's the case... I don't know if should expose this, though. Leaving as a suggestion, so the reviewer can just click or resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant