From 1e847059bca680639549b82beb4be538d2a1fdbc Mon Sep 17 00:00:00 2001
From: Brian Tiger Chow <brian.holderchow@gmail.com>
Date: Wed, 29 Oct 2014 18:12:41 -0700
Subject: [PATCH] style(cmd/ipfs/pprof) move defer close to initialization

---
 cmd/ipfs/Makefile | 8 ++++++++
 cmd/ipfs/ipfs.go  | 4 +++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/cmd/ipfs/Makefile b/cmd/ipfs/Makefile
index fccb80330..aa97f0a63 100644
--- a/cmd/ipfs/Makefile
+++ b/cmd/ipfs/Makefile
@@ -5,3 +5,11 @@ build:
 
 install: build
 	go install
+
+# cpu profiling: `go tool pprof ipfs cpu.prof`
+# mem profiling: `go tool pprof ipfs ipfs.mprof`
+
+clean:
+	rm -f cpu.prof
+	rm -f ipfs.mprof
+	rm -f ipfs
diff --git a/cmd/ipfs/ipfs.go b/cmd/ipfs/ipfs.go
index 9ce5d7faf..57b48c33f 100644
--- a/cmd/ipfs/ipfs.go
+++ b/cmd/ipfs/ipfs.go
@@ -99,12 +99,14 @@ func main() {
 	// if debugging, setup profiling.
 	if u.Debug {
 		ofi, err := os.Create("cpu.prof")
+		defer ofi.Close()
+
 		if err != nil {
 			fmt.Println(err)
 			return
 		}
+
 		pprof.StartCPUProfile(ofi)
-		defer ofi.Close()
 		defer pprof.StopCPUProfile()
 	}
 
-- 
GitLab