| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strict; |
| 4 | use diagnostics; |
| 5 | |
| 6 | #use Data::Dumper; |
| 7 | #use Date::Manip qw(ParseDate UnixDate); #sudo apt-get install libdate-manip-perl |
| 8 | #use Date::Calc qw(Delta_Days); #sudo apt-get install libdate-calc-perl |
| 9 | |
| 10 | #------------------------------------------------------------------------------ |
| 11 | # Helpers |
| 12 | #------------------------------------------------------------------------------ |
| 13 | |
| 14 | my $debug = 0; |
| 15 | |
| 16 | sub pr2 { print STDERR "@_\n"; } |
| 17 | sub pr { print "@_\n"; } |
| 18 | sub mylog { print STDERR "@_\n" if $debug; } |
| 19 | |
| 20 | sub plural { |
| 21 | my ($n) = @_; |
| 22 | $n > 1 ? "s" : ""; |
| 23 | } |
| 24 | |
| 25 | #------------------------------------------------------------------------------ |
| 26 | # Globals |
| 27 | #------------------------------------------------------------------------------ |
| 28 | |
| 29 | my $ok = 0; |
| 30 | my $so = 0; #spatch ok |
| 31 | my $fa = 0; #failed |
| 32 | my $gu = 0; #gave up |
| 33 | |
| 34 | my $nbfiles = 0; |
| 35 | |
| 36 | my $maxtime = 0; |
| 37 | #my $mintime = 0; |
| 38 | my $sumtime = 0; |
| 39 | |
| 40 | my $sumlinefiles = 0; |
| 41 | |
| 42 | my $errors = 0; |
| 43 | |
| 44 | my $sumlineP = 0; #whole git |
| 45 | my $sumlineP2 = 0; |
| 46 | my $sumlinePchange = 0; |
| 47 | |
| 48 | my $spfile = ""; |
| 49 | my $ruleno = "??"; |
| 50 | my $sizeSP = 0; |
| 51 | |
| 52 | my $cedescr = ""; |
| 53 | |
| 54 | my $numauthors = 0; |
| 55 | my $duration = 0; # in days |
| 56 | |
| 57 | my @cfiles = (); |
| 58 | |
| 59 | #------------------------------------------------------------------------------ |
| 60 | # SP |
| 61 | #------------------------------------------------------------------------------ |
| 62 | $spfile = `make sp_file`; |
| 63 | chomp $spfile; |
| 64 | |
| 65 | if($spfile =~ /(rule|mega|bt)(\d+)\.cocci/) { $ruleno = "$2"; } |
| 66 | |
| 67 | #------------------------------------------------------------------------------ |
| 68 | # CE |
| 69 | #------------------------------------------------------------------------------ |
| 70 | |
| 71 | #$cedescr = `make ce_descr`; |
| 72 | #chomp $cedescr; |
| 73 | #print STDERR (Dumper($cedescr)); |
| 74 | open TMP, "Makefile" or die "no Makefile file ?"; |
| 75 | while(<TMP>) { |
| 76 | if(/^(CE)?DESCRIPTION=["'](.*)["']/) { $cedescr = $2; } |
| 77 | } |
| 78 | |
| 79 | |
| 80 | |
| 81 | #$cedescr =~ s/\\/\\\\/g; |
| 82 | #$cedescr =~ s/\f/\\f/g; |
| 83 | #$cedescr =~ s/\t/\\t/g; |
| 84 | |
| 85 | #------------------------------------------------------------------------------ |
| 86 | # List c files |
| 87 | #------------------------------------------------------------------------------ |
| 88 | my $files = `make source_files`; |
| 89 | chomp $files; |
| 90 | @cfiles = split /\s+/, $files; |
| 91 | |
| 92 | $nbfiles = scalar(@cfiles); |
| 93 | |
| 94 | #------------------------------------------------------------------------------ |
| 95 | # Size files (lines) |
| 96 | #------------------------------------------------------------------------------ |
| 97 | map { |
| 98 | my ($linefile) = `wc -l $_`; |
| 99 | chomp $linefile; |
| 100 | die "wierd wc output" unless $linefile =~ /^(\d+) /; |
| 101 | $sumlinefiles += $1; |
| 102 | mylog "filesize $_ $1"; |
| 103 | } @cfiles; |
| 104 | |
| 105 | |
| 106 | #------------------------------------------------------------------------------ |
| 107 | # Size SP |
| 108 | #------------------------------------------------------------------------------ |
| 109 | $sizeSP = |
| 110 | `cat $spfile | perl -p -e "s/\\/\\/.*//g;" | grep -v '^[ \t]*\$' | wc -l`; |
| 111 | chomp $sizeSP; |
| 112 | |
| 113 | |
| 114 | #------------------------------------------------------------------------------ |
| 115 | # Bugs |
| 116 | #------------------------------------------------------------------------------ |
| 117 | if(!(-e "README")) { pr2 "no README file ?"; } |
| 118 | else { |
| 119 | open TMP, "README" or die "no README file ?"; |
| 120 | while(<TMP>) { |
| 121 | if (/\[bug\]/ || /status\]\s*bug/ || /status\]\s*BUG/ ) { |
| 122 | |
| 123 | # can also look for [semibug] but it's often related to [corrected_c] kind of pbs |
| 124 | #|| /status\]\s*semi-bug/ |
| 125 | |
| 126 | #pr2 "OLD BUG FORMAT: $_"; |
| 127 | $errors++ |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | |
| 133 | |
| 134 | #------------------------------------------------------------------------------ |
| 135 | # Size P (total) |
| 136 | #------------------------------------------------------------------------------ |
| 137 | |
| 138 | if(-e "gitinfo") { |
| 139 | ($sumlineP) = `cat gitinfo |wc -l`; |
| 140 | chomp $sumlineP; |
| 141 | } else { |
| 142 | pr2 "no GIT INFO?"; |
| 143 | } |
| 144 | |
| 145 | #------------------------------------------------------------------------------ |
| 146 | # Number of authors and duration |
| 147 | #------------------------------------------------------------------------------ |
| 148 | |
| 149 | |
| 150 | if(-e "gitinfo") { |
| 151 | |
| 152 | open TMP, "gitinfo" or die "no gitinfo file ?"; |
| 153 | |
| 154 | #for authors |
| 155 | my $h = {}; |
| 156 | |
| 157 | #for duration |
| 158 | my @mindate = (); |
| 159 | my @maxdate = (); |
| 160 | my $nodateyet = 1; |
| 161 | |
| 162 | while(<TMP>) { |
| 163 | #can also do: egrep "^Author" gitinfo | sort | uniq | wc -l |
| 164 | if (/^Author: (.*)/) { |
| 165 | $h->{$1}++; |
| 166 | } |
| 167 | |
| 168 | # if(/^Date: (.*) ([-+]\d+)?/) { |
| 169 | # my $date = ParseDate($1); |
| 170 | # if (!$date) { die "bad date" } |
| 171 | # else { |
| 172 | # my ($year, $month, $day) = UnixDate($date, "%Y", "%m", "%d"); |
| 173 | # my @current = ($year, $month, $day); |
| 174 | # if($nodateyet) { |
| 175 | # @mindate = @current; |
| 176 | # @maxdate = @current; |
| 177 | # $nodateyet = 0; |
| 178 | # } else { |
| 179 | # my $diff1 = Delta_Days(@mindate, @current); |
| 180 | # if($diff1 < 0) { @mindate = @current; } |
| 181 | # my $diff2 = Delta_Days(@current, @maxdate); |
| 182 | # if($diff2 < 0) { @maxdate = @current; } |
| 183 | # |
| 184 | # #pr2 "$diff1, $diff2"; |
| 185 | # } |
| 186 | # } |
| 187 | # } |
| 188 | |
| 189 | |
| 190 | |
| 191 | } |
| 192 | |
| 193 | # my $diff = Delta_Days(@mindate, @maxdate); |
| 194 | # if($diff == 1 || $diff == 0) { |
| 195 | # $duration = "1 day"; |
| 196 | # } |
| 197 | # elsif($diff < 31) { |
| 198 | # $duration = "$diff days"; |
| 199 | # } |
| 200 | # elsif($diff > 365) { |
| 201 | # my $years = int($diff / 365); |
| 202 | # my $s = plural($years); |
| 203 | # $duration = "$years year$s"; |
| 204 | # } |
| 205 | # elsif($diff > 31) { |
| 206 | # my $months = int($diff / 31); |
| 207 | # my $s = plural($months); |
| 208 | # $duration = "$months month$s"; |
| 209 | # } |
| 210 | # else { die "impossible"; } |
| 211 | |
| 212 | $duration = "xxx months"; |
| 213 | |
| 214 | $numauthors = scalar(keys %{$h}); |
| 215 | } else { |
| 216 | pr2 "no GIT INFO?"; |
| 217 | } |
| 218 | |
| 219 | |
| 220 | #------------------------------------------------------------------------------ |
| 221 | # Size P (only change for .c in drivers/ or sounds/ (the test files)) |
| 222 | #------------------------------------------------------------------------------ |
| 223 | |
| 224 | |
| 225 | foreach my $c (@cfiles) { |
| 226 | die "wierd: $c, with $spfile" unless ($c =~ /(.*)\.c$/); |
| 227 | my $base = $1; |
| 228 | my $bef = "$base.c"; |
| 229 | my $aft = "$base.res"; |
| 230 | if(-e "corrected_$base.res") { |
| 231 | $aft = "corrected_$base.res"; |
| 232 | mylog "found corrected"; |
| 233 | } |
| 234 | my $onlychange = 0; |
| 235 | open TMP, "diff -u -b -B $bef $aft |"; |
| 236 | |
| 237 | my $count = 0; |
| 238 | while(<TMP>) { |
| 239 | $count++; |
| 240 | |
| 241 | if (/^\+[^+]/) { $onlychange++; } |
| 242 | if (/^\-[^-]/) { $onlychange++; } |
| 243 | } |
| 244 | $sumlinePchange += $onlychange; |
| 245 | $sumlineP2 += $count; |
| 246 | } |
| 247 | |
| 248 | #------------------------------------------------------------------------------ |
| 249 | # Time |
| 250 | #------------------------------------------------------------------------------ |
| 251 | foreach my $c (@cfiles) { |
| 252 | die "" unless ($c =~ /(.*)\.c$/); |
| 253 | my $base = $1; |
| 254 | |
| 255 | my $diagnosefile = ""; |
| 256 | mylog "$base"; |
| 257 | |
| 258 | if(-e "$base.c.ok") { $ok++; $diagnosefile = "$base.c.ok"; } |
| 259 | if(-e "$base.c.failed") { $fa++; $diagnosefile = "$base.c.failed"; } |
| 260 | if(-e "$base.c.spatch_ok") { $so++; $diagnosefile = "$base.c.spatch_ok"; } |
| 261 | if(-e "$base.c.gave_up") { $gu++; $diagnosefile = "$base.c.gave_up"; } |
| 262 | |
| 263 | open TMP, $diagnosefile or die "no diagnose $base: $diagnosefile"; |
| 264 | my $found = 0; |
| 265 | my $time = 0; |
| 266 | while(<TMP>) { |
| 267 | # before -test_okfailed |
| 268 | # if (/real[ \t]+([0-9])+m([0-9]+)[.]([0-9]+)/) { |
| 269 | # $found++; |
| 270 | # |
| 271 | # $time = $1 * 60.0; # minutes |
| 272 | # $time += $2; # seconds |
| 273 | # $time += $3 / 1000.0; # 1/1000th sec. |
| 274 | # |
| 275 | # pr2 (sprintf "%4.1fs\n", $time); |
| 276 | # printf "I: %15s & %4.1fs\n", $c, $time; |
| 277 | # |
| 278 | # } |
| 279 | if (/time: (.*)/) { |
| 280 | $found++; |
| 281 | |
| 282 | $time = $1; |
| 283 | |
| 284 | mylog (sprintf "%4.1fs\n", $time); |
| 285 | printf "I: %15s & %4.1fs\n", $c, $time; |
| 286 | |
| 287 | } |
| 288 | |
| 289 | |
| 290 | } |
| 291 | die "not found time information in $diagnosefile" unless $found == 1; |
| 292 | |
| 293 | $sumtime += $time; |
| 294 | $maxtime = $time if $time > $maxtime; |
| 295 | |
| 296 | } |
| 297 | |
| 298 | #------------------------------------------------------------------------------ |
| 299 | # Computations |
| 300 | #------------------------------------------------------------------------------ |
| 301 | |
| 302 | my $correct = $ok + $so; |
| 303 | |
| 304 | my $pourcentcorrect = ($correct * 100.0) / $nbfiles; |
| 305 | my $avglines = $sumlinefiles / $nbfiles; |
| 306 | my $avgtime = $sumtime / $nbfiles; |
| 307 | |
| 308 | |
| 309 | my $ratioPvsSP = $sumlineP / $sizeSP; |
| 310 | my $ratioPvsSP2 = $sumlineP2 / $sizeSP; |
| 311 | |
| 312 | |
| 313 | #------------------------------------------------------------------------------ |
| 314 | # Results |
| 315 | #------------------------------------------------------------------------------ |
| 316 | |
| 317 | |
| 318 | pr "SP = $spfile"; |
| 319 | mylog "FILES = \n"; |
| 320 | map { mylog "\t$_"; } @cfiles; |
| 321 | pr "----------------------------------------"; |
| 322 | |
| 323 | |
| 324 | pr "!!Total files = $nbfiles"; |
| 325 | printf "!!AvgLine = %.1fl\n", $avglines; |
| 326 | |
| 327 | #pr " Correct number = $correct"; |
| 328 | printf "!!Correct = %.1f%s\n", $pourcentcorrect, "%"; |
| 329 | |
| 330 | pr "!!Human errors = $errors"; |
| 331 | |
| 332 | pr "!!Size SP = $sizeSP"; |
| 333 | pr "!!Size P = $sumlineP"; |
| 334 | pr "!!Size P (change only) = $sumlinePchange"; |
| 335 | |
| 336 | printf "!!Ratio P/SP = %3.1f\n", $ratioPvsSP; |
| 337 | |
| 338 | |
| 339 | printf "!!RunTime = %.1fs\n", $sumtime; |
| 340 | printf "!!MaxTime = %.1fs\n", $maxtime; |
| 341 | printf "!!AvgTime = %.1fs\n", $avgtime; |
| 342 | |
| 343 | my $totalstatus = $ok + $fa + $so + $gu; |
| 344 | mylog "----------------------------------------------------------------"; |
| 345 | mylog "Sanity checks: nb files vs total status: $nbfiles =? $totalstatus"; |
| 346 | |
| 347 | |
| 348 | |
| 349 | printf "L: %20s (r%3s) & %5.1f%% & %5dfi & %2de & %6.1fx & %6.1fs \n", |
| 350 | $cedescr, $ruleno, $pourcentcorrect, $nbfiles, $errors, $ratioPvsSP, $sumtime; |
| 351 | |
| 352 | |
| 353 | # Mega, Complex, Bluetooth |
| 354 | |
| 355 | printf "M: %60s & %5d & %6d (%d) & %2d & %s & %2d & %3d & %6.0fx & %6.1fs (%.1fs) & %5.0f\\%% \\\\\\hline%% SP: %s \n", |
| 356 | $cedescr, $nbfiles, $sumlineP, $sumlinePchange, $numauthors, $duration, $errors, $sizeSP, $ratioPvsSP, |
| 357 | $avgtime, $maxtime, $pourcentcorrect, $spfile; |
| 358 | |
| 359 | printf "C: %60s & %5d & %6d (%d) & %2d & %3d & %6.0fx & %6.1fs (%.1fs) & %5.0f\\%% \\\\\\hline%% SP: %s \n", |
| 360 | $cedescr, $nbfiles, $sumlineP, $sumlinePchange, $errors, $sizeSP, $ratioPvsSP, |
| 361 | $avgtime, $maxtime, $pourcentcorrect, $spfile; |
| 362 | |
| 363 | printf "B: %60s & %5d & %5d (%d) & %3d & %6.0fx & %6.1fs (%.1fs) & %5.0f\\%% \\\\\\hline%% SP: %s \n", |
| 364 | $cedescr, $nbfiles, $sumlineP, $sumlinePchange, $sizeSP, $ratioPvsSP, |
| 365 | $avgtime, $maxtime, $pourcentcorrect, $spfile; |
| 366 | |
| 367 | |