Java Package Flame Graph

轉(zhuǎn)自:http://www.brendangregg.com/blog/2017-06-30/package-flame-graph.html

Java Package Flame Graph
30 Jun 2017
CPU flame graphs visualize running code based on its flow or stack trace ancestry, showing which functions called which other functions and so on. But with Java, there's another way to visualize the same CPU workload which provides some additional insight: a Java package flame graph. Instead of visualizing the stack trace hierarchy, this visualizes the Java package name hierarchy. I'll explain with a quick example.
Here is a normal stack trace-based CPU flame graph for Java, running a microbenchmark (SVG):

The y-axis is stack depth. From bottom to top are parent to child functions, and the top edge shows the functions running on CPU.
These flame graphs answer many questions easily, such as where the bulk of the CPU time is spent, with ancestry and child functions. But there's one line of questioning that's still tricky: How much CPU time is spent in java/util/*
for example? The Search button (top right) lets you answer this by searching on "java/util", and the bottom right will show 4.3%. But this includes child functions (on purpose). How much CPU time was in java/util methods directly, excluding child functions calls? That takes a bit of effort to figure out, involving zooming on each call and excluding child calls manually. A package flame graph can help here.
Now for a Java package flame graph for the same workload, also showing CPU samples (SVG):

The y-axis now spans the package name. Click to navigate. This visualizes the on-CPU functions only, so function ancestry is excluded. The time in java/util is grouped together, which can be identified visually: it's 3.91% (it should be less than the earlier flame graph, as it excludes child calls; however, this is also a separate profile and the workload may have varied). There seems to be a grass of many thin rectangles: these are not Java methods, and so don't have a package name to spilt.
Is this package flame graph better than the normal stack trace flame graph? Definitely not. I use it in addition, as a different perspective for understanding the same CPU workload.
Here's how you can make a package flame graph, using the software from my FlameGraph repository:

perf record -F 99 -a -- sleep 30; ./jmaps# perf script | ./pkgsplit-perf.pl | grep java | ./flamegraph.pl > out.svg

Notice something? I'm not using -g
with perf record
, like I normally do, so this is not collecting stack traces. That means that this type of profiling has lower overhead, which is a bonus. It also means that Java doesn't need to be running with -XX:+PreserveFramePointer, although you probably still want to so that you can collect the normal (stack trace) flame graphs.
Also, some workloads can bust perf's 127 stack frame limit (tunable in Linux 4.8 onwards), which can badly mess up a normal flame graph to the point where it's unreadable. The package name flame graph will work fine in this situation.
I introduced Java package flame graphs in my JavaOne talk last year, and was just using them again to find some extra clues. I hope they are useful for you too.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 杏花紅, 杏花白, 村姑村妮胭脂濃。 杏花白, 杏花紅, 粉墨登場似雪叢。 杏花開, 杏花艷, 唐汪川里春潮涌。
    宗林的李閱讀 547評論 4 5
  • 其實(shí)我越來越不敢寫,比我優(yōu)秀的人有太多,我只是這蕓蕓眾生中不起眼的一員,沒有資格給他人建議和實(shí)用的生活技巧。幸運(yùn)的...
    OptiMisTic馮閱讀 586評論 0 0
  • 投稿專區(qū):接龍客棧-懸賞任務(wù)[接龍客棧]懸賞任務(wù)十一月榜單懸賞任務(wù)04【說書人】 文丨薔薇下的陽光 接龍客棧江湖情...
    薔薇下的陽光閱讀 965評論 15 10
  • 自我介紹應(yīng)該是什么樣的,開篇總是姓甚名誰,性別年齡,是哪里人,做著什么樣的工作吧。然而,這些可以描繪我們是什么樣的...
    青山應(yīng)如是212閱讀 311評論 1 1
  • 01 周末看《妻子的浪漫旅行》四位妻子們坐一桌說話,謝娜說:“像我這樣的女人,我其實(shí)是看杰哥臉色行事的人。” “我...
    江曉夏閱讀 220評論 0 6