From c00e8f6686836037b48b3a72f972e57c7f7b4a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zlatko=20=C4=8Calu=C5=A1i=C4=87?= Date: Sun, 6 Nov 2016 19:38:41 +0100 Subject: [PATCH] Introduce cpuprofile argument --- server.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.go b/server.go index 7a8d276..d58b4b3 100644 --- a/server.go +++ b/server.go @@ -7,14 +7,26 @@ import ( "net/http" "os" "path/filepath" + "runtime/pprof" ) func main() { + var cpuprofile = flag.String("cpuprofile", "", "write CPU profile to file") var listen = flag.String("listen", ":8000", "listen address") var path = flag.String("path", "/tmp/restic", "data directory") var tls = flag.Bool("tls", false, "turn on TLS support") flag.Parse() + if *cpuprofile != "" { + f, err := os.Create(*cpuprofile) + if err != nil { + log.Fatal(err) + } + log.Println("CPU profiling enabled") + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + } + log.Println("Creating repository directories") dirs := []string{ "data",