diff --git a/cmd/tsdb/Makefile b/cmd/tsdb/Makefile index ee17f044f..ae4dc1cf7 100644 --- a/cmd/tsdb/Makefile +++ b/cmd/tsdb/Makefile @@ -1,5 +1,5 @@ build: - @go1.8rc1 build . + @go build . bench: build @echo ">> running benchmark" @@ -8,3 +8,4 @@ bench: build @go tool pprof --inuse_space -svg ./tsdb benchout/mem.prof > benchout/memprof.inuse.svg @go tool pprof --alloc_space -svg ./tsdb benchout/mem.prof > benchout/memprof.alloc.svg @go tool pprof -svg ./tsdb benchout/block.prof > benchout/blockprof.svg + @go tool pprof -svg ./tsdb benchout/mutex.prof > benchout/mutexprof.svg diff --git a/cmd/tsdb/main.go b/cmd/tsdb/main.go index 55b1a7c8e..e47254feb 100644 --- a/cmd/tsdb/main.go +++ b/cmd/tsdb/main.go @@ -73,6 +73,7 @@ type writeBenchmark struct { cpuprof *os.File memprof *os.File blockprof *os.File + mtxprof *os.File } func NewBenchWriteCommand() *cobra.Command { @@ -259,14 +260,20 @@ func (b *writeBenchmark) startProfiling() { if err != nil { exitWithError(fmt.Errorf("bench: could not create memory profile: %v", err)) } - runtime.MemProfileRate = 4096 + runtime.MemProfileRate = 64 * 1024 // Start fatal profiling. b.blockprof, err = os.Create(filepath.Join(b.outPath, "block.prof")) if err != nil { exitWithError(fmt.Errorf("bench: could not create block profile: %v", err)) } - runtime.SetBlockProfileRate(1) + runtime.SetBlockProfileRate(20) + + b.mtxprof, err = os.Create(filepath.Join(b.outPath, "mutex.prof")) + if err != nil { + exitWithError(fmt.Errorf("bench: could not create mutex profile: %v", err)) + } + runtime.SetMutexProfileFraction(20) } func (b *writeBenchmark) stopProfiling() { @@ -286,6 +293,12 @@ func (b *writeBenchmark) stopProfiling() { b.blockprof = nil runtime.SetBlockProfileRate(0) } + if b.mtxprof != nil { + pprof.Lookup("mutex").WriteTo(b.mtxprof, 0) + b.mtxprof.Close() + b.mtxprof = nil + runtime.SetMutexProfileFraction(0) + } } func measureTime(stage string, f func()) time.Duration {