mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 23:06:32 +00:00
Merge pull request #1191 from prattmic/profile
debug: properly handle interrupted profiles
This commit is contained in:
commit
0ee1650f82
@ -19,10 +19,6 @@ var (
|
|||||||
memProfilePath string
|
memProfilePath string
|
||||||
cpuProfilePath string
|
cpuProfilePath string
|
||||||
insecure bool
|
insecure bool
|
||||||
|
|
||||||
prof interface {
|
|
||||||
Stop()
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -54,10 +50,21 @@ func runDebug() error {
|
|||||||
return errors.Fatal("only one profile (memory or CPU) may be activated at the same time")
|
return errors.Fatal("only one profile (memory or CPU) may be activated at the same time")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var prof interface {
|
||||||
|
Stop()
|
||||||
|
}
|
||||||
|
|
||||||
if memProfilePath != "" {
|
if memProfilePath != "" {
|
||||||
prof = profile.Start(profile.Quiet, profile.MemProfile, profile.ProfilePath(memProfilePath))
|
prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.MemProfile, profile.ProfilePath(memProfilePath))
|
||||||
} else if cpuProfilePath != "" {
|
} else if cpuProfilePath != "" {
|
||||||
prof = profile.Start(profile.Quiet, profile.CPUProfile, profile.ProfilePath(cpuProfilePath))
|
prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.CPUProfile, profile.ProfilePath(cpuProfilePath))
|
||||||
|
}
|
||||||
|
|
||||||
|
if prof != nil {
|
||||||
|
AddCleanupHandler(func() error {
|
||||||
|
prof.Stop()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if insecure {
|
if insecure {
|
||||||
@ -66,9 +73,3 @@ func runDebug() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func shutdownDebug() {
|
|
||||||
if prof != nil {
|
|
||||||
prof.Stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -4,6 +4,3 @@ package main
|
|||||||
|
|
||||||
// runDebug is a noop without the debug tag.
|
// runDebug is a noop without the debug tag.
|
||||||
func runDebug() error { return nil }
|
func runDebug() error { return nil }
|
||||||
|
|
||||||
// shutdownDebug is a noop without the debug tag.
|
|
||||||
func shutdownDebug() {}
|
|
||||||
|
@ -52,9 +52,6 @@ directories in an encrypted repository stored on different backends.
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
PersistentPostRun: func(*cobra.Command, []string) {
|
|
||||||
shutdownDebug()
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var logBuffer = bytes.NewBuffer(nil)
|
var logBuffer = bytes.NewBuffer(nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user