From 09365cc4eae5048d5563d4efff7944ebf89821d9 Mon Sep 17 00:00:00 2001
From: Alexander Neumann <alexander@bumpern.de>
Date: Sun, 8 Apr 2018 21:55:26 +0200
Subject: [PATCH] Add --trace-profile

---
 cmd/restic/global_debug.go | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/cmd/restic/global_debug.go b/cmd/restic/global_debug.go
index 7cad172f6..cb7dac10a 100644
--- a/cmd/restic/global_debug.go
+++ b/cmd/restic/global_debug.go
@@ -18,6 +18,7 @@ var (
 	listenMemoryProfile string
 	memProfilePath      string
 	cpuProfilePath      string
+	traceProfilePath    string
 	insecure            bool
 )
 
@@ -26,6 +27,7 @@ func init() {
 	f.StringVar(&listenMemoryProfile, "listen-profile", "", "listen on this `address:port` for memory profiling")
 	f.StringVar(&memProfilePath, "mem-profile", "", "write memory profile to `dir`")
 	f.StringVar(&cpuProfilePath, "cpu-profile", "", "write cpu profile to `dir`")
+	f.StringVar(&traceProfilePath, "trace-profile", "", "write trace to `dir`")
 	f.BoolVar(&insecure, "insecure-kdf", false, "use insecure KDF settings")
 }
 
@@ -46,7 +48,18 @@ func runDebug() error {
 		}()
 	}
 
-	if memProfilePath != "" && cpuProfilePath != "" {
+	profilesEnabled := 0
+	if memProfilePath != "" {
+		profilesEnabled++
+	}
+	if cpuProfilePath != "" {
+		profilesEnabled++
+	}
+	if traceProfilePath != "" {
+		profilesEnabled++
+	}
+
+	if profilesEnabled > 1 {
 		return errors.Fatal("only one profile (memory or CPU) may be activated at the same time")
 	}
 
@@ -58,6 +71,8 @@ func runDebug() error {
 		prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.MemProfile, profile.ProfilePath(memProfilePath))
 	} else if cpuProfilePath != "" {
 		prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.CPUProfile, profile.ProfilePath(cpuProfilePath))
+	} else if traceProfilePath != "" {
+		prof = profile.Start(profile.Quiet, profile.NoShutdownHook, profile.TraceProfile, profile.ProfilePath(traceProfilePath))
 	}
 
 	if prof != nil {