forked from TrueCloudLab/restic
Add block profile option
This commit is contained in:
parent
4fb1401266
commit
4ba8d40282
1 changed files with 18 additions and 11 deletions
|
@ -15,19 +15,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
listenMemoryProfile string
|
listenProfile string
|
||||||
memProfilePath string
|
memProfilePath string
|
||||||
cpuProfilePath string
|
cpuProfilePath string
|
||||||
traceProfilePath string
|
traceProfilePath string
|
||||||
insecure bool
|
blockProfilePath string
|
||||||
|
insecure bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
f := cmdRoot.PersistentFlags()
|
f := cmdRoot.PersistentFlags()
|
||||||
f.StringVar(&listenMemoryProfile, "listen-profile", "", "listen on this `address:port` for memory profiling")
|
f.StringVar(&listenProfile, "listen-profile", "", "listen on this `address:port` for memory profiling")
|
||||||
f.StringVar(&memProfilePath, "mem-profile", "", "write memory profile to `dir`")
|
f.StringVar(&memProfilePath, "mem-profile", "", "write memory profile to `dir`")
|
||||||
f.StringVar(&cpuProfilePath, "cpu-profile", "", "write cpu profile to `dir`")
|
f.StringVar(&cpuProfilePath, "cpu-profile", "", "write cpu profile to `dir`")
|
||||||
f.StringVar(&traceProfilePath, "trace-profile", "", "write trace to `dir`")
|
f.StringVar(&traceProfilePath, "trace-profile", "", "write trace to `dir`")
|
||||||
|
f.StringVar(&blockProfilePath, "block-profile", "", "write block profile to `dir`")
|
||||||
f.BoolVar(&insecure, "insecure-kdf", false, "use insecure KDF settings")
|
f.BoolVar(&insecure, "insecure-kdf", false, "use insecure KDF settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,12 +40,12 @@ func (fakeTestingTB) Logf(msg string, args ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDebug() error {
|
func runDebug() error {
|
||||||
if listenMemoryProfile != "" {
|
if listenProfile != "" {
|
||||||
fmt.Fprintf(os.Stderr, "running memory profile HTTP server on %v\n", listenMemoryProfile)
|
fmt.Fprintf(os.Stderr, "running profile HTTP server on %v\n", listenProfile)
|
||||||
go func() {
|
go func() {
|
||||||
err := http.ListenAndServe(listenMemoryProfile, nil)
|
err := http.ListenAndServe(listenProfile, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "memory profile listen failed: %v\n", err)
|
fmt.Fprintf(os.Stderr, "profile HTTP server listen failed: %v\n", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -58,9 +60,12 @@ func runDebug() error {
|
||||||
if traceProfilePath != "" {
|
if traceProfilePath != "" {
|
||||||
profilesEnabled++
|
profilesEnabled++
|
||||||
}
|
}
|
||||||
|
if blockProfilePath != "" {
|
||||||
|
profilesEnabled++
|
||||||
|
}
|
||||||
|
|
||||||
if profilesEnabled > 1 {
|
if profilesEnabled > 1 {
|
||||||
return errors.Fatal("only one profile (memory or CPU) may be activated at the same time")
|
return errors.Fatal("only one profile (memory, CPU, trace, or block) may be activated at the same time")
|
||||||
}
|
}
|
||||||
|
|
||||||
var prof interface {
|
var prof interface {
|
||||||
|
@ -73,6 +78,8 @@ func runDebug() error {
|
||||||
prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.CPUProfile, profile.ProfilePath(cpuProfilePath))
|
prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.CPUProfile, profile.ProfilePath(cpuProfilePath))
|
||||||
} else if traceProfilePath != "" {
|
} else if traceProfilePath != "" {
|
||||||
prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.TraceProfile, profile.ProfilePath(traceProfilePath))
|
prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.TraceProfile, profile.ProfilePath(traceProfilePath))
|
||||||
|
} else if blockProfilePath != "" {
|
||||||
|
prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.BlockProfile, profile.ProfilePath(blockProfilePath))
|
||||||
}
|
}
|
||||||
|
|
||||||
if prof != nil {
|
if prof != nil {
|
||||||
|
|
Loading…
Reference in a new issue