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 [-tag=tag|-html... <directory>...
15 # Use "tag" to select the revision (as per cvs -r option)
17 # Report details about lines of code in each file for each user
19 # Generate HTML output instead of text output
21 # The directories passed after the options should be relative paths to
22 # directories of interest from the top of the llvm source tree, e.g. "lib"
25 die "Usage userloc.pl [-tag=tag|-html] <directories>..."
32 while ( defined($ARGV[0]) && substr($ARGV[0],0,1) eq '-' )
34 if ($ARGV[0] =~ /-tag=.*/) {
36 $tag =~ s#-tag=(.*)#$1#;
37 } elsif ($ARGV[0] =~ /-filedetails/) {
39 } elsif ($ARGV[0] eq "-html") {
41 } elsif ($ARGV[0] eq "-debug") {
44 die "Invalid option: $ARGV[0]";
49 chomp(my $srcroot = `llvm-config --src-root`);
51 my $llvmdo = "$srcroot/utils/llvmdo";
55 my $annotate = "cvs -z6 annotate -lf ";
58 $annotate = $annotate . " -r" . $tag;
66 "$llvmdo -dirs \"$d\" -code-only echo |" || die "Can't get list of files with llvmdo";
67 while ( defined($line = <FILELIST>) ) {
69 print "File: $file\n" if ($debug);
70 $files = "$files $file";
78 my $files = GetCVSFiles($Dir);
80 open (DATA,"$annotate $files 2>&1 |")
81 || die "Can't read cvs annotation data";
84 while ( defined($line = <DATA>) )
87 if ($line =~ '^Annotations for.*') {
89 $curfile =~ s#^Annotations for ([[:print:]]*)#$1#;
90 print "Scanning: $curfile\n" if ($debug);
91 } elsif ($line =~ /^[0-9.]*[ \t]*\([^)]*\):/) {
93 $uname =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*) [^)]*\):.*#$1#;
96 $FileStats{$uname} = {} unless exists $FileStats{$uname};
97 ${$FileStats{$uname}}{$curfile}++;
111 foreach $user (keys %Stats) { $total += $Stats{$user}; }
114 print "<p>Total Source Lines: $total<br/></p>\n";
116 print " <tr><th style=\"text-align:right\">LOC</th>\n";
117 print " <th style=\"text-align:right\">\%LOC</th>\n";
118 print " <th style=\"text-align:left\">User</th>\n";
122 foreach $user ( sort keys %Stats )
124 my $v = $Stats{$user};
128 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;
130 print "<a href=\"#$user\">$user</a></td></tr>";
132 print $user,"</td></tr>";
135 printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $user;
139 print "</table>\n" if ($html);
142 foreach $user (sort keys %FileStats) {
144 foreach $file (sort keys %{$FileStats{$user}}) {
145 $total += ${$FileStats{$user}}{$file}
148 print "<table><tr><th style=\"text-align:left\" colspan=\"3\"><a name=\"$user\">$user</a></th></tr>\n";
152 foreach $file (sort keys %{$FileStats{$user}}) {
153 my $v = ${$FileStats{$user}}{$file};
155 printf "<tr><td style=\"text-align:right\"> %d</td><td
156 style=\"text-align:right\"> %4.1f%%</td><td
157 style=\"text-align:left\">%s</td></tr>",$v, (100.0/$total)*$v,$file;
159 printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $file;
162 if ($html) { print "</table>\n"; }
170 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
171 print "<html>\n<head>\n";
172 print " <title>LLVM LOC Based On CVS Annotation</title>\n";
173 print " <link rel=\"stylesheet\" href=\"llvm.css\" type=\"text/css\"/>\n";
175 print "<body><div class=\"doc_title\">LLVM LOC Based On CVS Annotation</div>\n";
176 print "<p>This document shows the total lines of code per user in each\n";
177 print "LLVM directory. Lines of code are attributed by the user that last\n";
178 print "committed the line. This does not necessarily reflect authorship.</p>\n";
185 push @DIRS, 'include';
188 push @DIRS, 'runtime';
192 push @DIRS, 'examples';
193 push @DIRS, 'projects/Stacker';
194 push @DIRS, 'projects/sample';
195 push @DIRS, 'autoconf';
198 for $Index ( 0 .. $#DIRS) {
199 print "Scanning Dir: $DIRS[$Index]\n" if ($debug);
200 ScanDir($DIRS[$Index]);
205 print "</body></html>\n" if ($html) ;