5
# Synopsis: This program uses "cvs annotate" to get a summary of how many lines
6
# of code the various developres are responsible for. It takes one
7
# argument, the directory to process. If the argument is not specified
8
# then the cwd is used. The directory must be an LLVM tree checked out
11
# Syntax: userloc.pl [-tag=tag|-html... <directory>...
15
# Use "tag" to select the revision (as per cvs -r option)
17
# Report details about lines of code in each file for each user
19
# Generate HTML output instead of text output
21
# Specify where the top llvm source directory is. Otherwise the
22
# llvm-config tool is used to find it.
24
# The directories passed after the options should be relative paths to
25
# directories of interest from the top of the llvm source tree, e.g. "lib"
28
die "Usage userloc.pl [-tag=tag|-html] <directories>..."
36
while ( defined($ARGV[0]) && substr($ARGV[0],0,1) eq '-' )
38
if ($ARGV[0] =~ /-tag=.*/) {
40
$tag =~ s#-tag=(.*)#$1#;
41
} elsif ($ARGV[0] =~ /-filedetails/) {
43
} elsif ($ARGV[0] eq "-html") {
45
} elsif ($ARGV[0] eq "-debug") {
47
} elsif ($ARGV[0] eq "-topdir") {
48
shift; $srcroot = $ARGV[0]; shift;
50
die "Invalid option: $ARGV[0]";
55
if (length($srcroot) == 0) {
56
chomp($srcroot = `llvm-config --src-root`);
58
if (! -d "$srcroot") {
59
die "Invalid source root: $srcroot\n";
62
my $llvmdo = "$srcroot/utils/llvmdo -topdir '$srcroot'";
66
my $annotate = "cvs -z6 annotate -lf ";
69
$annotate = $annotate . " -r" . $tag;
77
"$llvmdo -dirs \"$d\" -code-only echo |" || die "Can't get list of files with llvmdo";
78
while ( defined($line = <FILELIST>) ) {
80
print "File: $file\n" if ($debug);
81
$files = "$files $file";
89
my $files = GetCVSFiles($Dir);
91
open (DATA,"$annotate $files 2>&1 |")
92
|| die "Can't read cvs annotation data";
95
while ( defined($line = <DATA>) )
98
if ($line =~ '^Annotations for.*') {
100
$curfile =~ s#^Annotations for ([[:print:]]*)#$1#;
101
print "Scanning: $curfile\n" if ($debug);
102
} elsif ($line =~ /^[0-9.]*[ \t]*\([^)]*\):/) {
104
$uname =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*) [^)]*\):.*#$1#;
107
$FileStats{$uname} = {} unless exists $FileStats{$uname};
108
${$FileStats{$uname}}{$curfile}++;
122
foreach $user (keys %Stats) { $total += $Stats{$user}; }
125
print "<p>Total Source Lines: $total<br/></p>\n";
127
print " <tr><th style=\"text-align:right\">LOC</th>\n";
128
print " <th style=\"text-align:right\">\%LOC</th>\n";
129
print " <th style=\"text-align:left\">User</th>\n";
133
foreach $user ( sort keys %Stats )
135
my $v = $Stats{$user};
139
printf "<tr><td style=\"text-align:right\">%d</td><td style=\"text-align:right\">(%4.1f%%)</td><td style=\"text-align:left\">", $v, (100.0/$total)*$v;
141
print "<a href=\"#$user\">$user</a></td></tr>";
143
print $user,"</td></tr>";
146
printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $user;
150
print "</table>\n" if ($html);
153
foreach $user (sort keys %FileStats) {
155
foreach $file (sort keys %{$FileStats{$user}}) {
156
$total += ${$FileStats{$user}}{$file}
159
print "<table><tr><th style=\"text-align:left\" colspan=\"3\"><a name=\"$user\">$user</a></th></tr>\n";
163
foreach $file (sort keys %{$FileStats{$user}}) {
164
my $v = ${$FileStats{$user}}{$file};
166
printf "<tr><td style=\"text-align:right\"> %d</td><td
167
style=\"text-align:right\"> %4.1f%%</td><td
168
style=\"text-align:left\">%s</td></tr>",$v, (100.0/$total)*$v,$file;
170
printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $file;
173
if ($html) { print "</table>\n"; }
181
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
182
print "<html>\n<head>\n";
183
print " <title>LLVM LOC Based On CVS Annotation</title>\n";
184
print " <link rel=\"stylesheet\" href=\"llvm.css\" type=\"text/css\"/>\n";
186
print "<body><div class=\"doc_title\">LLVM LOC Based On CVS Annotation</div>\n";
187
print "<p>This document shows the total lines of code per user in each\n";
188
print "LLVM directory. Lines of code are attributed by the user that last\n";
189
print "committed the line. This does not necessarily reflect authorship.</p>\n";
196
push @DIRS, 'include';
199
push @DIRS, 'runtime';
203
push @DIRS, 'examples';
204
push @DIRS, 'projects/Stacker';
205
push @DIRS, 'projects/sample';
206
push @DIRS, 'autoconf';
209
for $Index ( 0 .. $#DIRS) {
210
print "Scanning Dir: $DIRS[$Index]\n" if ($debug);
211
ScanDir($DIRS[$Index]);
216
print "</body></html>\n" if ($html) ;