7

I want to get a sampling profile of my program that includes blocked time (waiting for a network service) as well as CPU time.

perf's default profiling mode (perf record -F 99 -g -- ./binary) samples whole-system running time, but doesn't give a clear indication about how much time my program spends in what parts of my program: it's skewed toward CPU-intensive parts and doesn't show IO-intensive parts at all. The sleep time profiling mode (related on SO) shows sleep times but no general profile.

What I'd like is something really simple: record a call stack of my program every 10ms, no matter whether it's running or currently blocked. Then make a flamegraph out of that.

Community
  • 1
  • 1
Christian Aichinger
  • 6,989
  • 4
  • 40
  • 60
  • [*This might be interesting.*](http://stackoverflow.com/a/27867426/23771) Flamegraphs have two problems. 1) They don't show you bottlenecks that consist of many small calls from multiple places. 2) They are based on the premise that samples need to be frequent and numerous, which is not true. (It's a myth.) That link explains why, and it explains a simple way to get the small number of samples, in a way that shows you both CPU and blocked time. – Mike Dunlavey Nov 20 '15 at 23:35
  • You can use DTrace as discussed in [here](http://www.brendangregg.com/FlameGraphs/offcpuflamegraphs.html) to generate I/O flamegraphs (section 1) and to determine the reason for waiting (section 3). – Hadi Brais Nov 24 '15 at 10:58
  • Look into 'off-cpu' profiling, ie https://stackoverflow.com/questions/23098153/how-to-use-linux-perf-tool-to-generate-off-cpu-profile – Alec Istomin Dec 22 '16 at 21:47
  • 1
    @AlecIstomin: BCC's off-cpu profile seems to include *only* off cpu times. What I'd be interested in would be a wall-clock-type profile that includes both CPU and off-CPU time for each thread in my program. Or am I misunderstanding something? – Christian Aichinger Dec 26 '16 at 10:28
  • Not sure if flamegraph is a good way for that.. Maybe try strace? You can select specific events to show on execution timeline. – Alec Istomin Dec 26 '16 at 19:11

0 Answers0