Skip to content

Instantly share code, notes, and snippets.

@elbeno
Last active June 19, 2018 09:20
Show Gist options
  • Save elbeno/41338aad32fe8b3ad7a2042f3d27d0ef to your computer and use it in GitHub Desktop.
Save elbeno/41338aad32fe8b3ad7a2042f3d27d0ef to your computer and use it in GitHub Desktop.
ykloc: measure year-kilo-lines-of-code per author
{
# fields between ( and )
start = index($0, "(") + 1
len = index($0, ")") - start
$0 = substr($0, start, len)
# field n-2 is the timestamp
line_age = systime() - $(NF - 2)
# fields before timestamp are author
author = $1
for (i = 2; i < (NF-2); i++) author = author " " $i
# accumulations
++lines[author]
total_age[author] += line_age
++all_lines
all_age += line_age
}
END {
# figure out nice formatting widths
longest_1 = length("Author") + 1
longest_2 = length("# Lines") + 1
longest_3 = length("ykloc") + 1
for (a in lines) {
longest_1 = max(longest_1, length(a))
longest_2 = max(longest_2, length(lines[a] ""))
longest_3 = max(longest_3, length(ykloc(lines[a], total_age[a]) ""))
}
longest_2 = max(longest_2, length(all_lines ""))
longest_3 = max(longest_3, length(ykloc(all_lines, all_age) ""))
formatstr = sprintf("%%%ds %%%ds %%%ds\n",
longest_1 + 1, longest_2 + 1, longest_3 + 1)
# print table
printf(formatstr, "Author", "# Lines", "ykloc")
printf(formatstr, "======", "=======", "=====")
PROCINFO["sorted_in"] = "ykloc_comp"
for (a in lines) {
printf(formatstr, a, lines[a], ykloc(lines[a], total_age[a]))
}
printf(formatstr, "------", "-------", "-----")
printf(formatstr, "All", all_lines, ykloc(all_lines, all_age))
}
function max(x, y) {
if (x > y) return x
return y
}
function ykloc(loc, seconds) {
return years(seconds) / 1000
}
function years(seconds) {
return seconds / (60 * 60 * 24 * 365)
}
function ykloc_comp(i1, v1, i2, v2)
{
ykloc1 = ykloc(v1, total_age[i1])
ykloc2 = ykloc(v2, total_age[i2])
if (ykloc2 < ykloc1) return -1
return ykloc1 != ykloc2
}
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
awk -f $DIR/ykloc.awk <(
for file in $(git ls-files); do
git blame -t $file;
done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment