dpba63888 2017-02-23 03:53
浏览 99
已采纳

Go Profiler(PPROF)时序差异

When I measure the run time of my Go program with Linux's time utility, I get the following output:

real    1m9.177s
user    7m1.788s
sys     0m39.016s

When I look at the output of the same exact program execution in Go's pprof CPU profiler, I get the following output:

Entering interactive mode (type "help" for commands)
(pprof) top
143.32s of 176s total (81.43%)

Where is the pprof getting this 176s figure from? It is neither the clock time nor the CPU time. I am running this program with GOMAXPROCS set to 8, and I have a feeling this has something to do with it. How exactly does pprof measure run time, and why is it different from linux's time?

  • 写回答

2条回答 默认 最新

  • doolo00026 2017-02-23 06:48
    关注

    The time utility and the pprof tool operate in different ways and should be used in different ways. Don't try to reconcile them. time measures near exact times for the program; pprof measures relative times for functions and methods. pprof is an intrusive statistical sample. When CPU profiling is enabled, the Go program stops about 100 times per second and records a sample consisting of the program counters on the currently executing goroutine's stack. Sampling has a cost and the results are estimates of the actual population.

    Use time to measure the overall actual CPU time for the program, that is absolute time. Use pprof to estimate where most of the time was spent in the functions and methods using relative time percentages. pprof identifies the bottlenecks. For actual CPU times, use Go testing package benchmarks.

    For an example, see Profiling Go Programs:

    By using Go's profiling tools to identify and correct specific bottlenecks, we can make the Go loop finding program run an order of magnitude faster and use 6x less memory.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog