python / python/cpython

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

オープン
#154,062 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-profiling type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

profiling.sampling エントリポイントから始め、flamegraph_demo.py を使ってコマンドを再現し、baseline.bin と diff.html を比較します。--diff-flamegraph が baseline の時間をどのようにスケーリングするかを追跡し、変更されていない f_2 について、baseline と current の self time が同じ 1 s であり、不要な色の変更がないことを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
performance
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。