File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ # Convenience wrapper for profiling and tracing Go tests.
3+ set -eu
4+
5+ # Create a temporary file to store the profile or trace data. Trap the exit
6+ # signals to clean it up after the script exits (typically via Ctrl-C).
7+ tmpfile=$( mktemp)
8+ trap ' rm -f "$tmpfile"' EXIT INT TERM
9+
10+ # Set the prompt and options for the select menu.
11+ PS3=" Choose a profile type: "
12+ options=(" cpu" " mem" " block" " mutex" " trace" )
13+
14+ select choice in " ${options[@]} "
15+ do
16+ case $choice in
17+ " cpu" | " mem" | " block" | " mutex" )
18+ echo " Writing $choice profile to $tmpfile "
19+
20+ go test -${choice} profile ${tmpfile} " $@ "
21+ go tool pprof -http=: ${tmpfile}
22+ break
23+ ;;
24+ " trace" )
25+ echo " Writing trace to $tmpfile "
26+
27+ go test -trace ${tmpfile} " $@ "
28+ go tool trace ${tmpfile}
29+ break
30+ ;;
31+ * )
32+ echo " Invalid option. Please try again."
33+ ;;
34+ esac
35+ done
You can’t perform that action at this time.
0 commit comments