python / python/cpython

API for outputting different formats from CPython sampling profiler

Open
#138,383 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance stdlib topic-profiling type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

CPython 3.15 has statistical sampling profiler which currently only supports outputting

  1. pstats https://docs.python.org/3.15/library/profile.html#pstats.Stats
  2. collapsed format for flamegraphs https://github.com/python/cpython/blob/8d5c3341c538cd1a4192ca8a1536b2eed4b98c69/Lib/profiling/sampling/stack_collector.py#L24

Since it's still an early stage for the sampling profiler, I thought it would be nice to initiate discussion around how to support multiple different formats from the profiler.

  1. pprof
  2. OTel

are the formats that could potentially be added, but supporting those from CPython would introduce dependencies that might complicate building/testing and distributing CPython.

I'd like to suggest that CPython has an interface to support 3rd party collectors. What do you think?

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/pre-pep-api-for-outputting-different-formats-from-cpython-sampling-profiler/103490

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Lib/profiling/sampling/stack_collector.py and the existing pstats and collapsed-format handling referenced in the issue. Review the linked Discourse discussion before proposing an interface for third-party collectors; done would require an agreed API, supported format boundaries, and a plan for CPython build, testing, and distribution constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.