python / python/cpython

Tachyon’s `--diff-flamegraph` scales times in baseline run to duration of current run

Open
#154,062 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug report

Bug description:

As discussed with @pablogsal during EuroPython sprints:

Using this simple example script (flamegraph_demo.py):

import time

def main():
    f_1()
    f_2()

def f_1():
    time.sleep(0.5)  # change this to 1.5 in the second run

def f_2():
    time.sleep(1)

main()
python -m profiling.sampling run --binary -o baseline.bin flamegraph_demo.py
vim flamegraph_demo.py  # edit f_1 to sleep for 1.5 s
python -m profiling.sampling run --diff-flamegraph baseline.bin -o diff.html flamegraph_demo.py

generates this diff flamegraph:

Image

f_2 is unchanged between both runs, so the “Baseline Self” time should be equal to the “Current Self” and equal to 1 s (that it displays “1 ms” is covered in #154059); however, the baseline for all functions gets scaled with the ratio of total time in this run over total time of the previous run (in this case: 2.5 s / 1.5 s = 1.667).

I can imagine scenarios where this scaling is useful (e.g. when the baseline is generated on a different machine). However, in the common case of running baseline and diff on the same machine, this scaling means that a lot of unchanged functions get colour-coded, which distracts from the few functions that experienced a meaningful change.

CPython versions tested on:

3.15

Operating systems tested on:

macOS

Linked PRs
  • gh-154082

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 with the profiling.sampling entry point and reproduce the commands using flamegraph_demo.py, comparing baseline.bin with diff.html. Trace how --diff-flamegraph scales baseline times and verify that unchanged f_2 shows equal 1 s baseline and current self times without unnecessary color changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.