20

I am trying to use pprof on my program, however, I have slightly different results from articles I read (links below). In my results, I am getting such table:

(pprof) top10
1.65s of 1.72s total (95.93%)
Showing top 10 nodes out of 114 (cum >= 0.01s)
      flat  flat%   sum%        cum   cum%
     1.19s 69.19% 69.19%      1.20s 69.77%  syscall.Syscall
     0.16s  9.30% 78.49%      0.16s  9.30%  runtime._ExternalCode

what are this columns: flat flat% sum% cum cum%?

Articles I was reading: https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs http://blog.golang.org/profiling-go-programs

Sławosz
  • 11,187
  • 15
  • 73
  • 106
  • 3
    The format is a little different, but the data and columns still have the same meaning. 'flat' is the time in a function, 'cum' is the cumulative time is a function and everything below it. – JimB Sep 14 '15 at 18:53
  • Do you mind to change your title to `What does flat, flat%, sum%, cum, cum% mean in Golang pprof results?` – Ryan Lyu Jul 04 '19 at 06:52
  • I think it maybe easier to reach when people search this kind of question. – Ryan Lyu Jul 04 '19 at 06:53

2 Answers2

40

flat and cum

Assuming there is a function foo, which is composed of 3 functions and a direct operation.

func foo(){
    a()                                 step1
    b()                                 step2
    do something directly.              step3
    c()                                 step4
}

Imagine when you call function foo, it takes 6 seconds, and the time distribution are following.

func foo(){
    a()                                 // step1 takes 1s
    b()                                 // step2 takes 1s
    do something directly.              // step3 takes 3s
    c()                                 // step4 takes 1s
}
  • flat would be the time spent on step3.
  • cum would be the total execution time of foo, which contains sub-function call and direct operations. (cum = step1+ step2+ step3+ step4)

sum%

when you run top in pprof console, each line of output stands for the time spent on specific function. Sum% means how much time/memory has been spent by previous lines.

To explain this metric, I pick another example which contains more lines. the value of sum% for forth line is 45.17%. it's the calculated in this way:

line1 19.33%
line2 13.27%
line3 6.60%
line4 5.97%
-----------
sum% 45.17%

enter image description here

Application of sum%

sum% could help you to identify the big rocks quickly. The following is another example of memory allocation report.

You can see that the first four functions consume 91.06% memory. If I want to do some performance tuning, I should focus on first four functions. All the functions below fourth could be ignored.

enter image description here

Reference

Reddit: What is the meaning of "flat" and "cum" in golang pprof output

Ryan Lyu
  • 4,180
  • 5
  • 35
  • 51
2

I know I'm going to get flack for this, but take a look at the GopherCon talks; one such example on interpretation is here, there is also a talk from Uber about pprof as well.

There is also Profiling Go Programs blog post.