Add STCPUPROFILE env

This commit is contained in:
Jakob Borg 2014-04-14 12:13:50 +02:00
parent fb162ff529
commit 70fa5ffa06

View File

@ -14,6 +14,7 @@ import (
"path/filepath"
"runtime"
"runtime/debug"
"runtime/pprof"
"strings"
"time"
@ -31,6 +32,7 @@ var (
myID string
confDir string
rateBucket *ratelimit.Bucket
stop = make(chan bool)
)
const (
@ -54,7 +56,8 @@ const (
- "net" (connecting and disconnecting, network messages)
- "pull" (file pull activity)
- "scanner" (the file change scanner)
`
STCPUPROFILE Write CPU profile to the specified file.`
)
func main() {
@ -73,7 +76,7 @@ func main() {
if showVersion {
fmt.Printf("syncthing %s (%s %s-%s)\n", Version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
os.Exit(0)
return
}
if len(os.Getenv("GOGC")) == 0 {
@ -142,7 +145,7 @@ func main() {
if reset {
resetRepositories()
os.Exit(0)
return
}
if profiler := os.Getenv("STPROFILER"); len(profiler) > 0 {
@ -235,7 +238,16 @@ func main() {
}
}
select {}
if cpuprof := os.Getenv("STCPUPROFILE"); len(cpuprof) > 0 {
f, err := os.Create(cpuprof)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
<-stop
}
func resetRepositories() {
@ -262,7 +274,8 @@ func restart() {
if os.Getenv("SMF_FMRI") != "" || os.Getenv("STNORESTART") != "" {
// Solaris SMF
infoln("Service manager detected; exit instead of restart")
os.Exit(0)
stop <- true
return
}
env := os.Environ()
@ -282,7 +295,7 @@ func restart() {
fatalln(err)
}
proc.Release()
os.Exit(0)
stop <- true
}
var saveConfigCh = make(chan struct{})