mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +00:00
Add option for debug pprof service
This commit is contained in:
parent
30ff7413be
commit
668a36a652
31
src/cmds/restic/global_debug.go
Normal file
31
src/cmds/restic/global_debug.go
Normal file
@ -0,0 +1,31 @@
|
||||
// +build debug
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
listenMemoryProfile string
|
||||
)
|
||||
|
||||
func init() {
|
||||
f := cmdRoot.PersistentFlags()
|
||||
f.StringVar(&listenMemoryProfile, "listen-profile", "", "listen on this `address:port` for memory profiling")
|
||||
}
|
||||
|
||||
func runDebug() {
|
||||
if listenMemoryProfile != "" {
|
||||
fmt.Fprintf(os.Stderr, "running memory profile HTTP server on %v\n", listenMemoryProfile)
|
||||
go func() {
|
||||
err := http.ListenAndServe(listenMemoryProfile, nil)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "memory profile listen failed: %v\n", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
6
src/cmds/restic/global_release.go
Normal file
6
src/cmds/restic/global_release.go
Normal file
@ -0,0 +1,6 @@
|
||||
// +build !debug
|
||||
|
||||
package main
|
||||
|
||||
// runDebug is a noop without the debug tag.
|
||||
func runDebug() {}
|
@ -22,6 +22,12 @@ directories in an encrypted repository stored on different backends.
|
||||
`,
|
||||
SilenceErrors: true,
|
||||
SilenceUsage: true,
|
||||
|
||||
// run the debug functions for all subcommands (if build tag "debug" is
|
||||
// enabled)
|
||||
PersistentPreRun: func(*cobra.Command, []string) {
|
||||
runDebug()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
Loading…
Reference in New Issue
Block a user