Pprof和Golang-如何解释结果?

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

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.

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