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