Browse Source

Add flag to enable CPU profiling

Rod Hynes 11 years ago
parent
commit
3e23c3e3b8
1 changed files with 16 additions and 1 deletions
  1. 16 1
      ConsoleClient/psiphonClient.go

+ 16 - 1
ConsoleClient/psiphonClient.go

@@ -25,6 +25,7 @@ import (
 	"log"
 	"os"
 	"os/signal"
+	"runtime/pprof"
 	"sync"
 
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon"
@@ -33,8 +34,13 @@ import (
 func main() {
 
 	var configFilename string
-	flag.StringVar(&configFilename, "config", "", "configuration file")
+	flag.StringVar(&configFilename, "config", "", "configuration input file")
+
+	var profileFilename string
+	flag.StringVar(&profileFilename, "profile", "", "CPU profile output file")
+
 	flag.Parse()
+
 	if configFilename == "" {
 		log.Fatalf("configuration file is required")
 	}
@@ -47,6 +53,15 @@ func main() {
 		log.Fatalf("error processing configuration file: %s", err)
 	}
 
+	if profileFilename != "" {
+		profileFile, err := os.Create(profileFilename)
+		if err != nil {
+			log.Fatalf("error opening profile file: %s", err)
+		}
+		pprof.StartCPUProfile(profileFile)
+		defer pprof.StopCPUProfile()
+	}
+
 	err = psiphon.InitDataStore(config)
 	if err != nil {
 		log.Fatalf("error initializing datastore: %s", err)