cmd/syncthing, lib/config: Enable HTTP CPU/heap profile collection for users

This adds a config to enable debug functions on the API server, which is
by default disabled. When enabled, the /rest/debug things become
available and become available without requiring a CSRF token (although
authentication is required if configured).

We also add a new endpoint /rest/debug/cpuprof?duration=15s (with the
duration being configurable, defaulting to 30s). This runs a CPU profile
for the duration and returns it as a file. It sets headers so that a
browser will save the file with an informative name.

The same is done for heap profiles, /rest/debug/heapprof, which does not
take any parameters.

The purpose of this is that any user can enable debugging under
advanced, then point their browser to the endpoint above and get a file
that contains a CPU or heap profile we can use, with the filename
telling us what version and architecture the profile is from.

On the command line, this becomes

    curl -O -J http://localhost:8082/rest/debug/cpuprof?duration=5s
    curl: Saved to filename
    'syncthing-cpu-darwin-amd64-v0.14.3+4-g935bcc0-110307.pprof'

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3467
This commit is contained in:
Jakob Borg
2016-08-02 11:06:45 +00:00
committed by Audrius Butkevicius
parent 08b5a7908f
commit ffe7a2fcd7
8 changed files with 60 additions and 7 deletions

View File

@@ -62,7 +62,7 @@
<device id="373HSRP-QLPNLIE-JYKZVQF-P4PKZ63-R2ZE6K3-YD442U2-JHBGBQG-WWXAHAU" name="s3" compression="metadata" introducer="false">
<address>tcp://127.0.0.1:22003</address>
</device>
<gui enabled="true" tls="false">
<gui enabled="true" tls="false" debugging="true">
<address>127.0.0.1:8082</address>
<apikey>abc123</apikey>
<theme>default</theme>