@@ -15,7 +15,8 @@ import (
15
15
)
16
16
17
17
func main () {
18
- cpuprofile := flag .String ("cpuprofile" , "" , "write cpu profile to file" )
18
+ cpuProfile := flag .String ("cpuprofile" , "" , "write cpu profile to file" )
19
+ memProfile := flag .String ("memprofile" , "" , "write mem profile to file" )
19
20
20
21
showMemStats := flag .Bool (
21
22
"show-mem-stats" ,
@@ -30,15 +31,23 @@ func main() {
30
31
}
31
32
32
33
var cpuProfOut io.Writer
33
- if * cpuprofile != "" {
34
+ if * cpuProfile != "" {
34
35
var err error
35
- if cpuProfOut , err = os .Create (* cpuprofile ); err != nil {
36
+ if cpuProfOut , err = os .Create (* cpuProfile ); err != nil {
36
37
fmt .Fprint (os .Stderr , errors .Wrap (err , "create cpu profile output file" ).Error ())
37
38
os .Exit (1 )
38
39
}
39
40
}
40
41
41
- if err := summarize (os .Stdin , os .Stdout , memStatsOut , cpuProfOut ); err != nil {
42
+ var memProfOut io.WriteCloser
43
+ if * memProfile != "" {
44
+ var err error
45
+ if memProfOut , err = os .Create (* memProfile ); err != nil {
46
+ fmt .Fprint (os .Stderr , errors .Wrap (err , "create mem profile output file" ).Error ())
47
+ }
48
+ }
49
+
50
+ if err := summarize (os .Stdin , os .Stdout , memStatsOut , cpuProfOut , memProfOut ); err != nil {
42
51
fmt .Fprintf (os .Stderr , "summarize: %s\n " , err .Error ())
43
52
os .Exit (1 )
44
53
}
@@ -47,6 +56,7 @@ func main() {
47
56
func summarize (
48
57
in io.Reader ,
49
58
out , memStatsOut , cpuProfOut io.Writer ,
59
+ memProfOut io.WriteCloser ,
50
60
) error {
51
61
if cpuProfOut != nil {
52
62
if err := pprof .StartCPUProfile (cpuProfOut ); err != nil {
@@ -68,6 +78,15 @@ func summarize(
68
78
}
69
79
}
70
80
81
+ if memProfOut != nil {
82
+ if err := pprof .WriteHeapProfile (memProfOut ); err != nil {
83
+ return errors .Wrap (err , "write mem profile" )
84
+ }
85
+ if err := memProfOut .Close (); err != nil {
86
+ return errors .Wrap (err , "close mem profile" )
87
+ }
88
+ }
89
+
71
90
if memStatsOut != nil {
72
91
numInternalNodes , numLeafNodes , internalNodesTotalSize , leafNodesTotalSize := rs .MemUsage ()
73
92
fmt .Fprintf (memStatsOut ,
0 commit comments