-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.sh
executable file
·332 lines (263 loc) · 5.76 KB
/
util.sh
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/local/bin/bash
set -uo pipefail
clear_log()
{
echo "" > $LOG
echo "" > $LOG
}
util_check_library()
{
O1=`find "/usr/local/lib" "/usr/lib" "/lib" -name *$1*`
if [ -z "$O1" ]; then
echo "Library $1 not present locally, please install"
fi
}
util_check_binary()
{
BIN_VAR=`which $1`
if [ -z $BIN_VAR ]; then
echo "Binary $1 not present locally, please install"
exit 1
else
return
fi
}
check_completed()
{
if [ -f $1 ]; then
COUNT=$(wc -l < $1)
if [ "$COUNT" -eq "0" ]; then
return 1
fi
return 0
else
return 1
fi
}
util_setup_root()
{
FSMNT=$1
echo "[Aurora `date +'%T'`] Creating the root and installing packages"
MNT=$FSMNT installroot
cp /etc/resolv.conf $FSMNT/etc/resolv.conf
mkdir -p $MNT/packages
cp -r packages $FSMNT/packages/Latest
chroot $FSMNT /bin/sh -c 'env PACKAGESITE=file:/packages pkg bootstrap -y'
chroot $FSMNT /bin/sh -c 'IGNORE_OSVERSION=yes ASSUME_ALWAYS_YES=yes pkg add /packages/Latest/*.pkg'
echo "[Aurora `date +'%T'`] Copying over necessary files"
mkdir -p $FSMNT/usr/lib/debug/boot/modules >/dev/null
mkdir -p $FSMNT/usr/aurora/tests/posix > /dev/null
cd $SRCROOT
DESTDIR=$FSMNT make install > /dev/null
cd -
}
util_setup_aurora()
{
FSMNT=$1
INFREQUENT=$(( 10 * 1000 ))
echo "[Aurora `date +'%T'`] Loading the Aurora module"
MNT=$FSMNT aurteardown > $LOG 2> $LOG
MNT=$FSMNT aursetup
if [ $# -eq 2 ]; then
sysctl aurora_slos.checkpointtime=$2 >/dev/null 2>/dev/null
else
sysctl aurora_slos.checkpointtime=$INFREQUENT >/dev/null 2>/dev/null
fi
}
util_teardown_aurora()
{
FSMNT=$1
sleep 2
MNT=$FSMNT aurteardown > /dev/null 2> /dev/null
# We pass in DISKPATH cause destroymd requires it but aurunstripe does not require
# any arguments so does not use it.
}
util_setup_zfs()
{
FSMNT=$1
shift
set -- $@
ZFS_DISKS=""
while [ "$#" -ne 0 ];
do
ZFS_DISKS="/dev/$1 ${ZFS_DISKS}"
shift
done
zpool create -f benchmark $ZFS_DISKS
zfs create benchmark/testmnt
zfs set mountpoint=$FSMNT benchmark/testmnt
zfs set recordsize=64k benchmark
zfs set sync=standard benchmark
zfs set checksum=off benchmark/testmnt
mkdir -p $FSMNT/dev
mkdir -p $FSMNT/proc
mount -t devfs devfs $FSMNT/dev
mount -t fdescfs fdesc $FSMNT/dev/fd
mount -t procfs proc $FSMNT/proc
}
util_teardown_zfs()
{
FSMNT=$1
umount $FSMNT/dev/fd
umount $FSMNT/dev
umount $FSMNT/proc
sync
zfs destroy -r benchmark/testmnt
zpool destroy benchmark
}
util_setup_ffs()
{
FSMNT=$1
FFSDISK=$2
newfs $FFSDISK > /dev/null
mount -t ufs $FFSDISK $FSMNT
mkdir -p $FSMNT/dev
mkdir -p $FSMNT/proc
mount -t devfs devfs $FSMNT/dev
mount -t fdescfs fdesc $FSMNT/dev/fd
mount -t procfs proc $FSMNT/proc
}
util_teardown_ffs()
{
FSMNT=$1
umount $FSMNT/dev/fd
umount $FSMNT/dev
umount $FSMNT/proc
sync
umount $FSMNT
}
util_start_dtrace()
{
DTRACEOUT="$1"
DTRACESCRIPT="$2"
PID="$3"
if [ ! -z $PID ]; then
$DTRACESCRIPT $PID > $DTRACEOUT 2> $DTRACEOUT &
else
$DTRACESCRIPT > $DTRACEOUT 2> $DTRACEOUT &
fi
}
util_stop_dtrace()
{
pkill dtrace
}
util_setup_pmcstat()
{
# Set up the performance counter module
kldload hwpmc
ln -s /boot/modules/sls.ko /boot/kernel/sls.ko
ln -s /boot/modules/slos.ko /boot/kernel/slos.ko
}
util_start_pmcstat()
{
PMCFILE=$1
pmcstat -S inst_retired.any -O $PMCFILE -n 4096 &
}
util_stop_pmcstat()
{
pkill pmcstat
sleep 1
}
util_start_pmcstat_args()
{
PMCOUT=$1
PMCARG=$2
pmcstat -S "$2" -O $PMCOUT -n 4096 &
}
util_stop_pmcstat_args()
{
PMCOUT=$1
GMONOUT=$2
pkill pmcstat
sleep 1
pmcstat -g -R $PMCOUT
mv "$3" $GMONOUT
}
util_process_pmcstat()
{
GMONDIR=$1
PMCFILE=$2
PMCTXT=$3
PMCGRAPH=$4
PMCSTACK=$5
pmcstat -g -R $PMCFILE
mv inst_retired.any $GMONDIR
# WARNING: $PMCTXT does not tell the whole story because it ignores
# all non-kernel, non-SLS objects. The $PMCGRAPH and $PMCSTACK
# outputs are more accurate.
touch $PMCTXT
echo "======================SLS=======================" >> $PMCTXT
gprof /boot/modules/sls.ko $GMONDIR/sls.ko.gmon >> $PMCTXT
echo "======================SLOS======================" >> $PMCTXT
gprof /boot/modules/slos.ko $GMONDIR/slos.ko.gmon >> $PMCTXT
echo "=====================KERNEL=====================" >> $PMCTXT
gprof /boot/kernel/kernel $GMONDIR/kernel.gmon >> $PMCTXT
# Create a deep stack trace file to get an accurate flame graph
pmcstat -R $PMCFILE -z100 -G $PMCSTACK
ln -s /usr/local/bin/perl /usr/bin/perl >/dev/null 2>/dev/null
../FlameGraph/stackcollapse-pmc.pl $PMCSTACK | ../FlameGraph/flamegraph.pl > $PMCGRAPH
rm -r $PMCSTACK
# Get a less deep file for stack tracing
pmcstat -R $PMCFILE -z5 -G $PMCSTACK
}
util_start_rusage() {
RUFILE=$1
PID=$2
touch $RUFILE
while true; do
procstat rusage $2 >> $RUFILE
sleep 1
done
}
util_stop_rusage() {
RUPID=$1
kill -SIGTERM $RUPID
}
util_start_sysctl() {
SYSCTLFILE=$1
touch $SYSCTLFILE
while true; do
sysctl aurora >> $SYSCTLFILE
sysctl aurora_slos >> $SYSCTLFILE
sleep 1
done
}
util_stop_sysctl() {
SYSCTLPID=$1
kill -SIGTERM $SYSCTLPID
}
util_aursetup_old()
{
$OLDAUR/tools/newfs_sls/newfs_sls $DISKPATH > /dev/null
kldload $OLDAUR/slos/slos.ko
mount -t slsfs $DISKPATH "$MNT"
mkdir "$MNT/dev"
mount -t devfs devfs "$MNT/dev"
kldload $OLDAUR/sls/sls.ko
}
util_aurteardown_old()
{
kldunload sls
umount "$MNT/dev"
umount "$MNT"
kldunload slos
}
util_setup_oldaurora()
{
FSMNT=$1
INFREQUENT=$(( 10 * 1000 ))
echo "[Aurora `date +'%T'`] Loading the Aurora module"
MNT=$FSMNT util_aurteardown_old > $LOG 2> $LOG
MNT=$FSMNT util_aursetup_old
if [ $# -eq 2 ]; then
sysctl aurora_slos.checkpointtime=$2 >/dev/null 2>/dev/null
else
sysctl aurora_slos.checkpointtime=$INFREQUENT >/dev/null 2>/dev/null
fi
}
util_teardown_oldaurora()
{
FSMNT=$1
sleep 2
MNT=$FSMNT util_aurteardown_old > /dev/null 2> /dev/null
}