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 # Report details about lines of code in each file for each user
22 # Generate HTML output instead of text output
24 die "Usage userloc.pl [-recurse|-tag=tag|-html] <directories>..."
32 while ( substr($ARGV[0],0,1) eq '-' )
34 if ($ARGV[0] eq "-recurse") {
36 } elsif ($ARGV[0] =~ /-tag=.*/) {
38 $tag =~ s#-tag=(.*)#$1#;
39 } elsif ($ARGV[0] =~ /-filedetails/) {
41 } elsif ($ARGV[0] eq "-html") {
43 } elsif ($ARGV[0] eq "-debug") {
46 die "Invalid option: $ARGV[0]";
51 die "Usage userloc.pl [-recurse|-tag=tag|-html] <directories>..."
62 if ( $d =~ ".*autoconf.*")
64 return 1 if ($f eq "configure.ac");
65 return 1 if ($f eq "AutoRegen.sh");
68 return 0 if ( "$f" eq "configure");
69 return 0 if ( "$f" eq 'PPCPerfectShuffle.h' );
70 return 0 if ( $f =~ /.*\.cvs/);
78 open STATUS, "cvs -nfz6 status $d -l 2>/dev/null |"
79 || die "Can't 'cvs status'";
80 while ( defined($line = <STATUS>) )
82 if ( $line =~ /^File:.*/ )
85 $line =~ s#^File: ([A-Za-z0-9._-]*)[ \t]*Status:.*#$1#;
86 $files = "$files $d/$line" if (ValidateFile($line,$d));
93 my $annotate = "cvs -z6 annotate -lf ";
96 $annotate = $annotate . " -r" . $tag;
102 my $files = GetCVSFiles($Dir);
104 open (DATA,"$annotate $files 2>&1 |")
105 || die "Can't read cvs annotation data";
108 while ( defined($line = <DATA>) )
111 if ($line =~ '^Annotations for.*') {
113 $curfile =~ s#^Annotations for ([[:print:]]*)#$1#;
114 } elsif ($line =~ /^[0-9.]*[ \t]*\([^)]*\):/) {
116 $uname =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*) [^)]*\):.*#$1#;
119 $FileStats{$uname} = {} unless exists $FileStats{$uname};
120 ${$FileStats{$uname}}{$curfile}++;
127 sub ValidateDirectory
130 return 0 if (! -d "$d" || ! -d "$d/CVS");
131 return 0 if ($d =~ /.*CVS.*/);
132 return 0 if ($d =~ /.*Debug.*/);
133 return 0 if ($d =~ /.*Release.*/);
134 return 0 if ($d =~ /.*Profile.*/);
135 return 0 if ($d =~ /.*docs\/CommandGuide\/html.*/);
136 return 0 if ($d =~ /.*docs\/CommandGuide\/man.*/);
137 return 0 if ($d =~ /.*docs\/CommandGuide\/ps.*/);
138 return 0 if ($d =~ /.*docs\/CommandGuide\/man.*/);
139 return 0 if ($d =~ /.*docs\/HistoricalNotes.*/);
140 return 0 if ($d =~ /.*docs\/img.*/);
141 return 0 if ($d =~ /.*bzip2.*/);
142 return 1 if ($d =~ /.*projects\/Stacker.*/);
143 return 1 if ($d =~ /.*projects\/sample.*/);
144 return 0 if ($d =~ /.*projects\/llvm-.*/);
145 return 0 if ($d =~ /.*win32.*/);
146 return 0 if ($d =~ /.*\/.libs\/.*/);
157 foreach $usr (keys %Stats) { $total += $Stats{$usr}; }
161 print " <tr><th style=\"text-align:right\">LOC</th>\n";
162 print " <th style=\"text-align:right\">\%LOC</th>\n";
163 print " <th style=\"text-align:left\">User</th>\n";
167 foreach $usr ( sort keys %Stats )
169 my $v = $Stats{$usr};
173 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,$usr;
175 printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $usr;
179 print "</table>\n" if ($html);
182 foreach $user (sort keys %FileStats) {
184 foreach $file (sort keys %{$FileStats{$user}}) {
185 $total += ${$FileStats{$user}}{$file}
188 print "<table><tr><th style=\"text-align:left\" colspan=\"3\">$user</th></tr>\n";
192 foreach $file (sort keys %{$FileStats{$user}}) {
193 my $v = ${$FileStats{$user}}{$file};
195 printf "<tr><td style=\"text-align:right\"> %d</td><td
196 style=\"text-align:right\"> %4.1f%%</td><td
197 style=\"text-align:left\">%s</td></tr>",$v, (100.0/$total)*$v,$file;
199 printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $file;
202 if ($html) { print "</table>\n"; }
211 $Dirs = join(" ", @ARGV);
212 $Dirs = `find $Dirs -type d \! -name CVS -print`;
213 @ALLDIRS = split(' ',$Dirs);
218 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
219 print "<html>\n<head>\n";
220 print " <title>LLVM LOC Based On CVS Annotation</title>\n";
221 print " <link rel=\"stylesheet\" href=\"llvm.css\" type=\"text/css\"/>\n";
223 print "<body><div class=\"doc_title\">LLVM LOC Based On CVS Annotation</div>\n";
224 print "<p>This document shows the total lines of code per user in each\n";
225 print "LLVM directory. Lines of code are attributed by the user that last\n";
226 print "committed the line. This does not necessarily reflect authorship.</p>\n";
233 if ( ValidateDirectory($Dir) )
239 push @ignored_dirs, $Dir;
247 if (scalar @ignored_dirs > 0) {
248 print "<p>The following directories were skipped:</p>\n";
250 foreach $index (0 .. $#ignored_dirs) {
251 print " <li>", $ignored_dirs[$index], "</li>\n";
255 print "</body></html>\n";