File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 2
2
# Convenience wrapper for profiling and tracing Go tests.
3
3
set -eu
4
4
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
7
9
10
+ # Set the prompt and options for the select menu.
11
+ PS3=" Choose a profile type: "
8
12
options=(" cpu" " mem" " block" " mutex" " trace" )
9
13
10
14
select choice in " ${options[@]} "
11
15
do
12
16
case $choice in
13
17
" cpu" | " mem" | " block" | " mutex" )
14
- tmpfile=$( mktemp)
15
18
echo " Writing $choice profile to $tmpfile "
16
19
17
20
go test -${choice} profile ${tmpfile} " $@ "
18
21
go tool pprof -http=: ${tmpfile}
19
22
break
20
23
;;
21
24
" trace" )
22
- tmpfile=$( mktemp)
23
25
echo " Writing trace to $tmpfile "
24
26
25
27
go test -trace ${tmpfile} " $@ "
You can’t perform that action at this time.
0 commit comments