restic/src/cmds/restic/global_debug.go

32 lines
602 B
Go
Raw Normal View History

2017-01-22 19:10:32 +01:00
// +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)
}
}()
}
}