René's URL Explorer Experiment


Title: Add Perfetto trace output to profiling.sampling · Issue #150327 · python/cpython · GitHub

Open Graph Title: Add Perfetto trace output to profiling.sampling · Issue #150327 · python/cpython

X Title: Add Perfetto trace output to profiling.sampling · Issue #150327 · python/cpython

Description: Feature or enhancement Proposal: Feature Add a Perfetto trace output backend to profiling.sampling (target: 3.16), alongside the existing other output formats. This would let users open Python sampling profiles directly in the Perfetto U...

Open Graph Description: Feature or enhancement Proposal: Feature Add a Perfetto trace output backend to profiling.sampling (target: 3.16), alongside the existing other output formats. This would let users open Python samp...

X Description: Feature or enhancement Proposal: Feature Add a Perfetto trace output backend to profiling.sampling (target: 3.16), alongside the existing other output formats. This would let users open Python samp...

Opengraph URL: https://github.com/python/cpython/issues/150327

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add Perfetto trace output to profiling.sampling","articleBody":"# Feature or enhancement\n\n### Proposal:\n\n## Feature\n\nAdd a Perfetto trace output backend to `profiling.sampling` (target: 3.16), alongside the existing other output formats. This would let users open Python sampling profiles directly in the [Perfetto UI](https://ui.perfetto.dev) and analyse them with PerfettoSQL in the [trace processor](https://perfetto.dev/docs/analysis/trace-processor).\n\nOpening this for design sanity-check before sending a PR, as suggested by @pablogsal in offline discussion. The most load-bearing question (how to emit protobuf without a runtime dependency) is covered below.\n\n## Motivation\n\n- Perfetto is a trace viewer oriented systems-perf work, and being able to view Python samples there means a Python profile can sit on the same timeline as scheduler events, native CPU samples, and application instrumentation rather than living in a separate tool.\n- Once trace processor can read the output, users get SQL-driven analysis of Python samples (top-N functions, per-thread breakdowns, custom aggregations).\n\n## Proposed design\n\n### Output format\n\nEmit a Perfetto trace (`perfetto.protos.Trace`) containing:\n- A `ProcessDescriptor` / `ThreadDescriptor` per observed process/thread.\n- `InternedData` carrying `Frame`, `Mapping`, and `Callstack` entries\n- One `TracePacket` per sample containing a `StackSample` message that references the interned callstack.\n\n`StackSample` is part of a **new set of public profiling protos** I'm landing in Perfetto specifically so that producers like this one have a stable, transport-neutral surface to target (rather than reusing `PerfSample`, which is shaped by `perf_event_open` and leaks producer diagnostics into the data). The RFC is at https://github.com/google/perfetto/discussions/6027.\n\nConcretely, each Python sample maps to roughly:\n\n```\nTracePacket {\n  timestamp: \u003cns>\n  trusted_packet_sequence_id: \u003cseq>\n  interned_data { ... }  // first packet only, or as new frames appear\n  stack_sample {\n    task_context_iid: \u003cthread>\n    execution_context_iid: \u003ccpu/mode>     // optional\n    callstack_iid: \u003cinterned callstack>\n    primary_descriptor_iid: \u003c\"wall_time_ns\" counter>\n    primary_weight: \u003cns since last sample>\n  }\n}\n```\n### Proto serialisation without a runtime dependency\n\nThe stdlib can't depend on `protobuf`, so I'd hand-roll the wire format for the specific message types we emit. This is tractable because:\n\n- **Proto wire format is tiny.** It's varints + length-delimited + fixed32/64 + a tag byte per field. The whole encoder for the messages we need is on the order of a couple hundred lines of Python.\n- **We only encode, never decode.** Decoding protobuf is signifcantly harder than encode.\n- **The set of message types is small and stable.** I've specifically designated in the RFC upstream that these protos I'm adding are going to be \"eternally stabe\" protos which we won't change the wire format or semantics in a non-backwards compatible way.\n- **Precedent.** Perfetto itself ships an ad-hoc proto encoder/decoder (`protozero`) in C++ for similar reasons.\n\nSketch of the shape:\n\n```python\n# Hand-rolled, no runtime deps.\ndef _varint(buf, n): ...\ndef _tag(buf, field_no, wire_type): ...\ndef _string(buf, field_no, s): ...\ndef _message(buf, field_no, payload): ...\n\ndef encode_stack_sample(buf, sample):\n    _tag(buf, 1, WIRE_VARINT); _varint(buf, sample.task_context_iid)\n    _tag(buf, 6, WIRE_VARINT); _varint(buf, sample.callstack_iid)\n    # ...\n```\n\nField numbers and wire types come straight from the `.proto` definitions in the Perfetto RFC. Any wire type constants would be inlined as Python integers.\n\n### CLI surface\n\nA new `--format perfetto` CLI flag to the profiling.sampling module in all the same places `--gecko` is allowed today.\n\n## Target\n\nPython 3.16.\n\n## Prerequisites\n\n- [Perfetto RFC-0027](https://github.com/google/perfetto/discussions/6027): public stack-sampling and heap-profiling protos. Required before this lands so we're targeting the stable protos.\n\ncc @pablogsal\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154541\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/LalitMaganti","@type":"Person","name":"LalitMaganti"},"datePublished":"2026-05-23T23:18:08Z","url":"https://github.com/python/cpython/issues/150327"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d8a01e3b-1099-141c-63c0-244513a699c7
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA01E:A70A9:1EE5A21:28AE7B3:6B023346
html-safe-nonce1b9992514d85ee5ffadd6510a0ce81b6dfb940518027fc364ec1ef1c5596f8b2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDFFOkE3MEE5OjFFRTVBMjE6MjhBRTdCMzo2QjAyMzM0NiIsInZpc2l0b3JfaWQiOiI1NDM5MzcwODI1NjkyMjMwNDcwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacad79ca3fedcaa75fa2e0326109a6959d0133bb64273c93b9aa7df90a3ae6b2a1
hovercard-subject-tagissue:4509876655
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/150327/issue_layout
twitter:imagehttps://opengraph.githubassets.com/8f524342d4c970d9bd94f17a5173522f388a95da33e64dfbee0e5acf7b0390f6/python/cpython/issues/150327
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/8f524342d4c970d9bd94f17a5173522f388a95da33e64dfbee0e5acf7b0390f6/python/cpython/issues/150327
og:image:altFeature or enhancement Proposal: Feature Add a Perfetto trace output backend to profiling.sampling (target: 3.16), alongside the existing other output formats. This would let users open Python samp...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameLalitMaganti
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/150327#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F150327
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F150327
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/150327
Reloadhttps://github.com/python/cpython/issues/150327
Reloadhttps://github.com/python/cpython/issues/150327
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/150327
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/150327
Add Perfetto trace output to profiling.samplinghttps://github.com/python/cpython/issues/150327#top
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-profilinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-profiling%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/LalitMaganti
LalitMagantihttps://github.com/LalitMaganti
on May 23, 2026https://github.com/python/cpython/issues/150327#issue-4509876655
Perfetto UIhttps://ui.perfetto.dev
trace processorhttps://perfetto.dev/docs/analysis/trace-processor
@pablogsalhttps://github.com/pablogsal
google/perfetto#6027https://github.com/google/perfetto/discussions/6027
Perfetto RFC-0027https://github.com/google/perfetto/discussions/6027
@pablogsalhttps://github.com/pablogsal
gh-150327: Add Perfetto trace output to profiling.sampling #154541https://github.com/python/cpython/pull/154541
LalitMagantihttps://github.com/LalitMaganti
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on May 23, 2026https://github.com/python/cpython/issues/150327#event-25890621576
https://github.com/LalitMaganti
LalitMagantihttps://github.com/LalitMaganti
on May 24, 2026https://github.com/python/cpython/issues/150327#issuecomment-4527174959
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on May 24, 2026https://github.com/python/cpython/issues/150327#issuecomment-4527464019
StanFromIrelandhttps://github.com/StanFromIreland
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-profilinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-profiling%22
on May 24, 2026https://github.com/python/cpython/issues/150327#event-25895404190
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on May 24, 2026https://github.com/python/cpython/issues/150327#issuecomment-4528012925
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on May 25, 2026https://github.com/python/cpython/issues/150327#issuecomment-4536423073
@ivonastojanovichttps://github.com/ivonastojanovic
@pablogsalhttps://github.com/pablogsal
https://github.com/lkollar
lkollarhttps://github.com/lkollar
on May 30, 2026https://github.com/python/cpython/issues/150327#issuecomment-4583497792
@pablogsalhttps://github.com/pablogsal
@ivonastojanovichttps://github.com/ivonastojanovic
https://github.com/ivonastojanovic
ivonastojanovichttps://github.com/ivonastojanovic
on May 31, 2026https://github.com/python/cpython/issues/150327#issuecomment-4587840823
@ivonastojanovichttps://github.com/ivonastojanovic
@pablogsalhttps://github.com/pablogsal
@pablogsalhttps://github.com/pablogsal
@ivonastojanovichttps://github.com/ivonastojanovic
https://github.com/LalitMaganti
LalitMagantihttps://github.com/LalitMaganti
on Jun 13, 2026https://github.com/python/cpython/issues/150327#issuecomment-4698681563
@pablogsalhttps://github.com/pablogsal
https://github.com/pablogsal
pablogsalhttps://github.com/pablogsal
on Jun 15, 2026https://github.com/python/cpython/issues/150327#issuecomment-4709873149
@LalitMagantihttps://github.com/LalitMaganti
https://github.com/LalitMaganti
LalitMagantihttps://github.com/LalitMaganti
on Jun 15, 2026https://github.com/python/cpython/issues/150327#issuecomment-4713324441
@LalitMagantihttps://github.com/LalitMaganti
LalitMagantihttps://github.com/LalitMaganti
on Jul 23, 2026https://github.com/python/cpython/issues/150327#event-28386619601
pythongh-150327: Add Perfetto trace output to profiling.samplinghttps://github.com/LalitMaganti/cpython/commit/6d2ea9fd019f2c7d2bf0ee642b3d91609fb10fb8
pythongh-150327https://github.com/python/cpython/issues/150327
6d2ea9fhttps://github.com/LalitMaganti/cpython/commit/6d2ea9fd019f2c7d2bf0ee642b3d91609fb10fb8
pythongh-150327: Add Perfetto trace output to profiling.samplinghttps://github.com/LalitMaganti/cpython/commit/bf341e77a73cbba1495363c1ecbaeef30eef869d
pythongh-150327https://github.com/python/cpython/issues/150327
bf341e7https://github.com/LalitMaganti/cpython/commit/bf341e77a73cbba1495363c1ecbaeef30eef869d
https://github.com/LalitMaganti
LalitMagantihttps://github.com/LalitMaganti
on Jul 23, 2026https://github.com/python/cpython/issues/150327#issuecomment-5059531521
#154541https://github.com/python/cpython/pull/154541
LalitMagantihttps://github.com/LalitMaganti
on Jul 23, 2026https://github.com/python/cpython/issues/150327#event-28387868992
pythongh-150327: Add Perfetto trace output to profiling.samplinghttps://github.com/LalitMaganti/cpython/commit/f3d18ff315891e82e0b10d7ecca76b799fe3f95d
pythongh-150327https://github.com/python/cpython/issues/150327
f3d18ffhttps://github.com/LalitMaganti/cpython/commit/f3d18ff315891e82e0b10d7ecca76b799fe3f95d
pythongh-150327: Add Perfetto trace output to profiling.samplinghttps://github.com/LalitMaganti/cpython/commit/1d27b2c78707d41a174b3dafa0c961c93d663088
pythongh-150327https://github.com/python/cpython/issues/150327
1d27b2chttps://github.com/LalitMaganti/cpython/commit/1d27b2c78707d41a174b3dafa0c961c93d663088
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on Jul 23, 2026https://github.com/python/cpython/issues/150327#issuecomment-5061477829
#154105https://github.com/python/cpython/pull/154105
#154101https://github.com/python/cpython/pull/154101
#154105 (review)https://github.com/python/cpython/pull/154105#pullrequestreview-4733813929
cpython/Lib/profiling/sampling/gecko_collector.pyhttps://github.com/python/cpython/blob/66e313f471516bfa04c5c8966c159fafe6be082e/Lib/profiling/sampling/gecko_collector.py#L408
66e313fhttps://github.com/python/cpython/commit/66e313f471516bfa04c5c8966c159fafe6be082e
cpython/Lib/profiling/sampling/gecko_collector.pyhttps://github.com/python/cpython/blob/66e313f471516bfa04c5c8966c159fafe6be082e/Lib/profiling/sampling/gecko_collector.py#L827-L830
66e313fhttps://github.com/python/cpython/commit/66e313f471516bfa04c5c8966c159fafe6be082e
cpython/Lib/profiling/sampling/gecko_collector.pyhttps://github.com/python/cpython/blob/66e313f471516bfa04c5c8966c159fafe6be082e/Lib/profiling/sampling/gecko_collector.py#L838-L839
66e313fhttps://github.com/python/cpython/commit/66e313f471516bfa04c5c8966c159fafe6be082e
cpython/Lib/profiling/sampling/heatmap_collector.pyhttps://github.com/python/cpython/blob/66e313f471516bfa04c5c8966c159fafe6be082e/Lib/profiling/sampling/heatmap_collector.py#L404-L406
66e313fhttps://github.com/python/cpython/commit/66e313f471516bfa04c5c8966c159fafe6be082e
cpython/Lib/profiling/sampling/stack_collector.pyhttps://github.com/python/cpython/blob/66e313f471516bfa04c5c8966c159fafe6be082e/Lib/profiling/sampling/stack_collector.py#L449
66e313fhttps://github.com/python/cpython/commit/66e313f471516bfa04c5c8966c159fafe6be082e
LalitMagantihttps://github.com/LalitMaganti
on Oct 31, 2026https://github.com/python/cpython/issues/150327#event-34759944813
pythongh-150327: End Perfetto opcode slices when the opcode goes awayhttps://github.com/LalitMaganti/cpython/commit/67229b1f3b5c999be30e8d4621b56418f3dad25c
pythongh-150327https://github.com/python/cpython/issues/150327
67229b1https://github.com/LalitMaganti/cpython/commit/67229b1f3b5c999be30e8d4621b56418f3dad25c
pythongh-150327: Clear Perfetto incremental state before any other pa…https://github.com/LalitMaganti/cpython/commit/4dc716a458073ea168c3be5a5a847562966d26a6
pythongh-150327https://github.com/python/cpython/issues/150327
4dc716ahttps://github.com/LalitMaganti/cpython/commit/4dc716a458073ea168c3be5a5a847562966d26a6
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/150327
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/150327
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-profilinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-profiling%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.