相应路径为 flamegraph2
追本溯源,这个改动是在2022年11月底被引入(注释了"实验性的"),随2023年2月初的Go 1.20版本发布。不过查看了 Go 1.20 Release Notes,好像并没有提及此处新feature。
这里用的库是 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-------------------]
这个调用者显示在确定函数的开销较大时非常有用。
新视图和火焰图之间的一些重要区别如下:
新视图的优势:
新视图的缺点:
推荐阅读