mirror of
https://github.com/kopia/kopia.git
synced 2026-01-24 14:28:06 -05:00
* fixed godot linter errors * reformatted source with gofumpt * disabled some linters * fixed nolintlint warnings * fixed gci warnings * lint: fixed 'nestif' warnings * lint: fixed 'exhaustive' warnings * lint: fixed 'gocritic' warnings * lint: fixed 'noctx' warnings * lint: fixed 'wsl' warnings * lint: fixed 'goerr113' warnings * lint: fixed 'gosec' warnings * lint: upgraded linter to 1.30.0 * lint: more 'exhaustive' warnings Co-authored-by: Nick <nick@kasten.io>
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
// +build profiling
|
|
|
|
package cli
|
|
|
|
import "github.com/pkg/profile"
|
|
|
|
var (
|
|
profileDir = app.Flag("profile-dir", "Write profile to the specified directory").Hidden().String()
|
|
profileCPU = app.Flag("profile-cpu", "Enable CPU profiling").Hidden().Bool()
|
|
profileMemory = app.Flag("profile-memory", "Enable memory profiling").Hidden().Int()
|
|
profileBlocking = app.Flag("profile-blocking", "Enable block profiling").Hidden().Bool()
|
|
profileMutex = app.Flag("profile-mutex", "Enable mutex profiling").Hidden().Bool()
|
|
)
|
|
|
|
// withProfiling runs the given callback with profiling enabled, configured according to command line flags.
|
|
func withProfiling(callback func() error) error {
|
|
if *profileDir != "" {
|
|
pp := profile.ProfilePath(*profileDir)
|
|
if *profileMemory > 0 {
|
|
defer profile.Start(pp, profile.MemProfileRate(*profileMemory)).Stop()
|
|
}
|
|
if *profileCPU {
|
|
defer profile.Start(pp, profile.CPUProfile).Stop()
|
|
}
|
|
if *profileBlocking {
|
|
defer profile.Start(pp, profile.BlockProfile).Stop()
|
|
}
|
|
if *profileMutex {
|
|
defer profile.Start(pp, profile.MutexProfile).Stop()
|
|
}
|
|
}
|
|
|
|
return callback()
|
|
}
|