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 [-details|-recurse|-tag=tag|-html... <directory>...
15 # Print detailed per-directory information.
17 # Recurse through sub directories. Without this, only the
18 # specified directory is examined
20 # Use "tag" to select the revision (as per cvs -r option)
22 # Generate HTML output instead of text output
24 die "Usage userloc.pl [-details|-recurse|-tag=tag|-html] <directories>..."
31 while ( substr($ARGV[0],0,1) eq '-' )
33 if ($ARGV[0] eq "-details")
37 elsif ($ARGV[0] eq "-recurse")
41 elsif ($ARGV[0] =~ /-tag=.*/)
44 $tag =~ s#-tag=(.*)#$1#;
46 elsif ($ARGV[0] eq "-html")
52 die "Invalid option: $ARGV[0]";
57 die "Usage userloc.pl [-details|-recurse|-tag=tag|-html] <directories>..."
68 return 0 if ( "$f" eq "configure");
69 if ( $d =~ ".*autoconf.*")
71 return 1 if ($f eq "configure.ac");
72 return 1 if ($f eq "AutoRegen.sh");
83 open STATUS, "cvs -nfz6 status $d -l 2>/dev/null |"
84 || die "Can't 'cvs status'";
85 while ( defined($line = <STATUS>) )
87 if ( $line =~ /^File:.*/ )
90 $line =~ s#^File: ([A-Za-z0-9._-]*)[ \t]*Status:.*#$1#;
91 $files = "$files $d/$line" if (ValidateFile($line,$d));
98 my $annotate = "cvs annotate -lf ";
101 $annotate = $annotate . " -r " . $tag;
107 my $files = GetCVSFiles($Dir);
109 open (DATA,"$annotate $files 2>/dev/null |")
110 || die "Can't read cvs annotation data";
113 while ( defined($line = <DATA>) )
115 if ($line =~ /^[0-9.]*[ \t]*\(/)
117 $line =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*).*#$1#;
124 $StatsDetails{$Dir} = { %st };
129 sub ValidateDirectory
132 return 0 if ($d =~ /.*CVS.*/);
133 return 0 if ($d =~ /.*Debug.*/);
134 return 0 if ($d =~ /.*Release.*/);
135 return 0 if ($d =~ /.*Profile.*/);
136 return 0 if ($d =~ /.*utils\/Burg.*/);
137 return 0 if ($d =~ /.*docs\/CommandGuide\/html.*/);
138 return 0 if ($d =~ /.*docs\/CommandGuide\/man.*/);
139 return 0 if ($d =~ /.*docs\/CommandGuide\/ps.*/);
140 return 0 if ($d =~ /.*docs\/CommandGuide\/man.*/);
141 return 0 if ($d =~ /.*docs\/HistoricalNotes.*/);
142 return 0 if ($d =~ /.*docs\/img.*/);
143 return 0 if ($d =~ /.*bzip2.*/);
144 return 1 if ($d =~ /.*projects\/Stacker.*/);
145 return 1 if ($d =~ /.*projects\/sample.*/);
146 return 0 if ($d =~ /.*projects\/llvm-.*/);
147 return 0 if ($d =~ /.*win32.*/);
159 if ($RowCount % 10 == 0)
161 print " <tr><th style=\"text-align:left\">Directory</th>\n";
162 foreach $user (sort keys %Stats)
164 print "<th style=\"text-align:right\">",$user,"</th>\n";
172 { print "<tr><td style=\"text-align:left\">",$dir,"</td>"; }
176 foreach $user (keys %{$hash}) { $total += $hash->{$user}; }
178 foreach $user ( sort keys %Stats )
180 my $v = $hash->{$user};
185 printf "<td style=\"text-align:right\">%d<br/>(%2.1f%%)</td>", $v,
190 printf "%8d (%4.1f%%): %s\n", $v, (100.0/$total)*$v, $user;
195 print "<td style=\"text-align:right\">- </td>";
198 print "</tr>\n" if ($html);
205 $Dirs = join(" ", @ARGV);
206 $Dirs = `find $Dirs -type d \! -name CVS -print`;
207 @ALLDIRS = split(' ',$Dirs);
212 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
213 print "<html>\n<head>\n";
214 print " <title>LLVM LOC Based On CVS Annotation</title>\n";
215 print " <link rel=\"stylesheet\" href=\"llvm.css\" type=\"text/css\"/>\n";
217 print "<body><div class=\"doc_title\">LLVM LOC Based On CVS Annotation</div>\n";
218 print "<p>This document shows the total lines of code per user in each\n";
219 print "LLVM directory. Lines of code are attributed by the user that last\n";
220 print "committed the line. This does not necessarily reflect authorship.</p>\n";
221 print "<p>The following directories were skipped:</p>\n";
227 if ( -d "$Dir" && -d "$Dir/CVS" && ValidateDirectory($Dir) )
233 print "<li>$Dir</li>\n";
245 foreach $dir (sort keys %StatsDetails)
247 printStats($dir,$StatsDetails{$dir});
251 printStats("Total",\%Stats);
256 print "</table></body></html>\n";