Skip to content

Commit a2fcb5f

Browse files
committed
Add a convenience wrapper for profiling and tracing Go tests.
1 parent 957d13a commit a2fcb5f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

etc/profile-test.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
# Convenience wrapper for profiling and tracing Go tests.
3+
set -eu
4+
5+
# Set the prompt for the select menu.
6+
PS3="Choose a profile type: "
7+
8+
options=("cpu" "mem" "block" "mutex" "trace")
9+
10+
select choice in "${options[@]}"
11+
do
12+
case $choice in
13+
"cpu" | "mem" | "block" | "mutex")
14+
tmpfile=$(mktemp)
15+
echo "Writing $choice profile to $tmpfile"
16+
17+
go test -${choice}profile ${tmpfile} "$@"
18+
go tool pprof -http=: ${tmpfile}
19+
break
20+
;;
21+
"trace")
22+
tmpfile=$(mktemp)
23+
echo "Writing trace to $tmpfile"
24+
25+
go test -trace ${tmpfile} "$@"
26+
go tool trace ${tmpfile}
27+
break
28+
;;
29+
*)
30+
echo "Invalid option. Please try again."
31+
;;
32+
esac
33+
done

0 commit comments

Comments
 (0)