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 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动