Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions etc/profile-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
# Convenience wrapper for profiling and tracing Go tests.
set -eu

# Create a temporary file to store the profile or trace data. Trap the exit
# signals to clean it up after the script exits (typically via Ctrl-C).
tmpfile=$(mktemp)
trap 'rm -f "$tmpfile"' EXIT INT TERM

# Set the prompt and options for the select menu.
PS3="Choose a profile type: "
options=("cpu" "mem" "block" "mutex" "trace")

select choice in "${options[@]}"
do
case $choice in
"cpu" | "mem" | "block" | "mutex")
echo "Writing $choice profile to $tmpfile"

go test -${choice}profile ${tmpfile} "$@"
go tool pprof -http=: ${tmpfile}
break
;;
"trace")
echo "Writing trace to $tmpfile"

go test -trace ${tmpfile} "$@"
go tool trace ${tmpfile}
break
;;
*)
echo "Invalid option. Please try again."
;;
esac
done
Loading