profiling: Fix downloading tracing profiling data (#6599)

pkg/pprof saves tracing profiling data in a different file name
(trace.out) in contrary to other profiling mode.
This commit is contained in:
Anis Elleuch 2018-10-15 19:13:19 +01:00 committed by kannappanr
parent 5b3090dffc
commit 81a481e098

View File

@ -218,18 +218,26 @@ func startProfiler(profilerType, dirPath string) (interface {
Stop()
}
// Enable profiler, supported types are [cpu, mem, block].
var profilerFileName string
// Enable profiler and set the name of the file that pkg/pprof
// library creates to store profiling data.
switch profilerType {
case "cpu":
profiler = profile.Start(profile.CPUProfile, profile.NoShutdownHook, profile.ProfilePath(dirPath))
profilerFileName = "cpu.pprof"
case "mem":
profiler = profile.Start(profile.MemProfile, profile.NoShutdownHook, profile.ProfilePath(dirPath))
profilerFileName = "mem.pprof"
case "block":
profiler = profile.Start(profile.BlockProfile, profile.NoShutdownHook, profile.ProfilePath(dirPath))
profilerFileName = "block.pprof"
case "mutex":
profiler = profile.Start(profile.MutexProfile, profile.NoShutdownHook, profile.ProfilePath(dirPath))
profilerFileName = "mutex.pprof"
case "trace":
profiler = profile.Start(profile.TraceProfile, profile.NoShutdownHook, profile.ProfilePath(dirPath))
profilerFileName = "trace.out"
default:
return nil, errors.New("profiler type unknown")
}
@ -237,7 +245,7 @@ func startProfiler(profilerType, dirPath string) (interface {
return &profilerWrapper{
stopFn: profiler.Stop,
pathFn: func() string {
return filepath.Join(dirPath, profilerType+".pprof")
return filepath.Join(dirPath, profilerFileName)
},
}, nil
}