2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 21:05:10 +00:00

Add option for debug pprof service

This commit is contained in:
Alexander Neumann 2017-01-22 19:10:32 +01:00
parent 30ff7413be
commit 668a36a652
3 changed files with 43 additions and 0 deletions

View 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)
}
}()
}
}

View File

@ -0,0 +1,6 @@
// +build !debug
package main
// runDebug is a noop without the debug tag.
func runDebug() {}

View File

@ -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() {