-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.sh
executable file
·294 lines (235 loc) · 10.6 KB
/
tests.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
#!/bin/sh
set -e
set -x
MM=./multimonitor_ldc
sleep 3600 &
PIDA=$!
trap "kill -9 $PIDA || true" EXIT
sleep 3600 &
PIDB=$!
trap "kill -9 $PIDA $PIDB || true" EXIT
sleep 3600 &
PIDC=$!
trap "kill -9 $PIDA $PIDB $PIDC || true" EXIT
stress-ng --cpu 1 --timeout 3600s &
PIDD=$!
trap "kill -9 $PIDA $PIDB $PIDC $PIDD || true" EXIT
sleep 8 # Sometimes if the system is loaded, it can take some time for the stress-ng-cpu to initialize.
PIDE=$(pidof 'stress-ng-cpu [run]')
trap "kill -9 $PIDA $PIDB $PIDC $PIDD $PIDE || true" EXIT
# TODO(baryluk): Spawn some processes with known CPU and Memory behaviour.
# Do a complex test first, so it catches quickly a lot of issues.
"${MM}" --interval_msec=100 --duration_sec=4 \
--sub "exec sleep 2" \
--sub "exec sleep 20" \
--pipe "while sleep 1; do echo \"\$(date '+P_%s.%N')\"; done" \
--exec "date '+S_%s.%N'" \
--exec_async "date '+A_%s.%N'" \
--async_delay_msec=500 \
--pid $PIDA --pid $PIDE --pids "$PIDA,$PIDB,$PIDC" \
--loadavg=max \
--vm \
--io=max \
--net=max \
--gpu=max
# Help tests.
"${MM}" 2>&1 | grep "^Multimonitor - sample information about system and processes" >/dev/null
"${MM}" --help | grep "^Multimonitor - sample information about system and processes" >/dev/null
"${MM}" -h | grep "^Multimonitor - sample information about system and processes" >/dev/null
# No monitor, just timestamps until duration.
"${MM}" --duration_sec=2
"${MM}" --interval_msec=1000 --duration_sec=2
# Monitor process by pids.
"${MM}" --interval_msec=1000 --duration_sec=2 --pids $PIDE
# Monitor process by pid.
"${MM}" --interval_msec=1000 --duration_sec=2 --pid $PIDE
# Monitor process by name.
"${MM}" --interval_msec=1000 --duration_sec=2 --process "stress-ng-cpu [run]"
# Monitor same process one by pid, and one by name.
"${MM}" --interval_msec=1000 --duration_sec=2 --pid $PIDA --process "stress-ng-cpu [run]"
# Monitor same process many times, in multiple ways.
"${MM}" --interval_msec=1000 --duration_sec=2 --pids $PIDA,$PIDB,$PIDA,$PIDD,$PIDE --pid $PIDA --pid $PIDA --pid $PIDE
# ISO 8601
"${MM}" --interval_msec=1000 --duration_sec=2 --pids $PIDE --utc_nice
# Human unfriently and human friendly.
"${MM}" --interval_msec=1000 --duration_sec=2 --pids $PIDE --human_friendly=false
"${MM}" --interval_msec=1000 --duration_sec=2 --pids $PIDE --human_friendly=true
# Buffer output.
"${MM}" --interval_msec=1000 --duration_sec=2 --pids $PIDE --buffered
"${MM}" --interval_msec=1000 --duration_sec=2 --pids $PIDE --buffered --human_friendly=false
# No monitor. Just timestamps, until duration.
"${MM}" --interval_msec=1000 --duration_sec=3
"${MM}" --interval_msec=10 --duration_sec=2
# Loadavg stuff.
"${MM}" --duration_sec=2 --loadavg=min
"${MM}" --duration_sec=2 --loadavg=med
"${MM}" --duration_sec=2 --loadavg=max
"${MM}" --duration_sec=2 --loadavg=none
# GPU stuff.
"${MM}" --gpu=min --interval_msec=1000 --duration_sec=3
"${MM}" --gpu=min --interval_msec=10 --duration_sec=2
"${MM}" --duration_sec=2 --gpu=min
"${MM}" --duration_sec=2 --gpu=med
"${MM}" --duration_sec=2 --gpu=max
"${MM}" --duration_sec=2 --gpu=none
"${MM}" --duration_sec=2 --gpu=min --human_friendly=false
"${MM}" --duration_sec=2 --gpu=med --human_friendly=false
"${MM}" --duration_sec=2 --gpu=max --human_friendly=false
"${MM}" --duration_sec=2 --gpu=none --human_friendly=false
# IO stuff.
"${MM}" --duration_sec=2 --io=min
"${MM}" --duration_sec=2 --io=max
"${MM}" --duration_sec=2 --io=none
"${MM}" --duration_sec=2 --io=min --human_friendly=false
"${MM}" --duration_sec=2 --io=max --human_friendly=false
"${MM}" --duration_sec=2 --io=none --human_friendly=false
# Net stuff.
"${MM}" --duration_sec=2 --net=min
"${MM}" --duration_sec=2 --net=med
"${MM}" --duration_sec=2 --net=max
"${MM}" --duration_sec=2 --net=none
"${MM}" --duration_sec=2 --net=min --human_friendly=false
"${MM}" --duration_sec=2 --net=med --human_friendly=false
"${MM}" --duration_sec=2 --net=max --human_friendly=false
"${MM}" --duration_sec=2 --net=none --human_friendly=false
# One sync.
"${MM}" --interval_msec=100 --duration_sec=2 --exec "date +S1_%s.%N"
# Two sync.
"${MM}" --interval_msec=100 --duration_sec=2 --exec "date +S1_%s.%N" --exec "date +S2_%s.%N"
# Sync and async.
"${MM}" --interval_msec=100 --duration_sec=2 --exec "date +S1_%s.%N" --exec_async "date +A1_%s.%N"
# Sync and two async.
"${MM}" --interval_msec=100 --duration_sec=2 --exec "date +S1_%s.%N" --exec_async "date +A1_%s.%N" --exec_async "date +A2_%s.%N"
# Sync and async, with slow updates.
"${MM}" --interval_msec=100 --duration_sec=2 --exec "date +S1_%s.%N" --exec_async "date +A1_%s.%N" --async_delay_msec=1000
# Slow async.
"${MM}" --interval_msec=100 --duration_sec=5 --exec "date +S1_%s.%N" --exec_async "sleep 1; date +A1_%s.%N" --async_delay_msec=200
# Slow sync.
"${MM}" --interval_msec=100 --duration_sec=5 --exec "sleep 1; date +S1_%s.%N"
# Sub process, ending after end of duration.
"${MM}" --interval_msec=100 --duration_sec=2 --sub "exec sleep 10"
# Sub process, ending before end of duration.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2"
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --exit_when_dead=false
# Sub process, ending prematurely, and exiting then.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --exit_when_dead=true
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --exit_when_dead
# Two sub-processes, one ending before duration, one ending after duration.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --sub "exec sleep 20"
# Two sub-processes, one ending before duration, one ending after duration. Terminate as soon as any process finishes (dead or zombie).
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --sub "exec sleep 20" --exit_when_dead=true
# Pipe that starts producing with a delay
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --sub "exec sleep 20" --pipe "while sleep 1; do echo \"\$(date +P_%s.%N)\"; done"
# Pipe that starts producing immedietly
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --sub "exec sleep 20" --pipe "while true; do echo \"\$(date +P_%s.%N)\"; sleep 1; done"
# Slow pipe producer, but trying to consume fast in async wrapper, faster than interval.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --sub "exec sleep 20" --async_delay_msec=5 --pipe "while sleep 1; do echo \"\$(date +P_%s.%N)\"; done"
# Super fast pipe producer, and reading fast, but droppping thing.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --sub "exec sleep 20" --async_delay_msec=5 --pipe "while true; do echo \"\$(date +P_%s.%N)\"; done"
# We don't need this echo thing.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --sub "exec sleep 20" --async_delay_msec=5 --pipe "while true; do date +P_%s.%N; sleep 1; done"
# Pipe that starts producing immedietly, produces for a bit, then stops.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 2" --sub "exec sleep 20" --pipe "for i in \$(seq 5); do echo \"\$(date +P_%s.%N)\"; sleep 1; done; echo BOOM; sleep 1; exit 1"
# Test dying pipe.
"${MM}" --interval_msec=100 --duration_sec=10 --pipe "echo A1; sleep 1; echo A2; sleep 1; echo A3; sleep 1; echo A4; sleep 1; echo BOOM; exit 1"
# Test invalid pipe.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 20" --pipe "while aklsjdlkj"
# Test command with comma.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "exec sleep 3; echo a,basdas,casdas"
# Test pure-shell work in sub. One doing a lot of CPU, and pipe writes, one just spinning, and one forking a lot.
"${MM}" --interval_msec=100 --duration_sec=10 --sub "while :; do echo asd; done > /dev/null" --sub "while :; do :; done" --sub "while :; do /bin/true; done >/dev/null"
# Monitor gpu and sub-process.
"${MM}" --interval_msec=100 --duration_sec=2 --sub "exec sleep 10" --gpu=min
# Sub-process monitor, then kill mm, before end of duration or sub-process finishes.
"${MM}" --interval_msec=100 --duration_sec=20 --sub "exec sleep 10" &
MMPID=$!
sleep 2
kill $MMPID
# Monitor by pid, then kill mm before end of duration.
"${MM}" --interval_msec=100 --duration_sec=20 --pid $PIDE &
MMPID=$!
sleep 2
kill $MMPID
echo "Waiting for $MMPID"
wait $MMPID || true
# TODO(baryluk): Detect sub-processes in --sub, --exec and --pipe terminating.
# For example if --pipe has incorrect format, we should not even start logging.
# If the first sample works, and fails later, we shall instead continue,
# display nan or something, emit stuff to stderr, or restart or termina also.
# (Depending on options).
# Cleanup.
kill $PIDA
echo "Waiting for $PIDA"
wait $PIDA || true
kill $PIDB
echo "Waiting for $PIDB"
wait $PIDB || true
kill $PIDC
echo "Waiting for $PIDC"
wait $PIDC || true
kill $PIDD
echo "Waiting for $PIDD"
wait $PIDD || true
kill $PIDE || true
echo "Waiting for $PIDE"
wait $PIDE || true
# Monitor by pid, kill monitored process before end of duration, then kill mm before id finishes.
sleep 3600 &
PIDA=$!
"${MM}" --interval_msec=500 --duration_sec=10 --pid $PIDA &
MMPID=$!
echo Sleeping
sleep 1
echo Sleeping
sleep 1
echo Sleeping
sleep 1
kill $PIDA
sleep 1
kill -9 $PIDA || true
echo "Waiting for $PIDA"
wait $PIDA || true
echo Sleeping
sleep 1
echo Sleeping
sleep 1
#kill $MMPID
echo "Waiting for $MMPID"
wait $MMPID || true
# Monitor by pid, kill monitored process before end of duration. mm should also finish due to --exit_when_dead. Then kill mm just for a good measure.
sleep 3600 &
PIDA=$!
"${MM}" --interval_msec=500 --duration_sec=10 --exit_when_dead=true --pid $PIDA &
MMPID=$!
echo Sleeping
sleep 1
echo Sleeping
sleep 1
echo Sleeping
sleep 1
kill $PIDA
sleep 1
kill -9 $PIDA || true
echo "Waiting for $PIDA"
wait $PIDA || true
echo Sleeping
sleep 1
echo Sleeping
sleep 1
#kill $MMPID
echo "Waiting for $MMPID"
wait $MMPID || true
# --DRT-gcopt=parallel:2
# --DRT-gcopt=parallel:0
# --DRT-scanDataSeg=precise
# --DRT-scanDataSeg=conservative
# "--DRT-gcopt=gc:precise cleanup:none"
# "--DRT-gcopt=gc:precise profile:1"
# TODO: --sub_pipe : Start sub-process, monitor it, but also receive its output and display as a column next to it.
# This could be really handy to transport back some extra metrics from the app.
# The app doesn't nacissarly need to even do it, but instead spawn a subprocess that does something
# to monitor something, and just put it on stdout. Becuase child will write to pipe too. I think.
# $ ./multimonitor_ldc --pid -5
# std.conv.ConvException@/usr/lib/ldc/x86_64-linux-gnu/include/d/std/conv.d(2382): Unexpected '-' when converting from type string to type uint
# $ ./multimonitor_ldc --pid 0
# [email protected](361): Can't open stat file for pid 0