-
Notifications
You must be signed in to change notification settings - Fork 4
/
kerneltools-start
executable file
·197 lines (187 loc) · 6.87 KB
/
kerneltools-start
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
#!/bin/bash
# -*- mode: sh; indent-tabs-mode: nil; sh-basic-offset: 4 -*-
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=bash
exec >kerneltools-start-stderrout.txt
exec 2>&1
echo "args:"
for i in "$@"; do
printf "[%s]\n" "$i"
done
echo
echo "pwd: `/bin/pwd`"
echo
echo "hostname: `hostname`"
echo
echo "mount:"
mount
echo
# defaults
subtools="turbostat" # subtools that will be used, any combination of: turbostat,perf,speed-select-util,trace-cmd,sysfs-trace <no-spaces>
interval=10
record_opts=""
base_freq=""
core_power=""
turbo_freq=""
trace_cmd_record_opts=""
sysfs_trace_setup_cmds=()
echo "Processing arguments"
longopts="subtools:,record-opts:,interval:,base-freq:,turbo-freq:,core-power:,trace-cmd-record-opts:,sysfs-trace-setup:,sysfs-trace-cleanup:"
opts=$(getopt -q -o "" --longoptions "$longopts" -n "getopt.sh" -- "$@");
eval set -- "$opts";
while true; do
arg="$1"
shift
val="$1"
shift
printf "arg: [%s] val: [%s]\n" "$arg" "$val"
case "$arg" in
--sysfs-trace-cleanup)
;;
--sysfs-trace-setup)
sysfs_trace_setup_cmds+=("$val")
echo "appending '$val' to sysfs_trace_setup_cmds"
;;
--subtools)
subtools=$val
echo "setting subtools=$subtools"
;;
--record-opts)
record_opts=$val
echo "setting record_opts=$record_opts"
;;
--base-freq)
base_freq=$val
echo "setting base_freq=$base_freq"
;;
--core-power)
core_power=$val
echo "setting core_power=$core_power"
;;
--turbo-freq)
turbo_freq=$val
echo "setting turbo_freq=$turbo_freq"
;;
--interval)
interval=$val
echo "setting turbo_freq=$turbo_freq"
;;
--trace-cmd-record-opts)
trace_cmd_record_opts=$val
echo "setting trace_cmd_record_opts=$trace_cmd_record_opts"
;;
--)
break
;;
*)
echo "Invalid option: $arg"
exit 1
esac
done
/bin/rm -f kerneltools-pids.txt
for subtool in `echo $subtools | sed -e 's/,/ /g'`; do
case "$subtool" in
perf)
echo "Starting perf record"
mkdir -p ~/.debug
cmd="/usr/bin/perf record -a $record_opts"
time=$(date -u --date="$(TZ=UTC uptime -s)" +%s)
echo "uptime as seconds since epoch: $time"
echo "Going to run $cmd"
$cmd &
perf_pid=$!
echo "perf pid is $perf_pid"
echo "$perf_pid" >>kerneltools-pids.txt
;;
turbostat)
echo "Starting turbostat"
nohup /usr/bin/turbostat -d -d -i $interval -o turbostat-stdout.txt 2>turbostat-stderr.txt &
turbo_pid=$!
echo "turbostat pid is $turbo_pid"
echo "$turbo_pid" >>kerneltools-pids.txt
;;
intel-speed-select)
echo "invoking intel-speed-select"
# get the settings before we change anything
/usr/bin/intel-speed-select perf-profile info -l 0 |& grep speed-select|grep ":"|sort|uniq >settings.txt
if [ ! -z "$base_freq" ]; then
if [ "$base_freq" == "enable" ]; then
echo "running: /usr/bin/intel-speed-select base-freq enable -a"
/usr/bin/intel-speed-select base-freq enable -a
elif [ "$base_freq" == "disable" ]; then
echo "running: /usr/bin/intel-speed-select base-freq disable -a"
/usr/bin/intel-speed-select base-freq disable -a
else
echo "The value for argument --base-freq [$base_freq] is not supported"
fi
fi
if [ ! -z "$core_power" ]; then
if [ "$core_power" == "enable" ]; then
echo "running: /usr/bin/intel-speed-select core-power enable -a"
/usr/bin/intel-speed-select core-power enable -a
elif [ "$core_power" == "disable" ]; then
echo "running: /usr/bin/intel-speed-select core-power disable -a"
/usr/bin/intel-speed-select core-power disable -a
else
echo "The value for argument --core-power [$core_power] is not supported"
fi
fi
if [ ! -z "$turbo_freq" ]; then
if [ "$turbo_freq" == "enable" ]; then
echo "running: /usr/bin/intel-speed-select turbo-freq enable -a"
/usr/bin/intel-speed-select turbo-freq enable -a
elif [ "$turbo_freq" == "disable" ]; then
echo "running: /usr/bin/intel-speed-select turbo-freq disable -a"
/usr/bin/intel-speed-select turbo-freq disable -a
else
echo "The value for argument --turbo-freq [$turbo_freq] is not supported"
fi
fi
for i in info get-lock-status get-config-levels get-config-version get-config-enabled get-config-current-level; do
/usr/bin/intel-speed-select perf-profile $i >perf-profile_$i.txt 2>&1
done
;;
trace-cmd)
echo "Starting trace-cmd"
echo "Available trace-cmd tracers:"
/usr/local/bin/trace-cmd list -t
echo "Starting function trace with functions: $trace_cmd_functions"
cmd="/usr/local/bin/trace-cmd record --date"
cmd+=" $trace_cmd_record_opts"
echo "Going to run:"
echo "$cmd"
$cmd &
trace_pid=$!
echo "trace-cmd pid is $trace_pid"
echo "$trace_pid" >>kerneltools-pids.txt
;;
sysfs-trace)
echo "Making sure debugfs is mounted"
mount --verbose --type debugfs none /sys/kernel/debug
echo "Configuring sysfs-trace"
if pushd /sys/kernel/debug/tracing > /dev/null; then
echo "Making sure tracing is really off"
echo 0 > tracing_on
echo "Clearing existing trace buffers"
echo > trace
echo "Executing sysfs-trace-setup commands:"
for val in "${sysfs_trace_setup_cmds[@]}"; do
echo "Running '${val}'"
eval ${val}
RC=$?
if [ "${RC}" != "0" ]; then
echo "ERROR: Command returned '${RC}'"
exit ${RC}
fi
done
popd > /dev/null
else
echo "ERROR: Is tracing enabled?"
exit 1
fi
touch kerneltools-pids.txt
;;
*)
echo "Invalid subtool: $subtool"
;;
esac
done