Pprof for profile
parent
ddee582e5e
commit
463c278610
33
flags.go
33
flags.go
|
@ -4,7 +4,9 @@ import (
|
||||||
"code.cloudfoundry.org/bytefmt"
|
"code.cloudfoundry.org/bytefmt"
|
||||||
"github.com/juju/gnuflag"
|
"github.com/juju/gnuflag"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,13 +52,36 @@ func Route() Params {
|
||||||
"Threads count on each osd")
|
"Threads count on each osd")
|
||||||
gnuflag.BoolVar(¶ms.parallel, "parallel", false,
|
gnuflag.BoolVar(¶ms.parallel, "parallel", false,
|
||||||
"Do test all osd in parallel mode")
|
"Do test all osd in parallel mode")
|
||||||
|
gnuflag.StringVar(¶ms.cpuprofile, "cpuprofile", "",
|
||||||
|
"Name of cpuprofile")
|
||||||
|
gnuflag.StringVar(¶ms.memprofile, "memprofile", "",
|
||||||
|
"Name of memprofile")
|
||||||
gnuflag.Parse(true)
|
gnuflag.Parse(true)
|
||||||
|
|
||||||
if params.mode == "osd" && len(params.define) != 0 {
|
if params.cpuprofile != "" {
|
||||||
if i := strings.HasPrefix(params.define, "osd."); i != true {
|
f, err := os.Create(params.cpuprofile)
|
||||||
log.Fatalln("Define correct osd in format osd.X")
|
if err != nil {
|
||||||
|
log.Fatal("could not create CPU profile: ", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
if err := pprof.StartCPUProfile(f); err != nil {
|
||||||
|
log.Fatal("could not start CPU profile: ", err)
|
||||||
|
}
|
||||||
|
defer pprof.StopCPUProfile()
|
||||||
|
}
|
||||||
|
|
||||||
|
if params.memprofile != "" {
|
||||||
|
f, err := os.Create(params.memprofile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("could not create memory profile: ", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
runtime.GC() // get up-to-date statistics
|
||||||
|
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||||
|
log.Fatal("could not write memory profile: ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blocksize, err := bytefmt.ToBytes(params.bs)
|
blocksize, err := bytefmt.ToBytes(params.bs)
|
||||||
params.blocksize = blocksize
|
params.blocksize = blocksize
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue