Release coccinelle-0.2.0rc1
[bpt/coccinelle.git] / scripts / stat_directory_complete.pl
CommitLineData
34e49164
C
1#!/usr/bin/perl
2
3use strict;
4use 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
14my $debug = 0;
15
16sub pr2 { print STDERR "@_\n"; }
17sub pr { print "@_\n"; }
18sub mylog { print STDERR "@_\n" if $debug; }
19
20sub plural {
21 my ($n) = @_;
22 $n > 1 ? "s" : "";
23}
24
25#------------------------------------------------------------------------------
26# Globals
27#------------------------------------------------------------------------------
28
29my $ok = 0;
30my $so = 0; #spatch ok
31my $fa = 0; #failed
32my $gu = 0; #gave up
33
34my $nbfiles = 0;
35
36my $maxtime = 0;
37#my $mintime = 0;
38my $sumtime = 0;
39
40my $sumlinefiles = 0;
41
42my $errors = 0;
43
44my $sumlineP = 0; #whole git
45my $sumlineP2 = 0;
46my $sumlinePchange = 0;
47
48my $spfile = "";
49my $ruleno = "??";
50my $sizeSP = 0;
51
52my $cedescr = "";
53
54my $numauthors = 0;
55my $duration = 0; # in days
56
57my @cfiles = ();
58
59#------------------------------------------------------------------------------
60# SP
61#------------------------------------------------------------------------------
62$spfile = `make sp_file`;
63chomp $spfile;
64
65if($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));
74open TMP, "Makefile" or die "no Makefile file ?";
75while(<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#------------------------------------------------------------------------------
88my $files = `make source_files`;
89chomp $files;
90@cfiles = split /\s+/, $files;
91
92$nbfiles = scalar(@cfiles);
93
94#------------------------------------------------------------------------------
95# Size files (lines)
96#------------------------------------------------------------------------------
97map {
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`;
111chomp $sizeSP;
112
113
114#------------------------------------------------------------------------------
115# Bugs
116#------------------------------------------------------------------------------
117if(!(-e "README")) { pr2 "no README file ?"; }
118else {
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
138if(-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
150if(-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
225foreach 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#------------------------------------------------------------------------------
251foreach 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
302my $correct = $ok + $so;
303
304my $pourcentcorrect = ($correct * 100.0) / $nbfiles;
305my $avglines = $sumlinefiles / $nbfiles;
306my $avgtime = $sumtime / $nbfiles;
307
308
309my $ratioPvsSP = $sumlineP / $sizeSP;
310my $ratioPvsSP2 = $sumlineP2 / $sizeSP;
311
312
313#------------------------------------------------------------------------------
314# Results
315#------------------------------------------------------------------------------
316
317
318pr "SP = $spfile";
319mylog "FILES = \n";
320map { mylog "\t$_"; } @cfiles;
321pr "----------------------------------------";
322
323
324pr "!!Total files = $nbfiles";
325printf "!!AvgLine = %.1fl\n", $avglines;
326
327#pr " Correct number = $correct";
328printf "!!Correct = %.1f%s\n", $pourcentcorrect, "%";
329
330pr "!!Human errors = $errors";
331
332pr "!!Size SP = $sizeSP";
333pr "!!Size P = $sumlineP";
334pr "!!Size P (change only) = $sumlinePchange";
335
336printf "!!Ratio P/SP = %3.1f\n", $ratioPvsSP;
337
338
339printf "!!RunTime = %.1fs\n", $sumtime;
340printf "!!MaxTime = %.1fs\n", $maxtime;
341printf "!!AvgTime = %.1fs\n", $avgtime;
342
343my $totalstatus = $ok + $fa + $so + $gu;
344mylog "----------------------------------------------------------------";
345mylog "Sanity checks: nb files vs total status: $nbfiles =? $totalstatus";
346
347
348
349printf "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
355printf "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
359printf "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
363printf "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