From 213acaee3bea58d3ddcfb6136f5945b6e218e628 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 13 Aug 2014 14:38:23 +0200 Subject: [PATCH] Include perfstats and heap profiles in standard build --- cmd/syncthing/heapprof.go | 6 +++--- cmd/syncthing/main.go | 17 +++++++++++------ cmd/syncthing/perfstats.go | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/syncthing/heapprof.go b/cmd/syncthing/heapprof.go index 6e6b17f13..24e0e522c 100644 --- a/cmd/syncthing/heapprof.go +++ b/cmd/syncthing/heapprof.go @@ -2,8 +2,6 @@ // All rights reserved. Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build heapprof - package main import ( @@ -16,7 +14,9 @@ import ( ) func init() { - go saveHeapProfiles() + if os.Getenv("STHEAPPROFILE") != "" { + go saveHeapProfiles() + } } func saveHeapProfiles() { diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 0115b2ef4..8f3b7606e 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -104,9 +104,6 @@ The following enviroment variables are interpreted by syncthing: Set this variable when running under a service manager such as runit, launchd, etc. - STPROFILER Set to a listen address such as "127.0.0.1:9090" to start the - profiler with HTTP access. - STTRACE A comma separated string of facilities to trace. The valid facility strings: - "beacon" (the beacon package) @@ -120,10 +117,18 @@ The following enviroment variables are interpreted by syncthing: - "xdr" (the xdr package) - "all" (all of the above) - STCPUPROFILE Write CPU profile to the specified file. - STGUIASSETS Directory to load GUI assets from. Overrides compiled in assets. + STPROFILER Set to a listen address such as "127.0.0.1:9090" to start the + profiler with HTTP access. + + STCPUPROFILE Write a CPU profile to cpu-$pid.pprof on exit. + + STHEAPPROFILE Write heap profiles to heap-$pid-$timestamp.pprof each time + heap usage increases. + + STPERFSTATS Write running performance statistics to perf-$pid.csv. + STDEADLOCKTIMEOUT Alter deadlock detection timeout (seconds; default 1200).` ) @@ -498,7 +503,7 @@ nextRepo: } if cpuprof := os.Getenv("STCPUPROFILE"); len(cpuprof) > 0 { - f, err := os.Create(cpuprof) + f, err := os.Create(fmt.Sprintf("cpu-%d.pprof", os.Getpid())) if err != nil { log.Fatal(err) } diff --git a/cmd/syncthing/perfstats.go b/cmd/syncthing/perfstats.go index cb701a350..d1596b501 100644 --- a/cmd/syncthing/perfstats.go +++ b/cmd/syncthing/perfstats.go @@ -2,8 +2,6 @@ // All rights reserved. Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build perfstats - package main import ( @@ -15,7 +13,9 @@ import ( ) func init() { - go savePerfStats(fmt.Sprintf("perfstats-%d.csv", syscall.Getpid())) + if os.Getenv("STPERFSTATS") != "" { + go savePerfStats(fmt.Sprintf("perfstats-%d.csv", syscall.Getpid())) + } } func savePerfStats(file string) {