From: Reid Spencer Date: Fri, 11 Aug 2006 20:44:17 +0000 (+0000) Subject: Clean up the HTML output. Add a -filedetails option to report the number of X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ae2e622e7452863e59cb621152e35dd16f1c4661;p=oota-llvm.git Clean up the HTML output. Add a -filedetails option to report the number of lines contributed by each user to each file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29624 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/userloc.pl b/utils/userloc.pl index ab636e8a697..28b6792a8e5 100755 --- a/utils/userloc.pl +++ b/utils/userloc.pl @@ -16,6 +16,8 @@ # 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 @@ -26,6 +28,7 @@ my $tag = ""; my $recurse = 0; my $html = 0; my $debug = 0; +my $filedetails = ""; while ( substr($ARGV[0],0,1) eq '-' ) { if ($ARGV[0] eq "-recurse") { @@ -33,6 +36,8 @@ while ( substr($ARGV[0],0,1) eq '-' ) } elsif ($ARGV[0] =~ /-tag=.*/) { $tag = $ARGV[0]; $tag =~ s#-tag=(.*)#$1#; + } elsif ($ARGV[0] =~ /-filedetails/) { + $filedetails = 1; } elsif ($ARGV[0] eq "-html") { $html = 1; } elsif ($ARGV[0] eq "-debug") { @@ -47,7 +52,7 @@ die "Usage userloc.pl [-recurse|-tag=tag|-html] ..." if ($#ARGV < 0); my %Stats; -my %StatsDetails; +my %FileStats; sub ValidateFile { @@ -96,19 +101,26 @@ 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 $curfile = ""; while ( defined($line = ) ) { - if ($line =~ /^[0-9.]*[ \t]*\([^)]*\):/) - { - chomp($line); - $line =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*) [^)]*\):.*#$1#; - $Stats{$line}++; + chomp($line); + if ($line =~ '^Annotations for.*') { + $curfile = $line; + $curfile =~ s#^Annotations for ([[:print:]]*)#$1#; + } 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}++; + } } } - close DATA; } @@ -135,56 +147,61 @@ sub ValidateDirectory return 1; } -my $RowCount = 0; sub printStats { my $dir = $_[0]; my $hash = $_[1]; - my $user; + my $usr; my $total = 0; - if ($RowCount % 10 == 0) - { - if ($html) { - print " Directory\n"; - foreach $user (sort keys %Stats) - { - print "",$user,"\n"; - } - print "\n"; - } - } - - $RowCount++; + foreach $usr (keys %Stats) { $total += $Stats{$usr}; } - if ($html) - { print "",$dir,""; } - else - { print $dir,"\n"; } - - foreach $user (keys %{$hash}) { $total += $hash->{$user}; } + if ($html) { + print ""; + print " \n"; + print " \n"; + print " \n"; + print "\n"; + } - foreach $user ( sort keys %Stats ) + foreach $usr ( sort keys %Stats ) { - my $v = $hash->{$user}; + my $v = $Stats{$usr}; if (defined($v)) { - if ($html) - { - printf "", $v, - (100.0/$total)*$v; - } - else - { - printf "%8d (%4.1f%%): %s\n", $v, (100.0/$total)*$v, $user; + if ($html) { + printf "", $v, (100.0/$total)*$v,$usr; + } else { + printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $usr; } } - elsif ($html) - { - print ""; + } + print "
LOC\%LOCUser
%d
(%2.1f%%)
%d(%4.1f%%)%s
\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 "\n"; + } else { + print $user,":\n"; + } + foreach $file (sort keys %{$FileStats{$user}}) { + my $v = ${$FileStats{$user}}{$file}; + if ($html) { + printf "",$v, (100.0/$total)*$v,$file; + } else { + printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $file; + } + } + if ($html) { print "
$user
  %d %4.1f%%%s
\n"; } } } - print "\n" if ($html); } my @ALLDIRS = @ARGV; @@ -223,16 +240,10 @@ for $Dir (@ALLDIRS) } } -if ($html) -{ - print "\n"; -} - -printStats("Total",\%Stats); +printStats; if ($html) { - print "
"; if (scalar @ignored_dirs > 0) { print "

The following directories were skipped:

\n"; print "
    \n";