douchuose2514 2016-03-08 06:36
浏览 96


I have built a web server and did an ab(apache benchmark) test. Now I want to know the computing time of each part.

I used the go tool pprof url:port/xxx and get the profile of this program, but it does not tell me the computing time(only has memory). Following is the results:

(pprof) top10
1827.59MB of 1978.12MB total (92.39%)
Dropped 175 nodes (cum <= 9.89MB)
Showing top 10 nodes out of 48 (cum >= 43.50MB)
  flat  flat%   sum%        cum   cum%
  769.54MB 38.90% 38.90%   769.54MB 38.90%  reflect.unsafe_New
  459.08MB 23.21% 62.11%   459.08MB 23.21%  services/semanticnew.TopicProbCounter.Update
  189.17MB  9.56% 71.67%  1081.21MB 54.66%*Buffer).dec_slice_struct
  122MB  6.17% 77.84%      122MB  6.17%*Buffer).dec_int32
  107.56MB  5.44% 83.28%   107.56MB  5.44%*conn).readReply
  68.13MB  3.44% 86.72%   527.21MB 26.65%  services/semanticnew.caculApPoiScore

  40.51MB  2.05% 88.77%    40.51MB  2.05%  runtime.malg
  28.59MB  1.45% 90.22%    28.59MB  1.45%  net/http.newBufioWriterSize
  22.50MB  1.14% 91.35%       23MB  1.16%  redismanage.(*Manager).getRequest
  20.50MB  1.04% 92.39%    43.50MB  2.20%  redismanage.(*Manager).GetRequest

In my web program, I have added the following code:

f, _ := os.Create("x.cpuprofile")
defer pprof.StopCPUProfile()

but it still does not work.

I have checked, but the file confused me. How can I generate this file? And the author used go tool pprof xxx, does it mean that xxx is the binary file which generated by xxx.go?

Anyway, the target is getting the computing time, but how? Do I have to generate this file to achieve this goal?

Many thanks

  • 写回答

1条回答 默认 最新

  • doubei8168 2016-03-08 14:45

    I've had success using Dmitry's advice from here:

    You merely need to import net/http/pprof, and collect profiles with:

    $ go tool pprof --text mybin http://myserver:6060:/debug/pprof/profile

    The net/http/pprof is imported solely for its side effects, so you can use

    import (
       _ "net/http/pprof"

    Aside from "mybin" and "myserver" you also need to substitute your port number in and remove the trailing colons after the port number. E.g. for my pet project, the command is

    go tool pprof

    You'll then get a pprof archive created which you can explore interactively through pprof, or you can use an external tool - personally I prefer the built-in capabilities.

    Note that and are existing problems with the combination of pprof and some kernels.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 韩国网站购物,KG支付的支付回调如何解决
  • ¥15 workstation导入ovf文件,报错,怎么解决呢?
  • ¥15 关于#c语言#的问题:构成555单稳态触发器,采用LED指示灯延时时间,对延时时间进行测量并显示(如楼道声控延时灯)需要Proteus仿真图和C语言代码
  • ¥50 神舟笔记本,没有linux的驱动,装的Ubuntu系统,想把风扇速度调到最大
  • ¥15 workstation加载centos进入emergency模式,查看日志报警如图,怎样解决呢?
  • ¥50 如何用单纯形法寻优不能精准找不到给定的参数,并联机构误差识别,给定误差有7个?matlab
  • ¥15 workstation加载centos进入emergency模式,查看日志报警如图,没有XFS,怎样解决呢?
  • ¥15 应用商店如何检测在架应用内容是否违规?
  • ¥15 Ubuntu系统配置PX4
  • ¥50 nw.js调用activex