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`);
50 my $llvmdo = "$srcroot/utils/llvmdo";
54 my $annotate = "cvs -z6 annotate -lf ";
57 $annotate = $annotate . " -r" . $tag;
65 "$llvmdo -dirs \"$d\" echo |" || die "Can't get list of files with llvmdo";
66 while ( defined($line = <FILELIST>) ) {
68 $files = "$files $file";
76 my $files = GetCVSFiles($Dir);
78 open (DATA,"$annotate $files 2>&1 |")
79 || die "Can't read cvs annotation data";
82 while ( defined($line = <DATA>) )
85 if ($line =~ '^Annotations for.*') {
87 $curfile =~ s#^Annotations for ([[:print:]]*)#$1#;
88 } elsif ($line =~ /^[0-9.]*[ \t]*\([^)]*\):/) {
90 $uname =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*) [^)]*\):.*#$1#;
93 $FileStats{$uname} = {} unless exists $FileStats{$uname};
94 ${$FileStats{$uname}}{$curfile}++;
108 foreach $user (keys %Stats) { $total += $Stats{$user}; }
112 print " <tr><th style=\"text-align:right\">LOC</th>\n";
113 print " <th style=\"text-align:right\">\%LOC</th>\n";
114 print " <th style=\"text-align:left\">User</th>\n";
118 foreach $user ( sort keys %Stats )
120 my $v = $Stats{$user};
124 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;
126 print "<a href=\"#$user\">$user</a></td></tr>";
128 print $user,"</td></tr>";
131 printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $user;
135 print "</table>\n" if ($html);
138 foreach $user (sort keys %FileStats) {
140 foreach $file (sort keys %{$FileStats{$user}}) {
141 $total += ${$FileStats{$user}}{$file}
144 print "<table><tr><th style=\"text-align:left\" colspan=\"3\"><a name=\"$user\">$user</a></th></tr>\n";
148 foreach $file (sort keys %{$FileStats{$user}}) {
149 my $v = ${$FileStats{$user}}{$file};
151 printf "<tr><td style=\"text-align:right\"> %d</td><td
152 style=\"text-align:right\"> %4.1f%%</td><td
153 style=\"text-align:left\">%s</td></tr>",$v, (100.0/$total)*$v,$file;
155 printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $file;
158 if ($html) { print "</table>\n"; }
166 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
167 print "<html>\n<head>\n";
168 print " <title>LLVM LOC Based On CVS Annotation</title>\n";
169 print " <link rel=\"stylesheet\" href=\"llvm.css\" type=\"text/css\"/>\n";
171 print "<body><div class=\"doc_title\">LLVM LOC Based On CVS Annotation</div>\n";
172 print "<p>This document shows the total lines of code per user in each\n";
173 print "LLVM directory. Lines of code are attributed by the user that last\n";
174 print "committed the line. This does not necessarily reflect authorship.</p>\n";
181 push @DIRS, 'include';
184 push @DIRS, 'runtime';
188 push @DIRS, 'examples';
189 push @DIRS, 'projects/Stacker';
190 push @DIRS, 'projects/sample';
191 push @DIRS, 'autoconf';
194 for $Index ( 0 .. $#DIRS) {
195 ScanDir($DIRS[$Index]);
200 print "</body></html>\n" if ($html) ;