From 3a32c4e59f9c63dfe5dc1b4fd2b89329159c8516 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 17 Jun 2023 17:48:54 +0200 Subject: [PATCH] document how to analyze performance / memory usage issues --- CONTRIBUTING.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 36a7c0695..e0f2e2c08 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -88,10 +88,40 @@ Then use the `go` tool to build restic: $ ./restic version restic 0.14.0-dev (compiled manually) compiled with go1.19 on linux/amd64 +To create a debug build use: + + $ go build -tags debug ./cmd/restic + You can run all tests with the following command: $ go test ./... + +Performance and Memory Usage Issues +=================================== + +Debug builds of restic support the `--block-profile`, `--cpu-profile`, +`--mem-profile`, and `--trace-profile` options which collect performance data +that later on can be analyzed using the go tools: + + $ restic --cpu-profile . [...] + $ go tool pprof -http localhost:12345 cpu.pprof + +To analyze a trace profile use `go tool trace -http=localhost:12345 trace.out`. + +As the memory usage of restic changes over time, it may be useful to capture a +snapshot of the current heap. This is possible using then `--listen-profile` +option. Then while restic runs you can query and afterwards analyze the heap statistics. + + $ restic --listen-profile localhost:12345 [...] + $ curl http://localhost:12345/debug/pprof/heap -o heap.pprof + $ go tool pprof -http localhost:12345 heap.pprof + +Further useful tools are setting the environment variable `GODEBUG=gctrace=1`, +which provides information about garbage collector runs. For a graphical variant +combine this with gcvis. + + Providing Patches =================