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 [-recurse|-tag=tag|-html... <directory>...
15 # Recurse through sub directories. Without this, only the
16 # specified directory is examined
18 # Use "tag" to select the revision (as per cvs -r option)
20 # Generate HTML output instead of text output
22 die "Usage userloc.pl [-recurse|-tag=tag|-html] <directories>..."
29 while ( substr($ARGV[0],0,1) eq '-' )
31 if ($ARGV[0] eq "-recurse") {
33 } elsif ($ARGV[0] =~ /-tag=.*/) {
35 $tag =~ s#-tag=(.*)#$1#;
36 } elsif ($ARGV[0] eq "-html") {
38 } elsif ($ARGV[0] eq "-debug") {
41 die "Invalid option: $ARGV[0]";
46 die "Usage userloc.pl [-recurse|-tag=tag|-html] <directories>..."
57 if ( $d =~ ".*autoconf.*")
59 return 1 if ($f eq "configure.ac");
60 return 1 if ($f eq "AutoRegen.sh");
63 return 0 if ( "$f" eq "configure");
64 return 0 if ( "$f" eq 'PPCPerfectShuffle.h' );
65 return 0 if ( $f =~ /.*\.cvs/);
73 open STATUS, "cvs -nfz6 status $d -l 2>/dev/null |"
74 || die "Can't 'cvs status'";
75 while ( defined($line = <STATUS>) )
77 if ( $line =~ /^File:.*/ )
80 $line =~ s#^File: ([A-Za-z0-9._-]*)[ \t]*Status:.*#$1#;
81 $files = "$files $d/$line" if (ValidateFile($line,$d));
88 my $annotate = "cvs -z6 annotate -lf ";
91 $annotate = $annotate . " -r" . $tag;
97 my $files = GetCVSFiles($Dir);
99 open (DATA,"$annotate $files 2>/dev/null |")
100 || die "Can't read cvs annotation data";
102 while ( defined($line = <DATA>) )
104 if ($line =~ /^[0-9.]*[ \t]*\([^)]*\):/)
107 $line =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*) [^)]*\):.*#$1#;
115 sub ValidateDirectory
118 return 0 if (! -d "$d" || ! -d "$d/CVS");
119 return 0 if ($d =~ /.*CVS.*/);
120 return 0 if ($d =~ /.*Debug.*/);
121 return 0 if ($d =~ /.*Release.*/);
122 return 0 if ($d =~ /.*Profile.*/);
123 return 0 if ($d =~ /.*docs\/CommandGuide\/html.*/);
124 return 0 if ($d =~ /.*docs\/CommandGuide\/man.*/);
125 return 0 if ($d =~ /.*docs\/CommandGuide\/ps.*/);
126 return 0 if ($d =~ /.*docs\/CommandGuide\/man.*/);
127 return 0 if ($d =~ /.*docs\/HistoricalNotes.*/);
128 return 0 if ($d =~ /.*docs\/img.*/);
129 return 0 if ($d =~ /.*bzip2.*/);
130 return 1 if ($d =~ /.*projects\/Stacker.*/);
131 return 1 if ($d =~ /.*projects\/sample.*/);
132 return 0 if ($d =~ /.*projects\/llvm-.*/);
133 return 0 if ($d =~ /.*win32.*/);
134 return 0 if ($d =~ /.*\/.libs\/.*/);
146 if ($RowCount % 10 == 0)
149 print " <tr><th style=\"text-align:left\">Directory</th>\n";
150 foreach $user (sort keys %Stats)
152 print "<th style=\"text-align:right\">",$user,"</th>\n";
161 { print "<tr><td style=\"text-align:left\">",$dir,"</td>"; }
165 foreach $user (keys %{$hash}) { $total += $hash->{$user}; }
167 foreach $user ( sort keys %Stats )
169 my $v = $hash->{$user};
174 printf "<td style=\"text-align:right\">%d<br/>(%2.1f%%)</td>", $v,
179 printf "%8d (%4.1f%%): %s\n", $v, (100.0/$total)*$v, $user;
184 print "<td style=\"text-align:right\">- </td>";
187 print "</tr>\n" if ($html);
194 $Dirs = join(" ", @ARGV);
195 $Dirs = `find $Dirs -type d \! -name CVS -print`;
196 @ALLDIRS = split(' ',$Dirs);
201 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
202 print "<html>\n<head>\n";
203 print " <title>LLVM LOC Based On CVS Annotation</title>\n";
204 print " <link rel=\"stylesheet\" href=\"llvm.css\" type=\"text/css\"/>\n";
206 print "<body><div class=\"doc_title\">LLVM LOC Based On CVS Annotation</div>\n";
207 print "<p>This document shows the total lines of code per user in each\n";
208 print "LLVM directory. Lines of code are attributed by the user that last\n";
209 print "committed the line. This does not necessarily reflect authorship.</p>\n";
216 if ( ValidateDirectory($Dir) )
222 push @ignored_dirs, $Dir;
231 printStats("Total",\%Stats);
236 if (scalar @ignored_dirs > 0) {
237 print "<p>The following directories were skipped:</p>\n";
239 foreach $index (0 .. $#ignored_dirs) {
240 print " <li>", $ignored_dirs[$index], "</li>\n";
244 print "</body></html>\n";