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