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"?
关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率

首页/
已采纳
有没有人在go可执行文件上使用简单的pprof?
收起
- 写回答
- 好问题 0 提建议
- 关注问题
微信扫一扫
点击复制链接分享
- 邀请回答
- 编辑 收藏 删除 结题
- 收藏 举报
1条回答 默认 最新
- 关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率
doucan9079 2014-05-01 16: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.
本回答被题主选为最佳回答 , 对您是否有帮助呢? 本回答被专家选为最佳回答 , 对您是否有帮助呢? 本回答被题主和专家选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏举报微信扫一扫
点击复制链接分享
编辑预览轻敲空格完成输入- 显示为
- 卡片
- 标题
- 链接
评论按下Enter换行,Ctrl+Enter发表内容
编辑
预览

轻敲空格完成输入
- 显示为
- 卡片
- 标题
- 链接
报告相同问题?
提交
- 2022-05-19 09:17回答 2 已采纳 我解决了,用.reg注册表自定义协议,自定义协议的参数是任意可执行文件的地址,协议会将地址交给bat执行,地址作为参数,bat中将url编码的地址转成正常地址然后执行就行了。
- 2019-01-09 22:21回答 2 已采纳 The short answer: Kind of? It sounds like what you're trying to accomplish is a shared library.
- 2022-07-29 07:56回答 4 已采纳 使用flyway去管理数据库版本吧,编写好变更脚本,自动更新另外注意各个环境的数据库版本和配置是否一致
- 2021-06-04 08:55恋喵大鲤鱼的博客 有时,我们开发的 Golang 程序会出现 CPU 使用率达到 100%,内存使用量过大,死锁等问题,我们该如何定位上诉问题的具体位置,来解决程序的到性能问题呢?Go 是一个非常注重性能的语言,语言内置了里性能分析库 ...
- 2014-02-12 11:46回答 1 已采纳 You can either use MIME type guessing using mime.TypeByExtension or http.DetectContentType from th
- 2022-07-28 11:45回答 1 已采纳 命令行中用ll查看一下这个文件有没有x权限,有的话命令行./vim... 执行
- 2020-02-20 03:12回答 2 已采纳 自己动手,丰衣足食。
- 2022-12-22 02:46试剑江湖。的博客 Go 在语言层面上集成了 profile 采样工具,只需在代码中简单地引入runtime/pprof或者net/http/pprof包,即可获取程序的 profile 文件,并通过 profile 文件来进行性能分析。net/http/pprof基于runtime/pprof包进行...
- 2021-09-09 08:21回答 1 已采纳 你看一下你的程序是否能正确运行。
- 2023-01-12 07:28回答 2 已采纳 重装下Pycharm,换成2022.X版本的试试
- 2020-12-27 08:05姚雨言的博客 (给Go开发大全加星标)来源:wudaijunhttps://wudaijun.com/2018/04/go-pprof/【导读】pprof是golang用于性能分析的工具、可以生成图形和文本报告。在实际项目中对高并发场景下的服务上线前必须经过pprof验证,本文...
- 2023-03-24 10:09蓝胖子的编程梦的博客 平时在使用prometheus对应用服务进行监控时,我们主要还是采用埋点的方式,同样,go runtime内部也是采用这样的方式对代码运行过程中的各种事件进行埋点,最后读取 整理后的埋点数据,形成我们在网页上看的trace监控...
- 2020-08-06 08:31cumian8165的博客 pprof 内存泄漏by Jonathan Levison ... 我如何在大型代码库上使用pprof调查Go中的内存泄漏 (How I investigated memory leaks in Go using pprof on a large codebase) I have been working with Go for the better...
- 2020-04-16 09:47djqueue的博客 当你在leetcode做完一道题的时候,你一定不会满足于只是通过,而是还希望你的代码至少击败90%+的人。 然鹅,像我这样的算法渣渣,提交完往往是这样的。。。 之前用C++做题的时候,遇到这种情况,我都是到提交...
- 没有解决我的问题, 去提问
联系我们(工作时间:8:30-22:00)
400-660-0108kefu@csdn.net在线客服
- 京ICP备19004658号
- 经营性网站备案信息
公安备案号11010502030143
- 营业执照
- 北京互联网违法和不良信息举报中心
- 家长监护
- 中国互联网举报中心
- 网络110报警服务
- Chrome商店下载
- 账号管理规范
- 版权与免责声明
- 版权申诉
- 出版物许可证
- ©1999-2025北京创新乐知网络技术有限公司