kubo/bin/collect-profiles.sh
Oli Evans 75240599c9
fix: prefer 127.0.0.1
With an empty API headers config like

```js
	"API": {
		"HTTPHeaders": {}
	},
```

running collect-profiles.sh shows connection errors when trying to POST to `/debug/pprof-mutex/` end point when using `localhost`.

The same errors do not occur when using `127.0.0.1`

License: MIT
Signed-off-by: Oli Evans <oli@tableflip.io>
2019-09-24 11:20:32 +01:00

41 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -x
set -euo pipefail
IFS=$'\n\t'
HTTP_API="${1:-127.0.0.1:5001}"
tmpdir=$(mktemp -d)
export PPROF_TMPDIR="$tmpdir"
pushd "$tmpdir"
IPFS_BIN=$(which ipfs)
if [[ -e "$IPFS_BIN" ]]; then
cp "$IPFS_BIN" ipfs
fi
echo Collecting goroutine stacks
curl -o goroutines.stacks "http://$HTTP_API"'/debug/pprof/goroutine?debug=2'
echo Collecting goroutine profile
go tool pprof -symbolize=remote -svg -output goroutine.svg "http://$HTTP_API/debug/pprof/goroutine"
echo Collecting heap profile
go tool pprof -symbolize=remote -svg -output heap.svg "http://$HTTP_API/debug/pprof/heap"
echo "Collecting cpu profile (~30s)"
go tool pprof -symbolize=remote -svg -output cpu.svg "http://$HTTP_API/debug/pprof/profile"
echo "Enabling mutex profiling"
curl -X POST -v "http://$HTTP_API"'/debug/pprof-mutex/?fraction=4'
echo "Waiting for mutex data to be updated (30s)"
sleep 30
curl -o mutex.txt "http://$HTTP_API"'/debug/pprof/mutex?debug=2'
go tool pprof -symbolize=remote -svg -output mutex.svg "http://$HTTP_API/debug/pprof/mutex"
echo "Disabling mutex profiling"
curl -X POST -v "http://$HTTP_API"'/debug/pprof-mutex/?fraction=0'
popd
tar cvzf "./ipfs-profile-$(uname -n)-$(date +'%Y-%m-%dT%H:%M:%S%z').tar.gz" -C "$tmpdir" .
rm -rf "$tmpdir"