1 # Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
2 # Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
3 # This file is part of Coccinelle.
5 # Coccinelle is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, according to version 2 of the License.
9 # Coccinelle is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
17 # The authors reserve the right to distribute this or future versions of
18 # Coccinelle under other licenses.
27 #use Date::Manip qw(ParseDate UnixDate); #sudo apt-get install libdate-manip-perl
28 #use Date::Calc qw(Delta_Days); #sudo apt-get install libdate-calc-perl
30 #------------------------------------------------------------------------------
32 #------------------------------------------------------------------------------
36 sub pr2
{ print STDERR
"@_\n"; }
37 sub pr
{ print "@_\n"; }
38 sub mylog
{ print STDERR
"@_\n" if $debug; }
45 #------------------------------------------------------------------------------
47 #------------------------------------------------------------------------------
50 my $so = 0; #spatch ok
64 my $sumlineP = 0; #whole git
66 my $sumlinePchange = 0;
75 my $duration = 0; # in days
79 #------------------------------------------------------------------------------
81 #------------------------------------------------------------------------------
82 $spfile = `make sp_file`;
85 if($spfile =~ /(rule|mega|bt)(\d+)\.cocci/) { $ruleno = "$2"; }
87 #------------------------------------------------------------------------------
89 #------------------------------------------------------------------------------
91 #$cedescr = `make ce_descr`;
93 #print STDERR (Dumper($cedescr));
94 open TMP
, "Makefile" or die "no Makefile file ?";
96 if(/^(CE)?DESCRIPTION=["'](.*)["']/) { $cedescr = $2; }
101 #$cedescr =~ s/\\/\\\\/g;
102 #$cedescr =~ s/\f/\\f/g;
103 #$cedescr =~ s/\t/\\t/g;
105 #------------------------------------------------------------------------------
107 #------------------------------------------------------------------------------
108 my $files = `make source_files`;
110 @cfiles = split /\s+/, $files;
112 $nbfiles = scalar(@cfiles);
114 #------------------------------------------------------------------------------
116 #------------------------------------------------------------------------------
118 my ($linefile) = `wc -l $_`;
120 die "wierd wc output" unless $linefile =~ /^(\d+) /;
122 mylog
"filesize $_ $1";
126 #------------------------------------------------------------------------------
128 #------------------------------------------------------------------------------
130 `cat $spfile | perl -p -e "s/\\/\\/.*//g;" | grep -v '^[ \t]*\$' | wc -l`;
134 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 if(!(-e
"README")) { pr2
"no README file ?"; }
139 open TMP
, "README" or die "no README file ?";
141 if (/\[bug\]/ || /status\]\s*bug/ || /status\]\s*BUG/ ) {
143 # can also look for [semibug] but it's often related to [corrected_c] kind of pbs
144 #|| /status\]\s*semi-bug/
146 #pr2 "OLD BUG FORMAT: $_";
154 #------------------------------------------------------------------------------
156 #------------------------------------------------------------------------------
159 ($sumlineP) = `cat gitinfo |wc -l`;
165 #------------------------------------------------------------------------------
166 # Number of authors and duration
167 #------------------------------------------------------------------------------
172 open TMP
, "gitinfo" or die "no gitinfo file ?";
183 #can also do: egrep "^Author" gitinfo | sort | uniq | wc -l
184 if (/^Author: (.*)/) {
188 # if(/^Date: (.*) ([-+]\d+)?/) {
189 # my $date = ParseDate($1);
190 # if (!$date) { die "bad date" }
192 # my ($year, $month, $day) = UnixDate($date, "%Y", "%m", "%d");
193 # my @current = ($year, $month, $day);
195 # @mindate = @current;
196 # @maxdate = @current;
199 # my $diff1 = Delta_Days(@mindate, @current);
200 # if($diff1 < 0) { @mindate = @current; }
201 # my $diff2 = Delta_Days(@current, @maxdate);
202 # if($diff2 < 0) { @maxdate = @current; }
204 # #pr2 "$diff1, $diff2";
213 # my $diff = Delta_Days(@mindate, @maxdate);
214 # if($diff == 1 || $diff == 0) {
215 # $duration = "1 day";
217 # elsif($diff < 31) {
218 # $duration = "$diff days";
220 # elsif($diff > 365) {
221 # my $years = int($diff / 365);
222 # my $s = plural($years);
223 # $duration = "$years year$s";
225 # elsif($diff > 31) {
226 # my $months = int($diff / 31);
227 # my $s = plural($months);
228 # $duration = "$months month$s";
230 # else { die "impossible"; }
232 $duration = "xxx months";
234 $numauthors = scalar(keys %{$h});
240 #------------------------------------------------------------------------------
241 # Size P (only change for .c in drivers/ or sounds/ (the test files))
242 #------------------------------------------------------------------------------
245 foreach my $c (@cfiles) {
246 die "wierd: $c, with $spfile" unless ($c =~ /(.*)\.c$/);
249 my $aft = "$base.res";
250 if(-e
"corrected_$base.res") {
251 $aft = "corrected_$base.res";
252 mylog
"found corrected";
255 open TMP
, "diff -u -b -B $bef $aft |";
261 if (/^\+[^+]/) { $onlychange++; }
262 if (/^\-[^-]/) { $onlychange++; }
264 $sumlinePchange += $onlychange;
265 $sumlineP2 += $count;
268 #------------------------------------------------------------------------------
270 #------------------------------------------------------------------------------
271 foreach my $c (@cfiles) {
272 die "" unless ($c =~ /(.*)\.c$/);
275 my $diagnosefile = "";
278 if(-e
"$base.c.ok") { $ok++; $diagnosefile = "$base.c.ok"; }
279 if(-e
"$base.c.failed") { $fa++; $diagnosefile = "$base.c.failed"; }
280 if(-e
"$base.c.spatch_ok") { $so++; $diagnosefile = "$base.c.spatch_ok"; }
281 if(-e
"$base.c.gave_up") { $gu++; $diagnosefile = "$base.c.gave_up"; }
283 open TMP
, $diagnosefile or die "no diagnose $base: $diagnosefile";
287 # before -test_okfailed
288 # if (/real[ \t]+([0-9])+m([0-9]+)[.]([0-9]+)/) {
291 # $time = $1 * 60.0; # minutes
292 # $time += $2; # seconds
293 # $time += $3 / 1000.0; # 1/1000th sec.
295 # pr2 (sprintf "%4.1fs\n", $time);
296 # printf "I: %15s & %4.1fs\n", $c, $time;
304 mylog
(sprintf "%4.1fs\n", $time);
305 printf "I: %15s & %4.1fs\n", $c, $time;
311 die "not found time information in $diagnosefile" unless $found == 1;
314 $maxtime = $time if $time > $maxtime;
318 #------------------------------------------------------------------------------
320 #------------------------------------------------------------------------------
322 my $correct = $ok + $so;
324 my $pourcentcorrect = ($correct * 100.0) / $nbfiles;
325 my $avglines = $sumlinefiles / $nbfiles;
326 my $avgtime = $sumtime / $nbfiles;
329 my $ratioPvsSP = $sumlineP / $sizeSP;
330 my $ratioPvsSP2 = $sumlineP2 / $sizeSP;
333 #------------------------------------------------------------------------------
335 #------------------------------------------------------------------------------
340 map { mylog
"\t$_"; } @cfiles;
341 pr
"----------------------------------------";
344 pr
"!!Total files = $nbfiles";
345 printf "!!AvgLine = %.1fl\n", $avglines;
347 #pr " Correct number = $correct";
348 printf "!!Correct = %.1f%s\n", $pourcentcorrect, "%";
350 pr
"!!Human errors = $errors";
352 pr
"!!Size SP = $sizeSP";
353 pr
"!!Size P = $sumlineP";
354 pr
"!!Size P (change only) = $sumlinePchange";
356 printf "!!Ratio P/SP = %3.1f\n", $ratioPvsSP;
359 printf "!!RunTime = %.1fs\n", $sumtime;
360 printf "!!MaxTime = %.1fs\n", $maxtime;
361 printf "!!AvgTime = %.1fs\n", $avgtime;
363 my $totalstatus = $ok + $fa + $so + $gu;
364 mylog
"----------------------------------------------------------------";
365 mylog
"Sanity checks: nb files vs total status: $nbfiles =? $totalstatus";
369 printf "L: %20s (r%3s) & %5.1f%% & %5dfi & %2de & %6.1fx & %6.1fs \n",
370 $cedescr, $ruleno, $pourcentcorrect, $nbfiles, $errors, $ratioPvsSP, $sumtime;
373 # Mega, Complex, Bluetooth
375 printf "M: %60s & %5d & %6d (%d) & %2d & %s & %2d & %3d & %6.0fx & %6.1fs (%.1fs) & %5.0f\\%% \\\\\\hline%% SP: %s \n",
376 $cedescr, $nbfiles, $sumlineP, $sumlinePchange, $numauthors, $duration, $errors, $sizeSP, $ratioPvsSP,
377 $avgtime, $maxtime, $pourcentcorrect, $spfile;
379 printf "C: %60s & %5d & %6d (%d) & %2d & %3d & %6.0fx & %6.1fs (%.1fs) & %5.0f\\%% \\\\\\hline%% SP: %s \n",
380 $cedescr, $nbfiles, $sumlineP, $sumlinePchange, $errors, $sizeSP, $ratioPvsSP,
381 $avgtime, $maxtime, $pourcentcorrect, $spfile;
383 printf "B: %60s & %5d & %5d (%d) & %3d & %6.0fx & %6.1fs (%.1fs) & %5.0f\\%% \\\\\\hline%% SP: %s \n",
384 $cedescr, $nbfiles, $sumlineP, $sumlinePchange, $sizeSP, $ratioPvsSP,
385 $avgtime, $maxtime, $pourcentcorrect, $spfile;