-
Notifications
You must be signed in to change notification settings - Fork 7
/
entrypoint.sh
executable file
·63 lines (54 loc) · 1.89 KB
/
entrypoint.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
#!/bin/bash
#entrypoint.sh <stat|record|probe> <trigger[1|0]> <max-run-time[X]> <repeat-count[N]> <extra-perf-args>
PERF=/usr/bin/perf
PERF_TYPE=${1:-record}
TRIGGER=${2:-0}
TIMEOUT=${3:-60}
COUNT=${4:-1}
EXTRA_PERF_ARGS=$5
OUT_SUFFIX=${HOSTNAME:+-$HOSTNAME}
declare -a PIDS
PIDS=($(ps -A -o pid=))
#Remove last element as it's the PID of the 'ps' command
unset PIDS[-1]
echo "Monitored PIDs: " "${PIDS[*]}"
#Convert array to comma separated list
PERF_PIDS=`(IFS=$','; echo "${PIDS[*]}")`
function start_perf_stat() {
for (( i=1; i<=${COUNT}; i++ ))
do
echo "timeout -t ${TIMEOUT} ${PERF} stat -a -p $PERF_PIDS -x ',' -I 1000 -A -o /out/perf-stat-output${OUT_SUFFIX} --append ${EXTRA_PERF_ARGS}"
timeout -t ${TIMEOUT} ${PERF} stat -a -p $PERF_PIDS -x ',' -I 1000 -A -o /out/perf-stat-output${OUT_SUFFIX} --append ${EXTRA_PERF_ARGS}
done
}
function start_perf_record() {
for (( i=1; i<=${COUNT}; i++ ))
do
echo "timeout -t ${TIMEOUT} ${PERF} record -a -g -p $PERF_PIDS -o /out/perf-record-output${OUT_SUFFIX} ${EXTRA_PERF_ARGS}"
timeout -t ${TIMEOUT} ${PERF} record -a -p $PERF_PIDS -o /out/perf-record-output${OUT_SUFFIX} ${EXTRA_PERF_ARGS}
done
}
case ${PERF_TYPE} in
stat )
if [ "${TRIGGER}" == "1" ]
then
#Trigger perf collection if /tmp/startperf is present
while read i; do if [ "$i" = startperf ]; then start_perf_stat; break; fi; done \
< <(inotifywait -e create,open,modify --format '%f' --monitor /tmp)
else
start_perf_stat
fi
;;
record )
if [ "${TRIGGER}" == "1" ]
then
#Trigger perf collection if /tmp/startperf is present
while read i; do if [ "$i" = startperf ]; then start_perf_record; break; fi; done \
< <(inotifywait -e create,open,modify --format '%f' --monitor /tmp)
else
start_perf_record
fi
;;
esac
#Long sleep :-)
sleep 1000000000d