-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtqparse.awk
executable file
·60 lines (50 loc) · 1.43 KB
/
tqparse.awk
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
#!/usr/bin/env awk -f
# TODO: will always output in seconds.
BEGIN {
# Number of lines prefixed by 'tq_stop'.
tq_entries = 0
}
/^tq_stop:/ {
++tq_entries
if (NF < 3) {
print "Bad input: '" $0 "' has less than 3 fields."
exit 1
}
# Use NF as the time because the message cold have spaces.
if (!match($NF, /[a-z]+/)) {
print "Bad input: expected floating point followed by unit for time, not '" $NF "'."
exit 1
}
time = substr($NF, 1, RSTART - 1)
unit = substr($NF, RSTART, RLENGTH)
# Message is $2 to $NF - 1
msg = $2
for (i = 3; i < NF; ++i) { msg = msg " " $i }
msg = substr(msg, 1, length(msg) - 1)
times[msg] += to_seconds(time, unit)
++freq[msg]
}
END {
print " ####### timequick #######"
print " # timequick entries: " NR - tq_entries
for (msg in times) {
print " " "----- " msg " -----"
printf " " "Total time : %.5f\n", times[msg]
printf " " "Frequency : %d\n", freq[msg]
printf " " "Average time: %.5f\n", times[msg] / freq[msg]
}
}
function to_seconds(time, unit) {
if (unit == "ns") {
return time / 1000000000
} else if (unit == "us") {
return time / 1000000
} else if (unit == "ms") {
return time / 1000
} else if (unit == "s") {
return time
} else {
print "Bad time unit: '" unit "'"
exit 2
}
}