Skip to content

Commit f4c2dca

Browse files
committed
valgrind tool cli arg
1 parent 89c15fa commit f4c2dca

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

valgrind.sh

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,43 @@ fi
99

1010
source lib/lib.sh
1111

12+
arg_tool=massif
13+
14+
for arg in "$@"
15+
do
16+
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]
17+
then
18+
echo "usage: ./valgrind.sh [OPTION]"
19+
echo "options:"
20+
echo " --tool=massif use valgrinds massif tool"
21+
echo " --tool=memcheck use valgrinds memcheck tool"
22+
echo " default tool: $arg_tool"
23+
exit 0
24+
elif [ "${arg::2}" == "--" ]
25+
then
26+
if [[ "$arg" == "--tool="* ]]
27+
then
28+
arg_tool="$(printf '%s' "$arg" | cut -d= -f2-)"
29+
if [ "$arg_tool" = massif ]
30+
then
31+
true
32+
elif [ "$arg_tool" = memcheck ]
33+
then
34+
true
35+
else
36+
err "Invalid valgrind tool '$arg_tool'"
37+
exit 1
38+
fi
39+
else
40+
err "invalid argument '$arg' see '--help'"
41+
exit 1
42+
fi
43+
else
44+
err "unexpected argument '$arg' see '--help'"
45+
exit 1
46+
fi
47+
done
48+
1249
check_deps "$1"
1350
check_warnings
1451
check_running
@@ -61,10 +98,9 @@ then
6198
log_cmd="logfile $logfile"
6299
fi
63100

64-
valgrind_tool=massif
65101
run_cmd=noop
66102

67-
if [ "$valgrind_tool" = "massif" ]
103+
if [ "$arg_tool" = "massif" ]
68104
then
69105
massif_logpath="logs/massif_${COMMIT_HASH:-null}_$(date '+%F_%H-%M').out.txt"
70106

@@ -82,7 +118,7 @@ then
82118
--massif-out-file=$massif_logpath \
83119
./$CFG_BIN -f autoexec.cfg "$log_cmd;#sid:$SERVER_UUID:valgrind.sh"
84120
EOF
85-
elif [ "$valgrind_tool" = "memcheck" ]
121+
elif [ "$arg_tool" = "memcheck" ]
86122
then
87123
read -rd '' run_cmd <<- EOF
88124
$CFG_ENV_RUNTIME valgrind \
@@ -94,7 +130,8 @@ then
94130
./$CFG_BIN -f autoexec.cfg "$log_cmd;#sid:$SERVER_UUID:valgrind.sh"
95131
EOF
96132
else
97-
err "Error: unsupported valgrind tool '$valgrind_tool'"
133+
err "Error: unsupported valgrind tool '$arg_tool'"
134+
exit 1
98135
fi
99136

100137
log "$run_cmd"
@@ -107,7 +144,7 @@ then
107144
log "applied patches: $git_patches"
108145
fi
109146

110-
if [ "$valgrind_tool" = "massif" ]
147+
if [ "$arg_tool" = "massif" ]
111148
then
112149
log "created massif report at $massif_logpath"
113150
log "you can inspect it using this command:"

0 commit comments

Comments
 (0)