go pprof
87 words
One minute
测试代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
package main
import (
"fmt"
"net/http"
_ "net/http/pprof"
"runtime"
)
func main() {
fmt.Println(runtime.NumCPU())
go http.ListenAndServe("0.0.0.0:6060", nil)
fmt.Println(fib(100))
select {}
}
func fib(n int) int {
if n <= 1 {
return 1
}
return fib(n-1) + fib(n-2)
}
|
火焰图
1
|
go tool pprof -http :8080 profile
|
go test
采集内存
1
|
go test -bench=. -memprofile=mem.prof
|
采集cpu
1
|
go test -bench=. -cpuprofile=cpu.prof
|