File: parse_warn.pl

package info (click to toggle)
blootbot 1.1.0-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,420 kB
  • ctags: 586
  • sloc: perl: 15,941; sh: 154; makefile: 56; sql: 45
file content (91 lines) | stat: -rwxr-xr-x 1,752 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/perl -w

# leading and trailing context lines.
my $contextspread	= 2;

use strict;

$| = 1;

if (!scalar @ARGV) {
    print "Usage: parse_warn.pl <files>\n";
    print "Example: parse_warn.pl log/*\n";
    exit 0;
}

my %done;
my $file;

foreach $file (@ARGV) {
    if (! -f $file) {
	print "warning: $file does not exist.\n";
	next;
    }
    my $str = ' value at .* line ';

    print "Opening $file... ";
    if ($file =~ /bz2$/) {	# bz2
	open(FILE, "bzcat $file | egrep '$str' |");
    } elsif ($file =~ /gz$/) {	# gz
	open(FILE, "zegrep '$str' $file |");
    } else {			# raw
	open(FILE, "egrep '$str' $file |");
    }

    print "Parsing... ";
    while (<FILE>) {
	if (/ at (\S+) line (\d+)/) {
	    my ($file,$lineno) = ($1,$2+1);
	    $done{$file}{$lineno}++;
	}
    }
    close FILE;

    print "Done.\n";
}

foreach $file (keys %done) {
    my $count = scalar(keys %{$done{$file}});
    print "warn $file: $count unique warnings.\n";

    if (! -f $file) {
	print "=> error: does not exist.\n\n";
	next;
    }

    if (open(IN,$file)) {
	my @lines = <IN>;
	close IN;

	my $total = scalar @lines;
	my $spread = 0;
	my $done = 0;
	for(my $i=0; $i<=$total; $i++) {
	    next unless (exists $done{$file}{$i+$contextspread} or $spread);

	    if (exists $done{$file}{$i+$contextspread}) {
		print "@@ $i @@\n" unless ($spread);
		# max lines between offending lines should be 2*context-1.
		# coincidence that it is!
		$spread = 2*$contextspread;
	    } else {
		$spread--;
	    }

	    if (exists $done{$file}{$i}) {
		print "*** ";
	    } else {
		print "--- ";
	    }

	    if ($i >= $total) {
		print "EOF\n";
	    } else {
		print $lines[$i];
	    }
	}
	print "\n";
    } else {
	print "=> error: could not open file.\n";
    }
}