From e575c93dcd4b6f6254b1a0110b26bbf1d305eb61 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 5 Mar 2019 12:57:16 +0100 Subject: [PATCH] misc: add collect-profiles.sh script, update gitignore License: MIT Signed-off-by: Jakub Sztandera --- .gitignore | 2 ++ bin/collect-profiles.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 bin/collect-profiles.sh diff --git a/.gitignore b/.gitignore index 1e21b5cc2fe..9ead6675ade 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ gx-workspace-update.json bin/gx bin/gx* bin/tmp +bin/gocovmerge +bin/cover vendor diff --git a/bin/collect-profiles.sh b/bin/collect-profiles.sh new file mode 100644 index 00000000000..e1f80cd32c9 --- /dev/null +++ b/bin/collect-profiles.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -x +set -euo pipefail +IFS=$'\n\t' + +HTTP_API="${1:-localhost:5001}" +tmpdir=$(mktemp -d) +export PPROF_TMPDIR="$tmpdir" +pushd "$tmpdir" + +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 -Iseconds).tar.gz" -C "$tmpdir" . +rm -rf "$tmpdir" + + + +