-
Notifications
You must be signed in to change notification settings - Fork 1
/
time.sh
executable file
·103 lines (89 loc) · 2.07 KB
/
time.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
#!/bin/bash
set -euo pipefail
timings() {
grep -E '(Starting|Done) whole node job|^Sentences:' \
| sed -r 's/^(\w+) ([0-9]+) (\w+) ([0-9]+:[0-9]+:[0-9]+) (\w+) ([0-9]+) (Starting|Done) whole node job ([0-9]+)( \([0-9]+\))? on (\w+)/\7\t\2 \3 \6 \4 \5\t\8\t\10/' \
| sed -r 's/^Sentences: ([0-9]+)$/Sentences\t0\t\1\tna/' \
| while IFS=$'\t' read WHAT DATE JOB NODE; do
SEC=$(date --date "$DATE" '+%s')
case $WHAT in
Sentences)
SENT_CNT=$JOB
;;
Starting)
START=$SEC
SJOB=$JOB
;;
Done)
if [ "$JOB" = "$SJOB" ]; then
echo $(($SEC - $START)) $SENT_CNT $JOB
fi
;;
esac
done
}
sentences() {
sed -nr 's,^Sentences: ([0-9]+)$,\1,p'
}
format_time() {
local TIME=$(cat)
printf "% 4d:%02d:%02d\n" \
$(( $TIME / 3600 )) \
$(( $(( $TIME % 3600 )) / 60 )) \
$(( $TIME % 60 ))
}
sum() {
paste -sd+ | bc
}
summary() {
# prints min, max, med
local TIMINGS=$(cat "$@" | sort -n)
local COUNT=$(wc -l <<< "$TIMINGS")
sed -n 1p <<< "$TIMINGS"
sed -n ${COUNT}p <<< "$TIMINGS"
echo $(( $(sum <<< "$TIMINGS") / $COUNT ))
sed -n $(( $COUNT / 2 ))p <<< "$TIMINGS"
}
MODE=summary
while true; do
case "$1" in
-l)
MODE=list
shift
;;
*)
break
esac
done
JOBS=$(cat $@ | timings)
if [ $MODE = "list" ]; then
echo "$JOBS"
elif [ $MODE = "summary" ]; then
TIMINGS=$(cut -d' ' -f1 <<< "$JOBS" | sort -n)
COUNT=$(wc -l <<< "$TIMINGS")
echo "Count: " $COUNT tasks
echo "Sum: " $(sum <<< "$TIMINGS" | format_time)
STATS=( $(summary <<< "$TIMINGS") )
echo "Min: " $(echo ${STATS[0]} | format_time)
echo "Max: " $(echo ${STATS[1]} | format_time)
echo "Mean: " $(echo ${STATS[2]} | format_time)
echo "Median: " $(echo ${STATS[3]} | format_time)
fi
WORDS_PER_SECOND=$(\
cat <<< "$JOBS" \
| cut -d' ' -f1-2 \
| while read JOB SENTENCE_COUNT; do
echo $(( $SENTENCE_COUNT / $JOB ))
done \
)
STATS=( $(summary <<< "$WORDS_PER_SECOND") )
echo
printf "\
Count: % 9d lines
Min: % 9d lines/second
Max: % 9d lines/second
Mean: % 9d lines/second
Median: % 9d lines/second
" \
$(cut -d' ' -f2 <<< "$JOBS" | sum) \
${STATS[@]}