Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 105 lines (84 sloc) 2.25 KB
#!/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=""
GRAY=""
NORMAL=""
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)
}
}