fix: dont fail to collect profiles if no ipfs bin
Due to the bash args used, collect-profiles.sh would fail if which ipfs failed to find an ipfs binary on the path, like when running ipfs in docker. Fixes that by using a check for the command that wont error if it's not found. Also - adds a commment to explains when to use the script and what it does. - be less chatty. Simpify the output so it's clearer what it's doing. Experts can read the script or set the -x flag themselves. License: MIT Signed-off-by: Oli Evans <oli@tableflip.io>
Oli Evans committed
Jan 16, 2020 at 11:42 UTC
4eb380a58ba98682bcfd08fae903d2e4679d1a6f
1 file changed
+22
-11
bin/collect-profiles.sh
+22
-11
@@ -1,20 +1,28 @@
1
#!/usr/bin/env bash
2
-set -x
2
+
3
+# collect-profiles.sh
4
+#
5
+# Collects go profile information from a running `ipfs` daemon.
6
+# Creates an archive including the profiles, profile graph svgs,
7
+# ...and where available, a copy of the `ipfs` binary on the PATH.
8
+#
9
+# Please run this script and attach the profile archive it creates
10
+# when reporting bugs at https://github.com/ipfs/go-ipfs/issues
11
+
12
set -euo pipefail
13
IFS=$'\n\t'
14
15
HTTP_API="${1:-127.0.0.1:5001}"
16
tmpdir=$(mktemp -d)
17
export PPROF_TMPDIR="$tmpdir"
9
-pushd "$tmpdir"
18
+pushd "$tmpdir" > /dev/null
19
11
-IPFS_BIN=$(which ipfs)
12
-if [[ -e "$IPFS_BIN" ]]; then
13
- cp "$IPFS_BIN" ipfs
20
+if command -v ipfs > /dev/null 2>&1; then
21
+ cp "$(command -v ipfs)" ipfs
22
fi
23
24
echo Collecting goroutine stacks
17
-curl -o goroutines.stacks "http://$HTTP_API"'/debug/pprof/goroutine?debug=2'
25
+curl -s -o goroutines.stacks "http://$HTTP_API"'/debug/pprof/goroutine?debug=2'
26
27
echo Collecting goroutine profile
28
go tool pprof -symbolize=remote -svg -output goroutine.svg "http://$HTTP_API/debug/pprof/goroutine"
@@ -26,15 +34,18 @@ echo "Collecting cpu profile (~30s)"
34
go tool pprof -symbolize=remote -svg -output cpu.svg "http://$HTTP_API/debug/pprof/profile"
35
36
echo "Enabling mutex profiling"
29
-curl -X POST -v "http://$HTTP_API"'/debug/pprof-mutex/?fraction=4'
37
+curl -X POST "http://$HTTP_API"'/debug/pprof-mutex/?fraction=4'
38
39
echo "Waiting for mutex data to be updated (30s)"
40
sleep 30
33
-curl -o mutex.txt "http://$HTTP_API"'/debug/pprof/mutex?debug=2'
41
+curl -s -o mutex.txt "http://$HTTP_API"'/debug/pprof/mutex?debug=2'
42
go tool pprof -symbolize=remote -svg -output mutex.svg "http://$HTTP_API/debug/pprof/mutex"
43
+
44
echo "Disabling mutex profiling"
36
-curl -X POST -v "http://$HTTP_API"'/debug/pprof-mutex/?fraction=0'
45
+curl -X POST "http://$HTTP_API"'/debug/pprof-mutex/?fraction=0'
46
38
-popd
39
-tar cvzf "./ipfs-profile-$(uname -n)-$(date +'%Y-%m-%dT%H:%M:%S%z').tar.gz" -C "$tmpdir" .
47
+OUTPUT_NAME=ipfs-profile-$(uname -n)-$(date +'%Y-%m-%dT%H:%M:%S%z').tar.gz
48
+echo "Creating $OUTPUT_NAME"
49
+popd > /dev/null
50
+tar czf "./$OUTPUT_NAME" -C "$tmpdir" .
51
rm -rf "$tmpdir"