mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
Add mutex profiling to benchmark
This commit is contained in:
parent
56e6af99f9
commit
c8438cfc81
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue