-
Notifications
You must be signed in to change notification settings - Fork 3
/
tracer-client
executable file
·287 lines (251 loc) · 8.76 KB
/
tracer-client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/bash
exec >tracer-client-stderrout.txt
exec 2>&1
. /usr/bin/tracer-base || (echo "/usr/bin/tracer-base not found"; exit 1)
dump_runtime
validate_label
validate_sw_prereqs
if [ -z "${WORKLOAD_CPUS}" ]; then
exit_error "WORKLOAD_CPUS is not defined. This must be defined to run tracer"
else
echo "WORKLOAD_CPUS: ${WORKLOAD_CPUS}"
fi
if [ -z "${HK_CPUS}" ]; then
exit_error "HK_CPUS is not defined. This must be defined to run tracer"
else
echo "HK_CPUS: ${HK_CPUS}"
fi
# defaults
duration=60
tracer=osnoise
longopts="duration:,tracer:,period:,runtime:,us_single:,us_total:,threshold:,stack:,cpu:,events:"
opts=$(getopt -q -o "d:t:p:r:u:U:T:s:c:" --longoptions "$longopts" -n "getopt.sh" -- "$@");
eval set -- "$opts";
while true; do
case "$1" in
-d|--duration)
shift
duration=$1
shift
;;
-t|--tracer)
shift
tracer=$1
shift
;;
-p|--period)
shift
period=$1
shift
;;
-r|--runtime)
shift
runtime=$1
shift
;;
-u|--us_single)
shift
us_single=$1
shift
;;
-U|--us_total)
shift
us_total=$1
shift
;;
-T|--threshold)
shift
threshold=$1
shift
;;
-s|--stack)
shift
stack=$1
shift
;;
-c|--cpu)
shift
cpu=$1
shift
;;
--events)
shift
event=$1
shift
;;
--)
shift;
break
;;
*)
shift
;;
esac
done
case "${tracer}" in
osnoise|timerlat)
echo "Running in ${tracer} mode"
;;
*)
exit_error "Invalid tracer mode (${tracer})"
;;
esac
{
data_dir=$(pwd)
if [ -d /tmp/sys/kernel/debug/tracing ]; then
TRACING_DIR=/tmp/sys/kernel/debug/tracing
else TRACING_DIR=/sys/kernel/debug/tracing
fi
if pushd ${TRACING_DIR} > /dev/null; then
echo "${tracer}" > current_tracer
echo "tracer: $(cat current_tracer)"
echo
echo "WORKLOAD_CPUS: ${WORKLOAD_CPUS}"
echo
# convert ${WORKLOAD_CPUS} into a hex cpu mask using toolbox
cpumask=$(${TOOLBOX_HOME}/bin/cpumask.py --cpus ${WORKLOAD_CPUS} | grep hexmask | cut -d'=' -f 2)
echo "${cpumask}" > tracing_cpumask
echo "tracing_cpumask: $(cat tracing_cpumask)"
echo
# clear the trace buffer
echo > trace
IFS=','
read -a eventarray <<< "$event"
echo "Found ${#eventarray[*]} tracepoints:"
for tracepoint in "${eventarray[@]}"; do
printf "Enabling tracepoint $tracepoint\n"
if [ -e events/osnoise/$tracepoint/enable ]; then
echo 1 > events/osnoise/$tracepoint/enable
elif [ ${tracepoint} == 'osnoise' ] && [ -e events/osnoise/enable ]; then
echo 1 > events/osnoise/enable
else
echo "Cound not find/enable tracepoint $tracepoint"
fi
done
IFS=' '
if [ ${period} ] && [ ${tracer} == 'osnoise' ]; then
previous_period=`cat osnoise/period_us`
echo "Setting osnoise/period_us to '$period' for tracer osnoise"
echo $period > osnoise/period_us
elif [ ${period} ] && [ ${tracer} == 'timerlat' ]; then
previous_period=`cat osnoise/timerlat_period_us`
echo "Setting osnoise/timerlat_period_us to '$period' for tracer timerlat"
echo $period > osnoise/timerlat_period_us
else echo "no valid path to set period because the tracer is neither osnoise or timerlat!"
fi
# the paths for single noise and total noise differ between kernels 4.x and 5.x
if [ ${us_single} ] && [ -d osnoise/stop_tracing_us ]; then
previous_us_single=`cat osnoise/stop_tracing_us`
echo "Setting osnoise/stop_tracing_us to '$us_single'"
echo $us_single > osnoise/stop_tracing_us
elif [ ${us_single} ] && [ -d osnoise/stop_tracing_in_us ]; then
previous_us_single=`cat osnoise/stop_tracing_in_us`
echo "Setting osnoise/stop_tracing_in_us to '$us_single'"
echo $us_single > osnoise/stop_tracing_in_us
fi
if [ ${us_total} ] && [ -d osnoise/stop_tracing_total_us ]; then
previous_us_total=`cat osnoise/stop_tracing_total_us`
echo "Setting osnoise/stop_tracing_total_us to '$us_total'"
echo $us_total > osnoise/stop_tracing_total_us
elif [ ${us_total} ] && [ -d osnoise/stop_tracing_out_us ]; then
previous_us_total=`cat osnoise/stop_tracing_out_us`
echo "Setting osnoise/stop_tracing_out_us to '$us_total'"
echo $us_total > osnoise/stop_tracing_out_us
fi
if [ ${runtime} ]; then
previous_runtime=`cat osnoise/runtime_us`
echo "setting osnoise/runtime_us to '$runtime'"
echo "$runtime" > osnoise/runtime_us
fi
if [ ${threshold} ] && [ -d osnoise/tracing_threshold ]; then
previous_threshold=`cat osnoise/tracing_threshold`
echo "setting osnoise/tracing_threshold to '$threshold'"
echo "$threshold" > osnoise/tracing_threshold
fi
if [ ${stack} ]; then
previous_stack=`cat osnoise/print_stack`
echo "setting osnoise/print_stack to '$stack'"
echo "$stack" > osnoise/print_stack
fi
echo
case "${tracer}" in
osnoise|timerlat)
echo "${tracer} config:"
more osnoise/*
echo
;;
esac
# critical section begin
date +%s.%N >${data_dir}/begin.txt
echo 1 > tracing_on
sleep ${duration}
echo 0 > tracing_on
date +%s.%N >${data_dir}/end.txt
# critical section end
echo "BEGIN: $(cat ${data_dir}/begin.txt)"
echo "END: $(cat ${data_dir}/end.txt)"
echo
echo "TRACE:"
if [ -z ${cpu} ]; then
cat trace
else
cat per_cpu/cpu${cpu}/trace
fi
# clear the trace buffer
echo > trace
IFS=','
read -a eventarray <<< "$event"
for tracepoint in "${eventarray[@]}"; do
printf "Disabling tracepoint $tracepoint\n"
if [ -e events/osnoise/$tracepoint/enable ]; then
echo 0 > events/osnoise/$tracepoint/enable
elif [ ${tracepoint} == 'osnoise' ] && [ -e events/osnoise/enable ]; then
echo 0 > events/osnoise/enable
else
echo "Cound not find/disable tracepoint $tracepoint"
fi
done
IFS=' '
if [ ${previous_period} ] && [ ${tracer} == 'osnoise' ]; then
echo "Restoring osnoise/period_us to '$previous_period' for tracer osnoise"
echo $previous_period > osnoise/period_us
elif [ ${previous_period} ] && [ ${tracer} == 'timerlat' ]; then
echo "Restoring osnoise/timerlat_period_us to '$previous_period' for tracer timerlat"
echo $previous_period > osnoise/timerlat_period_us
fi
# the paths for single noise and total noise differ between kernels 4.x and 5.x
if [ ${previous_us_single} ] && [ -d osnoise/stop_tracing_us ]; then
echo "Restoring osnoise/stop_tracing_us to '$previous_us_single'"
echo $previous_us_single > osnoise/stop_tracing_us
elif [ ${previous_us_single} ] && [ -d osnoise/stop_tracing_in_us ]; then
echo "Restoring osnoise/stop_tracing_in_us to '$previous_us_single'"
echo $previous_us_single > osnoise/stop_tracing_in_us
fi
if [ ${previous_us_total} ] && [ -d osnoise/stop_tracing_total_us ]; then
echo "Restoring osnoise/stop_tracing_total_us to '$previous_us_total'"
echo $previous_us_total > osnoise/stop_tracing_total_us
elif [ ${previous_us_total} ] && [ -d osnoise/stop_tracing_out_us ]; then
echo "Restoring osnoise/stop_tracing_out_us to '$previous_us_total'"
echo $previous_us_total > osnoise/stop_tracing_out_us
fi
if [ ${previous_runtime} ]; then
echo "Restoring osnoise/runtime_us to '$previous_runtime'"
echo "$previous_runtime" > osnoise/runtime_us
fi
if [ ${previous_threshold} ]; then
echo "Restoring osnoise/tracing_threshold to '$previous_threshold'"
echo "$previous_threshold" > osnoise/tracing_threshold
fi
if [ ${previous_stack} ]; then
echo "Restoring osnoise/print_stack to '$previous_stack'"
echo "$previous_stack" > osnoise/print_stack
fi
popd > /dev/null
else
exit_error "Failed to pushd to ${TRACING_DIR}"
fi
} > tracer-run-stderrout.txt 2>&1
rc=0
if [ ${rc} -gt 0 ]; then
exit_error "`cat tracer-run-stderrout.txt`"
fi