File tree Expand file tree Collapse file tree 4 files changed +2842
-0
lines changed
Expand file tree Collapse file tree 4 files changed +2842
-0
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,19 @@ package struc
33import (
44 "bytes"
55 "encoding/binary"
6+ "net/http"
7+ _ "net/http/pprof"
68 "testing"
79)
810
11+ func init () {
12+ // 启动 pprof http 服务
13+ go func () {
14+ println ("Starting pprof server on :6060" )
15+ println (http .ListenAndServe ("localhost:6060" , nil ))
16+ }()
17+ }
18+
919type BenchExample struct {
1020 Test [5 ]byte
1121 A int32
Original file line number Diff line number Diff line change 1+
2+ # 运行解码基准测试
3+ go test -bench=Decode -benchmem -cpuprofile=cpu_decode.prof -memprofile=mem_decode.prof -trace=trace_decode.out
4+
5+ # 运行编码基准测试
6+ go test -bench=Encode -benchmem -cpuprofile=cpu_encode.prof -memprofile=mem_encode.prof -trace=trace_encode.out
7+
8+ # 查看基准测试结果
9+ go tool pprof -http=:8080 cpu_decode.prof
10+ go tool pprof -http=:8080 mem_decode.prof
11+ go tool trace trace_decode.out
12+
13+ go tool pprof -http=:8080 cpu_encode.prof
14+ go tool pprof -http=:8080 mem_encode.prof
15+ go tool trace trace_encode.out
16+
17+ # 转换为svg
18+ go tool pprof -svg cpu_decode.prof > cpu_decode.svg
19+ go tool pprof -svg mem_decode.prof > mem_decode.svg
20+ go tool pprof -svg cpu_encode.prof > cpu_encode.svg
21+ go tool pprof -svg mem_encode.prof > mem_encode.svg
22+
23+
24+ # 查看trace
25+ go tool trace trace_decode.out
26+ go tool trace trace_encode.out
27+
28+ # 查看 text
29+ go tool pprof -text cpu_decode.prof
30+ go tool pprof -text mem_decode.prof
31+ go tool pprof -text cpu_encode.prof
32+ go tool pprof -text mem_encode.prof
You can’t perform that action at this time.
0 commit comments