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