2005-05-16 18:30:38 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# Program: userloc.pl
|
|
|
|
#
|
|
|
|
# Synopsis: This program uses "cvs annotate" to get a summary of how many lines
|
|
|
|
# of code the various developres are responsible for. It takes one
|
|
|
|
# argument, the directory to process. If the argument is not specified
|
|
|
|
# then the cwd is used. The directory must be an LLVM tree checked out
|
|
|
|
# from cvs.
|
|
|
|
#
|
2006-08-11 23:50:27 +00:00
|
|
|
# Syntax: userloc.pl [-tag=tag|-html... <directory>...
|
2005-05-16 18:30:38 +00:00
|
|
|
#
|
|
|
|
# Options:
|
|
|
|
# -tag=tag
|
|
|
|
# Use "tag" to select the revision (as per cvs -r option)
|
2006-08-11 20:44:17 +00:00
|
|
|
# -filedetails
|
|
|
|
# Report details about lines of code in each file for each user
|
2005-05-16 18:30:38 +00:00
|
|
|
# -html
|
|
|
|
# Generate HTML output instead of text output
|
2006-08-14 18:49:05 +00:00
|
|
|
# -topdir
|
|
|
|
# Specify where the top llvm source directory is. Otherwise the
|
|
|
|
# llvm-config tool is used to find it.
|
2006-08-11 23:50:27 +00:00
|
|
|
# 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.
|
2005-05-16 18:30:38 +00:00
|
|
|
|
2006-08-11 23:50:27 +00:00
|
|
|
die "Usage userloc.pl [-tag=tag|-html] <directories>..."
|
2005-05-16 18:30:38 +00:00
|
|
|
if ($#ARGV < 0);
|
|
|
|
|
|
|
|
my $tag = "";
|
|
|
|
my $html = 0;
|
2006-08-11 18:36:55 +00:00
|
|
|
my $debug = 0;
|
2006-08-11 20:44:17 +00:00
|
|
|
my $filedetails = "";
|
2006-08-14 18:49:05 +00:00
|
|
|
my $srcroot = "";
|
2006-08-11 23:50:27 +00:00
|
|
|
while ( defined($ARGV[0]) && substr($ARGV[0],0,1) eq '-' )
|
2005-05-16 18:30:38 +00:00
|
|
|
{
|
2006-08-11 23:50:27 +00:00
|
|
|
if ($ARGV[0] =~ /-tag=.*/) {
|
2005-05-16 18:30:38 +00:00
|
|
|
$tag = $ARGV[0];
|
|
|
|
$tag =~ s#-tag=(.*)#$1#;
|
2006-08-11 20:44:17 +00:00
|
|
|
} elsif ($ARGV[0] =~ /-filedetails/) {
|
|
|
|
$filedetails = 1;
|
2006-08-11 18:36:55 +00:00
|
|
|
} elsif ($ARGV[0] eq "-html") {
|
2005-05-16 18:30:38 +00:00
|
|
|
$html = 1;
|
2006-08-11 18:36:55 +00:00
|
|
|
} elsif ($ARGV[0] eq "-debug") {
|
|
|
|
$debug = 1;
|
2006-08-14 18:49:05 +00:00
|
|
|
} elsif ($ARGV[0] eq "-topdir") {
|
|
|
|
shift; $srcroot = $ARGV[0]; shift;
|
2006-08-11 18:36:55 +00:00
|
|
|
} else {
|
2005-05-16 18:30:38 +00:00
|
|
|
die "Invalid option: $ARGV[0]";
|
|
|
|
}
|
|
|
|
shift;
|
|
|
|
}
|
|
|
|
|
2006-08-14 18:49:05 +00:00
|
|
|
if (length($srcroot) == 0) {
|
|
|
|
chomp($srcroot = `llvm-config --src-root`);
|
|
|
|
}
|
|
|
|
if (! -d "$srcroot") {
|
|
|
|
die "Invalid source root: $srcroot\n";
|
|
|
|
}
|
2006-08-13 19:03:06 +00:00
|
|
|
chdir($srcroot);
|
2006-08-14 18:49:05 +00:00
|
|
|
my $llvmdo = "$srcroot/utils/llvmdo -topdir '$srcroot'";
|
2005-05-16 18:30:38 +00:00
|
|
|
my %Stats;
|
2006-08-11 20:44:17 +00:00
|
|
|
my %FileStats;
|
2005-05-16 18:30:38 +00:00
|
|
|
|
2006-08-11 23:50:27 +00:00
|
|
|
my $annotate = "cvs -z6 annotate -lf ";
|
|
|
|
if (length($tag) > 0)
|
2005-05-16 18:30:38 +00:00
|
|
|
{
|
2006-08-11 23:50:27 +00:00
|
|
|
$annotate = $annotate . " -r" . $tag;
|
2005-05-16 18:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub GetCVSFiles
|
|
|
|
{
|
|
|
|
my $d = $_[0];
|
|
|
|
my $files ="";
|
2006-08-11 23:50:27 +00:00
|
|
|
open FILELIST,
|
2006-08-13 19:03:06 +00:00
|
|
|
"$llvmdo -dirs \"$d\" -code-only echo |" || die "Can't get list of files with llvmdo";
|
2006-08-11 23:50:27 +00:00
|
|
|
while ( defined($line = <FILELIST>) ) {
|
|
|
|
chomp($file = $line);
|
2006-08-13 19:03:06 +00:00
|
|
|
print "File: $file\n" if ($debug);
|
2006-08-11 23:50:27 +00:00
|
|
|
$files = "$files $file";
|
2005-05-16 18:30:38 +00:00
|
|
|
}
|
|
|
|
return $files;
|
|
|
|
}
|
|
|
|
|
2006-08-11 18:36:55 +00:00
|
|
|
sub ScanDir
|
2005-05-16 18:30:38 +00:00
|
|
|
{
|
|
|
|
my $Dir = $_[0];
|
|
|
|
my $files = GetCVSFiles($Dir);
|
|
|
|
|
2006-08-11 20:44:17 +00:00
|
|
|
open (DATA,"$annotate $files 2>&1 |")
|
2005-05-16 18:30:38 +00:00
|
|
|
|| die "Can't read cvs annotation data";
|
|
|
|
|
2006-08-11 20:44:17 +00:00
|
|
|
my $curfile = "";
|
2005-05-16 18:30:38 +00:00
|
|
|
while ( defined($line = <DATA>) )
|
|
|
|
{
|
2006-08-11 20:44:17 +00:00
|
|
|
chomp($line);
|
|
|
|
if ($line =~ '^Annotations for.*') {
|
|
|
|
$curfile = $line;
|
|
|
|
$curfile =~ s#^Annotations for ([[:print:]]*)#$1#;
|
2006-08-13 19:03:06 +00:00
|
|
|
print "Scanning: $curfile\n" if ($debug);
|
2006-08-11 20:44:17 +00:00
|
|
|
} 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}++;
|
|
|
|
}
|
2005-05-16 18:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub printStats
|
|
|
|
{
|
|
|
|
my $dir = $_[0];
|
|
|
|
my $hash = $_[1];
|
2006-08-11 23:50:27 +00:00
|
|
|
my $user;
|
2005-05-16 18:30:38 +00:00
|
|
|
my $total = 0;
|
|
|
|
|
2006-08-11 23:50:27 +00:00
|
|
|
foreach $user (keys %Stats) { $total += $Stats{$user}; }
|
2005-05-16 18:30:38 +00:00
|
|
|
|
2006-08-11 20:44:17 +00:00
|
|
|
if ($html) {
|
2006-08-13 19:03:06 +00:00
|
|
|
print "<p>Total Source Lines: $total<br/></p>\n";
|
2006-08-11 20:44:17 +00:00
|
|
|
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";
|
|
|
|
}
|
2005-05-16 18:52:57 +00:00
|
|
|
|
2006-08-11 23:50:27 +00:00
|
|
|
foreach $user ( sort keys %Stats )
|
2005-05-16 18:30:38 +00:00
|
|
|
{
|
2006-08-11 23:50:27 +00:00
|
|
|
my $v = $Stats{$user};
|
2005-05-16 18:30:38 +00:00
|
|
|
if (defined($v))
|
|
|
|
{
|
2006-08-11 20:44:17 +00:00
|
|
|
if ($html) {
|
2006-08-11 23:50:27 +00:00
|
|
|
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>";
|
|
|
|
}
|
2006-08-11 20:44:17 +00:00
|
|
|
} else {
|
2006-08-11 23:50:27 +00:00
|
|
|
printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $user;
|
2005-05-16 18:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-11 20:44:17 +00:00
|
|
|
}
|
|
|
|
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) {
|
2006-08-11 23:50:27 +00:00
|
|
|
print "<table><tr><th style=\"text-align:left\" colspan=\"3\"><a name=\"$user\">$user</a></th></tr>\n";
|
2006-08-11 20:44:17 +00:00
|
|
|
} 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"; }
|
2005-05-16 18:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($html)
|
|
|
|
{
|
|
|
|
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
|
|
|
|
print "<html>\n<head>\n";
|
|
|
|
print " <title>LLVM LOC Based On CVS Annotation</title>\n";
|
|
|
|
print " <link rel=\"stylesheet\" href=\"llvm.css\" type=\"text/css\"/>\n";
|
|
|
|
print "</head>\n";
|
|
|
|
print "<body><div class=\"doc_title\">LLVM LOC Based On CVS Annotation</div>\n";
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2006-08-11 23:50:27 +00:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
|
|
|
for $Index ( 0 .. $#DIRS) {
|
2006-08-13 19:03:06 +00:00
|
|
|
print "Scanning Dir: $DIRS[$Index]\n" if ($debug);
|
2006-08-11 23:50:27 +00:00
|
|
|
ScanDir($DIRS[$Index]);
|
2005-05-16 18:30:38 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 20:44:17 +00:00
|
|
|
printStats;
|
2005-05-16 18:30:38 +00:00
|
|
|
|
2006-08-11 23:50:27 +00:00
|
|
|
print "</body></html>\n" if ($html) ;
|