Skip to content

Commit 80c3f56

Browse files
committed
Clean up temp file after the script exits.
1 parent a2fcb5f commit 80c3f56

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

etc/profile-test.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@
22
# Convenience wrapper for profiling and tracing Go tests.
33
set -eu
44

5-
# Set the prompt for the select menu.
6-
PS3="Choose a profile type: "
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
79

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

1014
select choice in "${options[@]}"
1115
do
1216
case $choice in
1317
"cpu" | "mem" | "block" | "mutex")
14-
tmpfile=$(mktemp)
1518
echo "Writing $choice profile to $tmpfile"
1619

1720
go test -${choice}profile ${tmpfile} "$@"
1821
go tool pprof -http=: ${tmpfile}
1922
break
2023
;;
2124
"trace")
22-
tmpfile=$(mktemp)
2325
echo "Writing trace to $tmpfile"
2426

2527
go test -trace ${tmpfile} "$@"

0 commit comments

Comments
 (0)