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