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