# then the cwd is used. The directory must be an LLVM tree checked out
# from cvs.
#
-# Syntax: userloc.pl [-details|-recurse|-tag=tag|-html... <directory>...
+# Syntax: userloc.pl [-tag=tag|-html... <directory>...
#
# Options:
-# -details
-# Print detailed per-directory information.
-# -recurse
-# Recurse through sub directories. Without this, only the
-# specified directory is examined
# -tag=tag
# Use "tag" to select the revision (as per cvs -r option)
+# -filedetails
+# Report details about lines of code in each file for each user
# -html
# Generate HTML output instead of text output
-
-die "Usage userloc.pl [-details|-recurse|-tag=tag|-html] <directories>..."
+# -topdir
+# Specify where the top llvm source directory is. Otherwise the
+# llvm-config tool is used to find it.
+# Directories:
+# The directories passed after the options should be relative paths to
+# directories of interest from the top of the llvm source tree, e.g. "lib"
+# or "include", etc.
+
+die "Usage userloc.pl [-tag=tag|-html] <directories>..."
if ($#ARGV < 0);
my $tag = "";
-my $details = 0;
-my $recurse = 0;
my $html = 0;
-while ( substr($ARGV[0],0,1) eq '-' )
+my $debug = 0;
+my $filedetails = "";
+my $srcroot = "";
+while ( defined($ARGV[0]) && substr($ARGV[0],0,1) eq '-' )
{
- if ($ARGV[0] eq "-details")
- {
- $details = 1 ;
- }
- elsif ($ARGV[0] eq "-recurse")
- {
- $recurse = 1;
- }
- elsif ($ARGV[0] =~ /-tag=.*/)
- {
+ if ($ARGV[0] =~ /-tag=.*/) {
$tag = $ARGV[0];
$tag =~ s#-tag=(.*)#$1#;
- }
- elsif ($ARGV[0] eq "-html")
- {
+ } elsif ($ARGV[0] =~ /-filedetails/) {
+ $filedetails = 1;
+ } elsif ($ARGV[0] eq "-html") {
$html = 1;
- }
- else
- {
+ } elsif ($ARGV[0] eq "-debug") {
+ $debug = 1;
+ } elsif ($ARGV[0] eq "-topdir") {
+ shift; $srcroot = $ARGV[0]; shift;
+ } else {
die "Invalid option: $ARGV[0]";
}
shift;
}
-die "Usage userloc.pl [-details|-recurse|-tag=tag|-html] <directories>..."
- if ($#ARGV < 0);
-
+if (length($srcroot) == 0) {
+ chomp($srcroot = `llvm-config --src-root`);
+}
+if (! -d "$srcroot") {
+ die "Invalid source root: $srcroot\n";
+}
+chdir($srcroot);
+my $llvmdo = "$srcroot/utils/llvmdo -topdir '$srcroot'";
my %Stats;
-my %StatsDetails;
+my %FileStats;
-sub ValidateFile
+my $annotate = "cvs -z6 annotate -lf ";
+if (length($tag) > 0)
{
- my $f = $_[0];
- my $d = $_[1];
-
- return 0 if ( "$f" eq "configure");
- if ( $d =~ ".*autoconf.*")
- {
- return 1 if ($f eq "configure.ac");
- return 1 if ($f eq "AutoRegen.sh");
- return 0;
- }
-
- return 1;
+ $annotate = $annotate . " -r" . $tag;
}
sub GetCVSFiles
{
my $d = $_[0];
my $files ="";
- open STATUS, "cvs -nfz6 status $d -l 2>/dev/null |"
- || die "Can't 'cvs status'";
- while ( defined($line = <STATUS>) )
- {
- if ( $line =~ /^File:.*/ )
- {
- chomp($line);
- $line =~ s#^File: ([A-Za-z0-9._-]*)[ \t]*Status:.*#$1#;
- $files = "$files $d/$line" if (ValidateFile($line,$d));
- }
-
+ open FILELIST,
+ "$llvmdo -dirs \"$d\" -code-only echo |" || die "Can't get list of files with llvmdo";
+ while ( defined($line = <FILELIST>) ) {
+ chomp($file = $line);
+ print "File: $file\n" if ($debug);
+ $files = "$files $file";
}
return $files;
}
-my $annotate = "cvs annotate -lf ";
-if (length($tag) > 0)
-{
- $annotate = $annotate . " -r " . $tag;
-}
-
-sub ScanDir
+sub ScanDir
{
my $Dir = $_[0];
my $files = GetCVSFiles($Dir);
- open (DATA,"$annotate $files 2>/dev/null |")
+ open (DATA,"$annotate $files 2>&1 |")
|| die "Can't read cvs annotation data";
- my %st;
+ my $curfile = "";
while ( defined($line = <DATA>) )
{
- if ($line =~ /^[0-9.]*[ \t]*\(/)
- {
- $line =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*).*#$1#;
- chomp($line);
- $st{$line}++;
- $Stats{$line}++;
+ chomp($line);
+ if ($line =~ '^Annotations for.*') {
+ $curfile = $line;
+ $curfile =~ s#^Annotations for ([[:print:]]*)#$1#;
+ print "Scanning: $curfile\n" if ($debug);
+ } elsif ($line =~ /^[0-9.]*[ \t]*\([^)]*\):/) {
+ $uname = $line;
+ $uname =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*) [^)]*\):.*#$1#;
+ $Stats{$uname}++;
+ if ($filedetails) {
+ $FileStats{$uname} = {} unless exists $FileStats{$uname};
+ ${$FileStats{$uname}}{$curfile}++;
+ }
}
}
-
- $StatsDetails{$Dir} = { %st };
-
close DATA;
}
-sub ValidateDirectory
-{
- my $d = $_[0];
- return 0 if ($d =~ /.*CVS.*/);
- return 0 if ($d =~ /.*Debug.*/);
- return 0 if ($d =~ /.*Release.*/);
- return 0 if ($d =~ /.*Profile.*/);
- return 0 if ($d =~ /.*docs\/CommandGuide\/html.*/);
- return 0 if ($d =~ /.*docs\/CommandGuide\/man.*/);
- return 0 if ($d =~ /.*docs\/CommandGuide\/ps.*/);
- return 0 if ($d =~ /.*docs\/CommandGuide\/man.*/);
- return 0 if ($d =~ /.*docs\/HistoricalNotes.*/);
- return 0 if ($d =~ /.*docs\/img.*/);
- return 0 if ($d =~ /.*bzip2.*/);
- return 1 if ($d =~ /.*projects\/Stacker.*/);
- return 1 if ($d =~ /.*projects\/sample.*/);
- return 0 if ($d =~ /.*projects\/llvm-.*/);
- return 0 if ($d =~ /.*win32.*/);
- return 1;
-}
-
-my $RowCount = 0;
sub printStats
{
my $dir = $_[0];
my $user;
my $total = 0;
- if ($RowCount % 10 == 0)
- {
- print " <tr><th style=\"text-align:left\">Directory</th>\n";
- foreach $user (sort keys %Stats)
- {
- print "<th style=\"text-align:right\">",$user,"</th>\n";
- }
+ foreach $user (keys %Stats) { $total += $Stats{$user}; }
+
+ if ($html) {
+ print "<p>Total Source Lines: $total<br/></p>\n";
+ print "<table>";
+ print " <tr><th style=\"text-align:right\">LOC</th>\n";
+ print " <th style=\"text-align:right\">\%LOC</th>\n";
+ print " <th style=\"text-align:left\">User</th>\n";
print "</tr>\n";
}
- $RowCount++;
-
- if ($html)
- { print "<tr><td style=\"text-align:left\">",$dir,"</td>"; }
- else
- { print $dir,"\n"; }
-
- foreach $user (keys %{$hash}) { $total += $hash->{$user}; }
-
foreach $user ( sort keys %Stats )
{
- my $v = $hash->{$user};
+ my $v = $Stats{$user};
if (defined($v))
{
- if ($html)
- {
- printf "<td style=\"text-align:right\">%d<br/>(%2.1f%%)</td>", $v,
- (100.0/$total)*$v;
- }
- else
- {
- printf "%8d (%4.1f%%): %s\n", $v, (100.0/$total)*$v, $user;
+ if ($html) {
+ 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;
+ if ($filedetails) {
+ print "<a href=\"#$user\">$user</a></td></tr>";
+ } else {
+ print $user,"</td></tr>";
+ }
+ } else {
+ printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $user;
}
}
- elsif ($html)
- {
- print "<td style=\"text-align:right\">- </td>";
+ }
+ print "</table>\n" if ($html);
+
+ if ($filedetails) {
+ foreach $user (sort keys %FileStats) {
+ my $total = 0;
+ foreach $file (sort keys %{$FileStats{$user}}) {
+ $total += ${$FileStats{$user}}{$file}
+ }
+ if ($html) {
+ print "<table><tr><th style=\"text-align:left\" colspan=\"3\"><a name=\"$user\">$user</a></th></tr>\n";
+ } else {
+ print $user,":\n";
+ }
+ foreach $file (sort keys %{$FileStats{$user}}) {
+ my $v = ${$FileStats{$user}}{$file};
+ if ($html) {
+ printf "<tr><td style=\"text-align:right\"> %d</td><td
+ style=\"text-align:right\"> %4.1f%%</td><td
+ style=\"text-align:left\">%s</td></tr>",$v, (100.0/$total)*$v,$file;
+ } else {
+ printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $file;
+ }
+ }
+ if ($html) { print "</table>\n"; }
}
}
- print "</tr>\n" if ($html);
}
-my @ALLDIRS = @ARGV;
-
-if ($recurse)
-{
- $Dirs = join(" ", @ARGV);
- $Dirs = `find $Dirs -type d \! -name CVS -print`;
- @ALLDIRS = split(' ',$Dirs);
-}
if ($html)
{
print "<p>This document shows the total lines of code per user in each\n";
print "LLVM directory. Lines of code are attributed by the user that last\n";
print "committed the line. This does not necessarily reflect authorship.</p>\n";
-print "<p>The following directories were skipped:</p>\n";
-print "<ol>\n";
}
-for $Dir (@ALLDIRS)
-{
- if ( -d "$Dir" && -d "$Dir/CVS" && ValidateDirectory($Dir) )
- {
- ScanDir($Dir);
- }
- elsif ($html)
- {
- print "<li>$Dir</li>\n";
- }
+my @DIRS;
+if ($#ARGV > 0) {
+ @DIRS = @ARGV;
+} else {
+ push @DIRS, 'include';
+ push @DIRS, 'lib';
+ push @DIRS, 'tools';
+ push @DIRS, 'runtime';
+ push @DIRS, 'docs';
+ push @DIRS, 'test';
+ push @DIRS, 'utils';
+ push @DIRS, 'examples';
+ push @DIRS, 'projects/Stacker';
+ push @DIRS, 'projects/sample';
+ push @DIRS, 'autoconf';
}
-
-if ($html)
-{
- print "</ol>\n";
- print "<table>\n";
+
+for $Index ( 0 .. $#DIRS) {
+ print "Scanning Dir: $DIRS[$Index]\n" if ($debug);
+ ScanDir($DIRS[$Index]);
}
-if ($details)
-{
- foreach $dir (sort keys %StatsDetails)
- {
- printStats($dir,$StatsDetails{$dir});
- }
-}
-
-printStats("Total",\%Stats);
-
-
-if ($html)
-{
- print "</table></body></html>\n";
-}
+printStats;
+print "</body></html>\n" if ($html) ;