Add mutex profiling to benchmark

This commit is contained in:
Fabian Reinartz 2017-05-14 11:51:56 +02:00
parent 56e6af99f9
commit c8438cfc81
2 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -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 {