add command line option for memory profiling
This commit is contained in:
parent
ae779ae25d
commit
4ce6980098
20
main.go
20
main.go
@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,7 +60,12 @@ func main() {
|
|||||||
cpuprofile := flag.String(
|
cpuprofile := flag.String(
|
||||||
"cpuprofile",
|
"cpuprofile",
|
||||||
"",
|
"",
|
||||||
"path to the file to write the cpu profile")
|
"path to the file to write the CPU profile")
|
||||||
|
|
||||||
|
memprofile := flag.String(
|
||||||
|
"memprofile",
|
||||||
|
"",
|
||||||
|
"path to the file to write the memory profile")
|
||||||
|
|
||||||
flag.StringVar(&gLastDirPath,
|
flag.StringVar(&gLastDirPath,
|
||||||
"last-dir-path",
|
"last-dir-path",
|
||||||
@ -125,4 +131,16 @@ func main() {
|
|||||||
|
|
||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *memprofile != "" {
|
||||||
|
f, err := os.Create(*memprofile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("could not create memory profile: ", err)
|
||||||
|
}
|
||||||
|
runtime.GC()
|
||||||
|
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||||
|
log.Fatal("could not write memory profile: ", err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user