Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # |
| 3 | # Program: userloc.pl |
| 4 | # |
| 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 |
| 9 | # from cvs. |
| 10 | # |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 11 | # Syntax: userloc.pl [-tag=tag|-html... <directory>... |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 12 | # |
| 13 | # Options: |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 14 | # -tag=tag |
| 15 | # Use "tag" to select the revision (as per cvs -r option) |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 16 | # -filedetails |
| 17 | # Report details about lines of code in each file for each user |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 18 | # -html |
| 19 | # Generate HTML output instead of text output |
Reid Spencer | ca7592a | 2006-08-14 18:49:05 +0000 | [diff] [blame] | 20 | # -topdir |
| 21 | # Specify where the top llvm source directory is. Otherwise the |
| 22 | # llvm-config tool is used to find it. |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 23 | # Directories: |
| 24 | # The directories passed after the options should be relative paths to |
| 25 | # directories of interest from the top of the llvm source tree, e.g. "lib" |
| 26 | # or "include", etc. |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 27 | |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 28 | die "Usage userloc.pl [-tag=tag|-html] <directories>..." |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 29 | if ($#ARGV < 0); |
| 30 | |
| 31 | my $tag = ""; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 32 | my $html = 0; |
Reid Spencer | bb6f6eb | 2006-08-11 18:36:55 +0000 | [diff] [blame] | 33 | my $debug = 0; |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 34 | my $filedetails = ""; |
Reid Spencer | ca7592a | 2006-08-14 18:49:05 +0000 | [diff] [blame] | 35 | my $srcroot = ""; |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 36 | while ( defined($ARGV[0]) && substr($ARGV[0],0,1) eq '-' ) |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 37 | { |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 38 | if ($ARGV[0] =~ /-tag=.*/) { |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 39 | $tag = $ARGV[0]; |
| 40 | $tag =~ s#-tag=(.*)#$1#; |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 41 | } elsif ($ARGV[0] =~ /-filedetails/) { |
| 42 | $filedetails = 1; |
Reid Spencer | bb6f6eb | 2006-08-11 18:36:55 +0000 | [diff] [blame] | 43 | } elsif ($ARGV[0] eq "-html") { |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 44 | $html = 1; |
Reid Spencer | bb6f6eb | 2006-08-11 18:36:55 +0000 | [diff] [blame] | 45 | } elsif ($ARGV[0] eq "-debug") { |
| 46 | $debug = 1; |
Reid Spencer | ca7592a | 2006-08-14 18:49:05 +0000 | [diff] [blame] | 47 | } elsif ($ARGV[0] eq "-topdir") { |
| 48 | shift; $srcroot = $ARGV[0]; shift; |
Reid Spencer | bb6f6eb | 2006-08-11 18:36:55 +0000 | [diff] [blame] | 49 | } else { |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 50 | die "Invalid option: $ARGV[0]"; |
| 51 | } |
| 52 | shift; |
| 53 | } |
| 54 | |
Reid Spencer | ca7592a | 2006-08-14 18:49:05 +0000 | [diff] [blame] | 55 | if (length($srcroot) == 0) { |
| 56 | chomp($srcroot = `llvm-config --src-root`); |
| 57 | } |
| 58 | if (! -d "$srcroot") { |
| 59 | die "Invalid source root: $srcroot\n"; |
| 60 | } |
Reid Spencer | 3219563 | 2006-08-13 19:03:06 +0000 | [diff] [blame] | 61 | chdir($srcroot); |
Reid Spencer | ca7592a | 2006-08-14 18:49:05 +0000 | [diff] [blame] | 62 | my $llvmdo = "$srcroot/utils/llvmdo -topdir '$srcroot'"; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 63 | my %Stats; |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 64 | my %FileStats; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 65 | |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 66 | my $annotate = "cvs -z6 annotate -lf "; |
| 67 | if (length($tag) > 0) |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 68 | { |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 69 | $annotate = $annotate . " -r" . $tag; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | sub GetCVSFiles |
| 73 | { |
| 74 | my $d = $_[0]; |
| 75 | my $files =""; |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 76 | open FILELIST, |
Reid Spencer | 3219563 | 2006-08-13 19:03:06 +0000 | [diff] [blame] | 77 | "$llvmdo -dirs \"$d\" -code-only echo |" || die "Can't get list of files with llvmdo"; |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 78 | while ( defined($line = <FILELIST>) ) { |
| 79 | chomp($file = $line); |
Reid Spencer | 3219563 | 2006-08-13 19:03:06 +0000 | [diff] [blame] | 80 | print "File: $file\n" if ($debug); |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 81 | $files = "$files $file"; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 82 | } |
| 83 | return $files; |
| 84 | } |
| 85 | |
Reid Spencer | bb6f6eb | 2006-08-11 18:36:55 +0000 | [diff] [blame] | 86 | sub ScanDir |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 87 | { |
| 88 | my $Dir = $_[0]; |
| 89 | my $files = GetCVSFiles($Dir); |
| 90 | |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 91 | open (DATA,"$annotate $files 2>&1 |") |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 92 | || die "Can't read cvs annotation data"; |
| 93 | |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 94 | my $curfile = ""; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 95 | while ( defined($line = <DATA>) ) |
| 96 | { |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 97 | chomp($line); |
| 98 | if ($line =~ '^Annotations for.*') { |
| 99 | $curfile = $line; |
| 100 | $curfile =~ s#^Annotations for ([[:print:]]*)#$1#; |
Reid Spencer | 3219563 | 2006-08-13 19:03:06 +0000 | [diff] [blame] | 101 | print "Scanning: $curfile\n" if ($debug); |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 102 | } elsif ($line =~ /^[0-9.]*[ \t]*\([^)]*\):/) { |
| 103 | $uname = $line; |
| 104 | $uname =~ s#^[0-9.]*[ \t]*\(([a-zA-Z0-9_.-]*) [^)]*\):.*#$1#; |
| 105 | $Stats{$uname}++; |
| 106 | if ($filedetails) { |
| 107 | $FileStats{$uname} = {} unless exists $FileStats{$uname}; |
| 108 | ${$FileStats{$uname}}{$curfile}++; |
| 109 | } |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 112 | close DATA; |
| 113 | } |
| 114 | |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 115 | sub printStats |
| 116 | { |
| 117 | my $dir = $_[0]; |
| 118 | my $hash = $_[1]; |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 119 | my $user; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 120 | my $total = 0; |
| 121 | |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 122 | foreach $user (keys %Stats) { $total += $Stats{$user}; } |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 123 | |
| 124 | if ($html) { |
Reid Spencer | 3219563 | 2006-08-13 19:03:06 +0000 | [diff] [blame] | 125 | print "<p>Total Source Lines: $total<br/></p>\n"; |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 126 | print "<table>"; |
| 127 | print " <tr><th style=\"text-align:right\">LOC</th>\n"; |
| 128 | print " <th style=\"text-align:right\">\%LOC</th>\n"; |
| 129 | print " <th style=\"text-align:left\">User</th>\n"; |
| 130 | print "</tr>\n"; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 133 | foreach $user ( sort keys %Stats ) |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 134 | { |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 135 | my $v = $Stats{$user}; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 136 | if (defined($v)) |
| 137 | { |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 138 | if ($html) { |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 139 | 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; |
| 140 | if ($filedetails) { |
| 141 | print "<a href=\"#$user\">$user</a></td></tr>"; |
| 142 | } else { |
| 143 | print $user,"</td></tr>"; |
| 144 | } |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 145 | } else { |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 146 | printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $user; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 147 | } |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 150 | print "</table>\n" if ($html); |
| 151 | |
| 152 | if ($filedetails) { |
| 153 | foreach $user (sort keys %FileStats) { |
| 154 | my $total = 0; |
| 155 | foreach $file (sort keys %{$FileStats{$user}}) { |
| 156 | $total += ${$FileStats{$user}}{$file} |
| 157 | } |
| 158 | if ($html) { |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 159 | print "<table><tr><th style=\"text-align:left\" colspan=\"3\"><a name=\"$user\">$user</a></th></tr>\n"; |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 160 | } else { |
| 161 | print $user,":\n"; |
| 162 | } |
| 163 | foreach $file (sort keys %{$FileStats{$user}}) { |
| 164 | my $v = ${$FileStats{$user}}{$file}; |
| 165 | if ($html) { |
| 166 | printf "<tr><td style=\"text-align:right\"> %d</td><td |
| 167 | style=\"text-align:right\"> %4.1f%%</td><td |
| 168 | style=\"text-align:left\">%s</td></tr>",$v, (100.0/$total)*$v,$file; |
| 169 | } else { |
| 170 | printf "%8d (%4.1f%%) %s\n", $v, (100.0/$total)*$v, $file; |
| 171 | } |
| 172 | } |
| 173 | if ($html) { print "</table>\n"; } |
| 174 | } |
| 175 | } |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 178 | |
| 179 | if ($html) |
| 180 | { |
| 181 | print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n"; |
| 182 | print "<html>\n<head>\n"; |
| 183 | print " <title>LLVM LOC Based On CVS Annotation</title>\n"; |
| 184 | print " <link rel=\"stylesheet\" href=\"llvm.css\" type=\"text/css\"/>\n"; |
| 185 | print "</head>\n"; |
| 186 | print "<body><div class=\"doc_title\">LLVM LOC Based On CVS Annotation</div>\n"; |
| 187 | print "<p>This document shows the total lines of code per user in each\n"; |
| 188 | print "LLVM directory. Lines of code are attributed by the user that last\n"; |
| 189 | print "committed the line. This does not necessarily reflect authorship.</p>\n"; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 192 | my @DIRS; |
| 193 | if ($#ARGV > 0) { |
| 194 | @DIRS = @ARGV; |
| 195 | } else { |
| 196 | push @DIRS, 'include'; |
| 197 | push @DIRS, 'lib'; |
| 198 | push @DIRS, 'tools'; |
| 199 | push @DIRS, 'runtime'; |
| 200 | push @DIRS, 'docs'; |
| 201 | push @DIRS, 'test'; |
| 202 | push @DIRS, 'utils'; |
| 203 | push @DIRS, 'examples'; |
| 204 | push @DIRS, 'projects/Stacker'; |
| 205 | push @DIRS, 'projects/sample'; |
| 206 | push @DIRS, 'autoconf'; |
| 207 | } |
| 208 | |
| 209 | for $Index ( 0 .. $#DIRS) { |
Reid Spencer | 3219563 | 2006-08-13 19:03:06 +0000 | [diff] [blame] | 210 | print "Scanning Dir: $DIRS[$Index]\n" if ($debug); |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 211 | ScanDir($DIRS[$Index]); |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Reid Spencer | ae2e622 | 2006-08-11 20:44:17 +0000 | [diff] [blame] | 214 | printStats; |
Reid Spencer | 4dd4e6a | 2005-05-16 18:30:38 +0000 | [diff] [blame] | 215 | |
Reid Spencer | c0d5ed3 | 2006-08-11 23:50:27 +0000 | [diff] [blame] | 216 | print "</body></html>\n" if ($html) ; |