Commit | Line | Data |
---|---|---|
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 | ||
23 | use strict; | |
24 | use 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 | ||
34 | my $debug = 0; | |
35 | ||
36 | sub pr2 { print STDERR "@_\n"; } | |
37 | sub pr { print "@_\n"; } | |
38 | sub mylog { print STDERR "@_\n" if $debug; } | |
39 | ||
40 | sub plural { | |
41 | my ($n) = @_; | |
42 | $n > 1 ? "s" : ""; | |
43 | } | |
44 | ||
45 | #------------------------------------------------------------------------------ | |
46 | # Globals | |
47 | #------------------------------------------------------------------------------ | |
48 | ||
49 | my $ok = 0; | |
50 | my $so = 0; #spatch ok | |
51 | my $fa = 0; #failed | |
52 | my $gu = 0; #gave up | |
53 | ||
54 | my $nbfiles = 0; | |
55 | ||
56 | my $maxtime = 0; | |
57 | #my $mintime = 0; | |
58 | my $sumtime = 0; | |
59 | ||
60 | my $sumlinefiles = 0; | |
61 | ||
62 | my $errors = 0; | |
63 | ||
64 | my $sumlineP = 0; #whole git | |
65 | my $sumlineP2 = 0; | |
66 | my $sumlinePchange = 0; | |
67 | ||
68 | my $spfile = ""; | |
69 | my $ruleno = "??"; | |
70 | my $sizeSP = 0; | |
71 | ||
72 | my $cedescr = ""; | |
73 | ||
74 | my $numauthors = 0; | |
75 | my $duration = 0; # in days | |
76 | ||
77 | my @cfiles = (); | |
78 | ||
79 | #------------------------------------------------------------------------------ | |
80 | # SP | |
81 | #------------------------------------------------------------------------------ | |
82 | $spfile = `make sp_file`; | |
83 | chomp $spfile; | |
84 | ||
85 | if($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)); | |
94 | open TMP, "Makefile" or die "no Makefile file ?"; | |
95 | while(<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 | #------------------------------------------------------------------------------ | |
108 | my $files = `make source_files`; | |
109 | chomp $files; | |
110 | @cfiles = split /\s+/, $files; | |
111 | ||
112 | $nbfiles = scalar(@cfiles); | |
113 | ||
114 | #------------------------------------------------------------------------------ | |
115 | # Size files (lines) | |
116 | #------------------------------------------------------------------------------ | |
117 | map { | |
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`; | |
131 | chomp $sizeSP; | |
132 | ||
133 | ||
134 | #------------------------------------------------------------------------------ | |
135 | # Bugs | |
136 | #------------------------------------------------------------------------------ | |
137 | if(!(-e "README")) { pr2 "no README file ?"; } | |
138 | else { | |
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 | ||
158 | if(-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 | ||
170 | if(-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 | ||
245 | foreach 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 | #------------------------------------------------------------------------------ | |
271 | foreach 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 | ||
322 | my $correct = $ok + $so; | |
323 | ||
324 | my $pourcentcorrect = ($correct * 100.0) / $nbfiles; | |
325 | my $avglines = $sumlinefiles / $nbfiles; | |
326 | my $avgtime = $sumtime / $nbfiles; | |
327 | ||
328 | ||
329 | my $ratioPvsSP = $sumlineP / $sizeSP; | |
330 | my $ratioPvsSP2 = $sumlineP2 / $sizeSP; | |
331 | ||
332 | ||
333 | #------------------------------------------------------------------------------ | |
334 | # Results | |
335 | #------------------------------------------------------------------------------ | |
336 | ||
337 | ||
338 | pr "SP = $spfile"; | |
339 | mylog "FILES = \n"; | |
340 | map { mylog "\t$_"; } @cfiles; | |
341 | pr "----------------------------------------"; | |
342 | ||
343 | ||
344 | pr "!!Total files = $nbfiles"; | |
345 | printf "!!AvgLine = %.1fl\n", $avglines; | |
346 | ||
347 | #pr " Correct number = $correct"; | |
348 | printf "!!Correct = %.1f%s\n", $pourcentcorrect, "%"; | |
349 | ||
350 | pr "!!Human errors = $errors"; | |
351 | ||
352 | pr "!!Size SP = $sizeSP"; | |
353 | pr "!!Size P = $sumlineP"; | |
354 | pr "!!Size P (change only) = $sumlinePchange"; | |
355 | ||
356 | printf "!!Ratio P/SP = %3.1f\n", $ratioPvsSP; | |
357 | ||
358 | ||
359 | printf "!!RunTime = %.1fs\n", $sumtime; | |
360 | printf "!!MaxTime = %.1fs\n", $maxtime; | |
361 | printf "!!AvgTime = %.1fs\n", $avgtime; | |
362 | ||
363 | my $totalstatus = $ok + $fa + $so + $gu; | |
364 | mylog "----------------------------------------------------------------"; | |
365 | mylog "Sanity checks: nb files vs total status: $nbfiles =? $totalstatus"; | |
366 | ||
367 | ||
368 | ||
369 | printf "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 | ||
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; | |
378 | ||
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; | |
382 | ||
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; | |
386 | ||
387 |