doumu6997 2013-09-28 14:14
浏览 46
已采纳

有没有人在go可执行文件上使用简单的pprof?

I have looked at the article about profiling go programs, and I simple do not understand it. Do someone have a simple code example were the performance of code snippet is logged in text file by a profile-"object"?

  • 写回答

1条回答 默认 最新

  • doucan9079 2014-05-02 00:11
    关注

    Here are the commands I use for a simple CPU and memory profiling to get you started.

    Let's say you made a benchmark function like this :

    File something_test.go :

    func BenchmarkProfileMe(b *testing.B) {
     // execute the significant portion of the code you want to profile b.N times
    }
    

    In a shell script:

    # -test XXX is a trick so you don't trigger other tests by asking a non existent specific test called literally XXX
    # you can adapt the benchtime depending on the type of code you want to profile.
    
    go test -v -bench ProfileMe -test.run XXX -cpuprofile cpu.pprof -memprofile mem.pprof -benchtime 10s
    
    go tool pprof --text ./something.test cpu.pprof           ## To get a CPU profile per function
    
    go tool pprof --text ./something.test cpu.pprof --lines   ## To get a CPU profile per line
    
    go tool pprof --text ./something.test mem.pprof           ## To get the memory profile
    

    It will present you the hottests spots in each cases on the console.

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

报告相同问题?

悬赏问题

  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃