关于后端:pprof新增的火焰图实现

7次阅读

共计 3138 个字符,预计需要花费 8 分钟才能阅读完成。

最近用 pprof,发现新增了一个选项

相应门路为 flamegraph2

寻根究底,这个改变是在 2022 年 11 月底被引入(正文了 ” 实验性的 ”),随 2023 年 2 月初的 Go 1.20 版本公布。不过查看了 Go 1.20 Release Notes,如同并没有提及此处改变。

这里用的库是 github.com/google/pprof,查看了这个我的项目的改变

是在 2022 年 8 月中旬,commit 信息为:

Added alternative flamegraph implementation that can show callers. (#716)

Add an experimental flame-graph implementation. It can be selected in
pprof's web interface using the new"Flame (experimental)" menu entry.
At some point this new implementation may become the default.

The new view is similar to flame-graph view. But it can show caller
information as well. This should allow it to satisfy many users of
Graph and Peek views as well.

Let's illustrate with an example. Suppose we have profile data that
consists of the following stacks:

1000 main -> foo -> malloc
2000 main -> bar -> malloc


When main is selected, both the old and new views show:

[——————-3000 main———————]
[—1000 foo—–] [———-2000 bar————]
[—1000 malloc–] [———-2000 malloc———]


But suppose now the user selects the right-most malloc slot.
The old view will show just the path leading to that malloc:

[———-2000 main———–]
[———-2000 bar————]
[———-2000 malloc———]


The new view will however show a flame-graph view that grows
upwards that displays the call stacks leading to malloc:

[—1000 main—-] [———-2000 main———–]
[—1000 foo—–] [———-2000 bar————]
[——————-3000 malloc——————-]


This caller display is useful when trying to determine expensive
callers of function.

A list of important differences between the new view and flame graphs:

New view pros:

1.  Callers are shown, e.g., all paths leading to malloc.
2.  Shows self-cost clearly with a different saturation.
3.  Font size is adjusted to fit more text into boxes.
4.  Highlighting on hover shows other occurrences of a function.
5.  Search works more like other views.
6.  Pivot changes are reflected in browser history (so back and forward
    buttons can be used to navigate between different selections).
7.  Allows eventual removal of the D3 dependency, which may make
    integrations into various environments easier.
8.  Colors provide higher contrast between foreground and background.

New view cons:

1.  There are small differences in how things look and feel.
2.  Color-scheme is very different.
3.  Change triggered by selecting a new entry is not animated.

以下内容来自 ChatGPT:

在这个提交中,增加了一个实验性的火焰图(flame graph)实现。能够通过 pprof 的 Web 界面抉择新的 ”Flame (experimental)” 菜单项来查看。在某个时刻,这个新实现可能会成为默认选项。

这个新视图相似于火焰图视图,然而它能够显示调用者信息。这样能够满足许多应用 Graph 和 Peek 视图的用户的需要。

让咱们通过一个例子来阐明。假如咱们有以下堆栈的性能数据:

1000    main -> foo -> malloc
2000    main -> bar -> malloc

当抉择 main 时,旧视图和新视图都会显示:

[-------------------3000 main---------------------]
[---1000 foo-----] [----------2000 bar------------]
[---1000 malloc--] [----------2000 malloc---------]

然而,假如当初用户抉择最左边的 malloc 槽。旧视图将只显示通往该 malloc 的门路:

[----------2000 main-----------]
[----------2000 bar------------]
[----------2000 malloc---------]

然而,新视图将显示一个火焰图视图,从下往上展现通往 malloc 的调用堆栈:

[---1000 main----] [----------2000 main-----------]
[---1000 foo-----] [----------2000 bar------------]
[-------------------3000 malloc-------------------]

这个调用者显示在确定函数的开销较大时十分有用。

新视图和火焰图之间的一些重要区别如下:

新视图的劣势:

  1. 显示调用者,例如,所有通往 malloc 的门路。
  2. 应用不同的色彩饱和度分明地显示本身开销。
  3. 字体大小调整以在方框中显示更多文本。
  4. 悬停时的高亮显示显示函数的其余呈现。
  5. 搜寻性能的工作形式更像其余视图。
  6. 值轴更改会在浏览器历史中反映进去(因而能够应用后退和后退按钮在不同的抉择之间导航)。
  7. 容许最终删除 D3 依赖项,这可能使集成到各种环境中变得更容易。
  8. 色彩提供前景和背景之间更高的对比度。

新视图的毛病:

  1. 外观和感觉上有些渺小的差别。
  2. 色彩计划有很大的不同。
  3. 抉择新条目触发的更改没有动画成果。

本文由 mdnice 多平台公布

正文完
 0