Skip to content

Instantly share code, notes, and snippets.

@lhlyu
Created March 25, 2022 10:33
Show Gist options
  • Save lhlyu/92d5ef2cd45ba61e5bbbbf369fa8ecad to your computer and use it in GitHub Desktop.
Save lhlyu/92d5ef2cd45ba61e5bbbbf369fa8ecad to your computer and use it in GitHub Desktop.
go查找内存泄漏
  • 开启监听
package main

import (
    "net/http"
    _ "net/http/pprof"
)

func main() {
    http.ListenAndServe(":6060", nil)
}
  • 命令行

参考

# 查看内存
go tool pprof -inuse_space http://localhost:6060/debug/pprof/heap
# 查看goroutine
go tool pprof http://localhost:6060/debug/pprof/goroutine
# 下载goroutine详情
wget http://localhost:6060/debug/pprof/goroutine?debug=1 -O debug.html
wget http://localhost:6060/debug/pprof/goroutine?debug=2 -O debug2.html

# pprof内部命令
top
list
traces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment