Add a script for cleaning out the "known noise"
[p5sagit/p5-mst-13.2.git] / Porting / thirdclean
1 local $/;
2 $_ = <ARGV>;
3
4 my @accv = /(^-+ \w+ -- \d+ --(?:.(?!^-))+)/msg;
5 my @leak = /(\d+ bytes? in \d+ leaks? .+? created at:(?:.(?!^\d))+)/msg;
6
7 $leak[ 0] =~ s/.* were found:\n\n//m; # Snip off totals.
8 $leak[-1] =~ s/^-+.*//ms; # Snip off final memory layout.
9
10 # Weed out the known access violations.
11
12 @accv = grep { ! /-- ru[hs] --.+setlocale.+Perl_init_i18nl10n/s }  @accv;
13 @accv = grep { ! /-- (?:fon|ris) --.+__strxfrm_sb/s }              @accv;
14 @accv = grep { ! /-- rih --.+memmove.+sv_catpv.+moreswitches/s }   @accv;
15 @accv = grep { ! /-- (?:rih|rus) --.+strcpy.+gv_fetchfile/s }      @accv;
16 @accv = grep { ! /-- rus --.+_doprnt_dis/s }                       @accv;
17 @accv = grep { ! /-- rih --.+strcmp.+doopen_pmc/s }                @accv;
18 @accv = grep { ! /-- rih --.+memmove.+my_setenv/s }                @accv;
19
20 # Weed out the known memory leaks.
21
22 @leak = grep { ! /setlocale.+Perl_init_i18nl10n/s }   @leak;
23 @leak = grep { ! /setlocale.+set_numeric_standard/s } @leak;
24 @leak = grep { ! /_findiop.+fopen/s }                 @leak;
25 @leak = grep { ! /_findiop.+__fdopen/s }              @leak;
26 @leak = grep { ! /Perl_new\w+.+Perl_yyparse/s }       @leak;
27
28 # Output the cleaned up report.
29
30 # Access violations.
31
32 for (my $i = 0; $i < @accv; $i++) {
33   $_ = $accv[$i];
34   s/\d+/$i/;
35   print;
36 }
37
38 # Memory leaks.
39
40 my ($leakb, $leakn, $leaks);
41
42 for (my $i = 0; $i < @leak; $i++) {
43   $_ = $leak[$i];
44   print $_, "\n";
45   /^(\d+) bytes? in (\d+) leak/;
46   $leakb += $1;
47   $leakn += $2;
48   $leaks += $1 if /including (\d+) super/;
49 }
50
51 print "Bytes $leakb Leaks $leakn Super $leaks\n" if $leakb;