mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-09 09:50:30 +00:00
Add STCPUPROFILE env
This commit is contained in:
parent
fb162ff529
commit
70fa5ffa06
@ -14,6 +14,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"runtime/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -31,30 +32,32 @@ var (
|
|||||||
myID string
|
myID string
|
||||||
confDir string
|
confDir string
|
||||||
rateBucket *ratelimit.Bucket
|
rateBucket *ratelimit.Bucket
|
||||||
|
stop = make(chan bool)
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
usage = "syncthing [options]"
|
usage = "syncthing [options]"
|
||||||
extraUsage = `The following enviroment variables are interpreted by syncthing:
|
extraUsage = `The following enviroment variables are interpreted by syncthing:
|
||||||
|
|
||||||
STNORESTART Do not attempt to restart when requested to, instead just exit.
|
STNORESTART Do not attempt to restart when requested to, instead just exit.
|
||||||
Set this variable when running under a service manager such as
|
Set this variable when running under a service manager such as
|
||||||
runit, launchd, etc.
|
runit, launchd, etc.
|
||||||
|
|
||||||
STPROFILER Set to a listen address such as "127.0.0.1:9090" to start the
|
STPROFILER Set to a listen address such as "127.0.0.1:9090" to start the
|
||||||
profiler with HTTP access.
|
profiler with HTTP access.
|
||||||
|
|
||||||
STTRACE A comma separated string of facilities to trace. The valid
|
STTRACE A comma separated string of facilities to trace. The valid
|
||||||
facility strings:
|
facility strings:
|
||||||
- "discover" (the node discovery package)
|
- "discover" (the node discovery package)
|
||||||
- "files" (file set store)
|
- "files" (file set store)
|
||||||
- "idx" (index sending and receiving)
|
- "idx" (index sending and receiving)
|
||||||
- "mc" (multicast beacon)
|
- "mc" (multicast beacon)
|
||||||
- "need" (file need calculations)
|
- "need" (file need calculations)
|
||||||
- "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{})
|
||||||
|
Loading…
Reference in New Issue
Block a user