| 1 |
#!/usr/bin/env python |
| 2 |
# |
| 3 |
# Copyright (C) 2013 Anders Logg |
| 4 |
# |
| 5 |
# This file is part of DOLFIN. |
| 6 |
# |
| 7 |
# DOLFIN is free software: you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU Lesser General Public License as |
| 9 |
# published by the Free Software Foundation, either version 3 of the |
| 10 |
# License, or (at your option) any later version. |
| 11 |
# |
| 12 |
# DOLFIN is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU Lesser General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU Lesser General Public License |
| 18 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
# |
| 20 |
# First added: 2013-02-26 |
| 21 |
# Last changed: 2013-02-26 |
| 22 |
# |
| 23 |
# Plot growth of code as function of time. This script should be |
| 24 |
# run rom the top level directory. |
| 25 |
|
| 26 |
from commands import getoutput |
| 27 |
from datetime import datetime |
| 28 |
import pylab as pl |
| 29 |
|
| 30 |
# Suffixes to check |
| 31 |
suffixes = [".h", ".hh", ".cpp", ".C"] |
| 32 |
|
| 33 |
# Paths to skip |
| 34 |
skip = ["demo", "bench", "test", "local", "build"] |
| 35 |
|
| 36 |
# Get time stamps |
| 37 |
timestamps = getoutput("bzr log | grep timestamp | awk '{print $3}'") |
| 38 |
t = [] |
| 39 |
for timestamp in timestamps.split("\n"): |
| 40 |
y, m, d = timestamp.split("-") |
| 41 |
t.append(datetime(int(y), int(m), int(d))) |
| 42 |
t.reverse() |
| 43 |
|
| 44 |
# Revisions to check |
| 45 |
revisions = range(len(t)) |
| 46 |
|
| 47 |
# For quick testing |
| 48 |
#revisions = revisions[-10:] |
| 49 |
#t = t[-10:] |
| 50 |
|
| 51 |
# Iterate over revisions |
| 52 |
locs = [] |
| 53 |
for i, r in enumerate(revisions): |
| 54 |
|
| 55 |
print "Updating to revision %r %s" % (r, t[i]) |
| 56 |
|
| 57 |
# Update repository |
| 58 |
getoutput("bzr update -r %d" % r) |
| 59 |
|
| 60 |
# Count the lines of code |
| 61 |
n_total = 0 |
| 62 |
for suffix in suffixes: |
| 63 |
skips = " | ".join("grep -v %s" % s for s in skip) |
| 64 |
n = getoutput("""find . -name *%s \ |
| 65 |
| %s \ |
| 66 |
| xargs wc -l \ |
| 67 |
| grep total \ |
| 68 |
| awk '{print $1}'""" % (suffix, skips)) |
| 69 |
if n.isdigit(): |
| 70 |
n_total += int(n) |
| 71 |
|
| 72 |
# Store lines of code |
| 73 |
print "%d lines of code" % n_total |
| 74 |
locs.append(n_total) |
| 75 |
|
| 76 |
# Store results to file |
| 77 |
f = open("klocs.csv", "w") |
| 78 |
f.write("\n".join("%d-%d-%d,%d" % \ |
| 79 |
(t[i].year, t[i].month, t[i].day, locs[i]) \ |
| 80 |
for i in range(len(revisions)))) |
| 81 |
f.close() |
| 82 |
|
| 83 |
# Plot results |
| 84 |
pl.plot(t, locs) |
| 85 |
pl.grid(True) |
| 86 |
pl.ylabel("Lines of code") |
| 87 |
pl.title("Code growth for DOLFIN %d - %d" % (t[0].year, t[-1].year)) |
| 88 |
pl.show() |