-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergetime
executable file
·104 lines (84 loc) · 2.25 KB
/
mergetime
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
#!/usr/bin/awk -f
function p(s)
{
days = int(s / 86400)
hours = int((s -= days * 86400) / 3600)
mins = int((s -= hours * 3600) / 60)
secs = s - mins * 60
if (days > 0)
return sprintf("%dd %dh %02dm %02ds", days, hours, mins, secs)
if (hours > 0)
return sprintf("%dh %02dm %02ds", hours, mins, secs)
if (mins > 0)
return sprintf("%dm %02ds", mins, secs)
return sprintf("%ds", secs)
}
BEGIN {
YELLOW="[0;33m"
GRAY="[38;5;245m"
NORMAL="[0m"
VERBOSE = 0
COLOR = 1
for (i = 1; i < ARGC; i++) {
if (ARGV[i] == "all")
VERBOSE = 1
else if (ARGV[i] == "nocolor")
COLOR = 0
}
# Get installed packages from eix because the log messes up when package names changes
while ("eix -I --format '<installedversions:NAMEVERSION>' --pure-packages" | getline)
installed[$1] = 1
while (getline < "/var/log/emerge.log")
if ($2 == "===" && $6 == "Compiling/Merging") {
patsplit($7, a, "[^(:]+")
pkg = a[1]
start[pkg] = $1
} else if ($2 == "===" && $6 == "Merging") {
patsplit($7, a, "[^(:]+")
pkg = a[1]
diff = $1 - start[pkg]
if (start[pkg] == 0)
continue
else
start[pkg] = 0
if (diff < min[pkg] || min[pkg] == 0)
min[pkg] = diff
if (diff > max[pkg])
max[pkg] = diff
last[pkg] = diff
sum[pkg] += diff
count[pkg]++
}
sort = "sort -n"
for (pkg in sum)
if (installed[pkg]) {
if (VERBOSE)
printf "%6d %15s %15s %15s %15s %s\n", min[pkg], p(last[pkg]), p(min[pkg]), p(sum[pkg]/count[pkg]), p(max[pkg]), pkg |& sort
else
printf "%6d %15s %s\n", min[pkg], p(min[pkg]), pkg |& sort
sum_min += min[pkg]
sum_avg += sum[pkg]/count[pkg]
sum_max += max[pkg]
sum_last += last[pkg]
}
close(sort, "to")
i = 0
while (sort |& getline) {
if (COLOR) {
if (++i % 10 == 0)
printf "%s", NORMAL
else if (i % 5 == 0)
printf "%s", GRAY
}
print
}
if (COLOR)
printf "%s", YELLOW
if (VERBOSE) {
printf "---------------- last ----------- min ----------- avg ----------- max ------------------------------------------------\n"
printf "%6d %15s %15s %15s %15s\n", sum_min, p(sum_last), p(sum_min), p(sum_avg), p(sum_max)
} else {
printf "----------------- min ------------------------------------------------\n"
printf "%6d %15s\n", sum_min, p(sum_min)
}
}