Title: pprof 使用 · Issue #126 · codcodog/Blog · GitHub
Open Graph Title: pprof 使用 · Issue #126 · codcodog/Blog
X Title: pprof 使用 · Issue #126 · codcodog/Blog
Description: pprof 基本使用 查看堆栈调用信息 $ go tool pprof http://localhost:6060/debug/pprof/heap 查看协程信息 $ go tool pprof http://localhost:6060/debug/pprof/goroutine 查看30s内的 CPU 信息 $ go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30 其他 $ go too...
Open Graph Description: pprof 基本使用 查看堆栈调用信息 $ go tool pprof http://localhost:6060/debug/pprof/heap 查看协程信息 $ go tool pprof http://localhost:6060/debug/pprof/goroutine 查看30s内的 CPU 信息 $ go tool pprof http://localhost:6060/de...
X Description: pprof 基本使用 查看堆栈调用信息 $ go tool pprof http://localhost:6060/debug/pprof/heap 查看协程信息 $ go tool pprof http://localhost:6060/debug/pprof/goroutine 查看30s内的 CPU 信息 $ go tool pprof http://localhost:6060/de...
Opengraph URL: https://github.com/codcodog/Blog/issues/126
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"pprof 使用","articleBody":"pprof\r\n======\r\n\r\n\r\n### 基本使用\r\n\r\n查看堆栈调用信息\r\n```bash\r\n$ go tool pprof http://localhost:6060/debug/pprof/heap\r\n```\r\n\r\n查看协程信息\r\n```bash\r\n$ go tool pprof http://localhost:6060/debug/pprof/goroutine\r\n```\r\n\r\n查看30s内的 CPU 信息\r\n```bash\r\n$ go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30\r\n```\r\n\r\n其他\r\n```bash\r\n$ go tool pprof http://localhost:6060/debug/pprof/threadcreate\r\n\r\n$ go tool pprof http://localhost:6060/debug/pprof/block\r\n\r\n$ go tool pprof http://localhost:6060/debug/pprof/mutex\r\n\r\n$ go tool pprof http://localhost:6060/debug/pprof/trace?seconds=5\r\n```\r\n\r\n### 扩展使用\r\n排查 `golang` 程序内存泄露.\r\n\r\n获取 A 时间点的堆栈 profile\r\n```bash\r\n$ curl -s http://localhost:6060/debug/pprof/heap \u003e A.heap\r\n```\r\n\r\n过一段时间后,内存开始泄露了,再获取 B 时间点的堆栈 profile\r\n```bash\r\n$ curl -s http://localhost:6060/debug/pprof/heap \u003e B.heap\r\n```\r\n\r\n比较 A, B 时间点的堆栈差异\r\n```bash\r\n$ go tool pprof --base A.heap B.heap\r\n```\r\n\r\n使用 `web` 命令生成一个 SVG 文件\r\n```bash\r\n(pprof) web\r\n```\r\n\r\n或者直接打开 web 界面\r\n```\r\n$ go tool pprof --http :9090 --base B.heap A.heap\r\n```\r\n\r\n\u003e 生成图表,需要安装 [Graphviz](https://graphviz.org/)\r\n\r\n### 参考\r\n[Profiling Go programs with pprof](https://jvns.ca/blog/2017/09/24/profiling-go-with-pprof/)\r\n[Hi, 使用多年的go pprof检查内存泄漏的方法居然是错的](https://colobu.com/2019/08/20/use-pprof-to-compare-go-memory-usage/) \r\n\r\n","author":{"url":"https://github.com/codcodog","@type":"Person","name":"codcodog"},"datePublished":"2021-03-02T14:11:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/126/Blog/issues/126"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:761ca313-b514-7851-90e2-cd88ba5448a2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C06:2FB15B:473FF0:60E807:6A4C2F14 |
| html-safe-nonce | ae972677635bac8e3a470141a2ca709ff5383498bcc62a9cd74129ded2863c8e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzA2OjJGQjE1Qjo0NzNGRjA6NjBFODA3OjZBNEMyRjE0IiwidmlzaXRvcl9pZCI6Ijg0NTM0MjExMDI2ODQ0NTA1ODAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1b04840f0ac10042ef563461651252fd06b1a3a81d1207979a2296444af983ba |
| hovercard-subject-tag | issue:820056017 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/codcodog/Blog/126/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d58afbb836f07adc90b4eef963410463fae8a844eb894fe8847687da93ddacd2/codcodog/Blog/issues/126 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d58afbb836f07adc90b4eef963410463fae8a844eb894fe8847687da93ddacd2/codcodog/Blog/issues/126 |
| og:image:alt | pprof 基本使用 查看堆栈调用信息 $ go tool pprof http://localhost:6060/debug/pprof/heap 查看协程信息 $ go tool pprof http://localhost:6060/debug/pprof/goroutine 查看30s内的 CPU 信息 $ go tool pprof http://localhost:6060/de... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | codcodog |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1b6b16d04026f131a36d57e3b01d0f4d26a51800edf48bf5ed0256e0ac905511 |
| turbo-cache-control | no-preview |
| go-import | github.com/codcodog/Blog git https://github.com/codcodog/Blog.git |
| octolytics-dimension-user_id | 18098145 |
| octolytics-dimension-user_login | codcodog |
| octolytics-dimension-repository_id | 75478736 |
| octolytics-dimension-repository_nwo | codcodog/Blog |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 75478736 |
| octolytics-dimension-repository_network_root_nwo | codcodog/Blog |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9ee13484b32cf23e15fde191da4c9aa47d41201c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width