-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlinux-log-summary
More file actions
executable file
·192 lines (168 loc) · 4.8 KB
/
linux-log-summary
File metadata and controls
executable file
·192 lines (168 loc) · 4.8 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/perl -w
#
# © Copyright 2010 by Geert Uytterhoeven
#
# This file is subject to the terms and conditions of the GNU General Public
# License.
#
sub usage()
{
my $name = $0;
$name =~ s@.*/@@g;
die <<EOF;
Usage: $name [options] buildlogs...
Valid options:
-h, --help Display this help
-d, --debug Enable debug mode
-v, --verbose Enable verbose mode to show affected configs
EOF
}
sub set_common_prefix()
{
my $s = shift;
return if $s !~ m{^/};
return if $s =~ m{^/opt/};
return if $s =~ m{^/tmp/};
return if $s =~ m{^/usr/};
if (defined($common_prefix)) {
chop $common_prefix while ($s !~ /^\Q$common_prefix\E/);
} else {
$common_prefix = $s;
}
}
sub add_record()
{
my $db = shift;
my $log = shift;
my $line = shift;
my $id = shift;
if (!exists($db->{$line})) {
$db->{$line}{"cnt"} = 1;
} else {
$db->{$line}{"cnt"}++;
}
$db->{$line}{"logs"}{$log} = 1;
&set_common_prefix($id);
}
sub read_log()
{
my $log = shift;
my ($line, $id, $msg);
open(LOG, "<$log") or die "Cannot open $log";
while ($line = <LOG>) {
chomp($line);
if ($line =~ m{^warning: The last gc run reported the following} or
$line =~ m{^warning: There are too many unreachable loose objects}) {
# git warning
print STDERR "Ignoring git: $line\n" if $debug;
} elsif (($id, $msg) = $line =~ m{(^.*):\s*error:\s*(.*$)}i) {
# compile error
&add_record(\%errors, $log, $line, $id);
} elsif (($id, $msg) = $line =~ m{(^.*): (undefined reference.*)}i) {
# link error: undefined reference.
&add_record(\%errors, $log, $line, $id);
} elsif (($id, $msg) = $line =~ m{(^.*): (relocation truncated.*)}i) {
# link error: relocation truncated
&add_record(\%errors, $log, $line, $id);
} elsif (($msg) = $line =~ m{error: (.*undefined!)}i) {
# link error: undefined symbol
&add_record(\%errors, $log, $line, "");
} elsif (($id, $msg) = $line =~ m{^.*:\s*error in (.*);\s*(.*$)}i) {
# link error
&add_record(\%errors, $log, "$id: $msg", $id);
} elsif (($target) = $line =~ m{No rule to make target .(.*).,}i) {
# make error
&add_record(\%errors, $log, "No rule to make target $target",
"make");
} elsif (($target) = $line =~ m{Inconsistent kallsyms data}i) {
# kallsyms error
&add_record(\%errors, $log, "Inconsistent kallsyms data",
"kallsyms");
} elsif (($id, $msg) = $line =~ m{(^.*):\s*warning:\s*(.*$)}i) {
# compile warning
&add_record(\%warnings, $log, $line, $id);
} elsif (($msg) = $line =~ m{warning:\s(modpost:\s.*$)}i) {
# modpost warning
&add_record(\%warnings, $log, $msg, "modpost");
} elsif ($line =~ m{^distcc}) {
# distcc cruft
print STDERR "Ignoring distcc: $line\n" if $debug;
} elsif (($msg) = $line =~ m{^Warning (\(.*)}i) {
# dtc warning
&add_record(\%warnings, $log, $line, "dtc");
} elsif (($msg) = $line =~ m{^warning: (.*)}i) {
# modpost or relocs_check.pl warning
&add_record(\%warnings, $log, $line, "");
} elsif ($debug) {
print STDERR "Unhandled error: $line\n" if ($line =~ /error/i);
print STDERR "Unhandled warning: $line\n" if ($line =~ /warn/i);
}
# FIXME headers_check
}
close(LOG);
}
sub print_record()
{
my $record = shift;
my $line = shift;
my $type = shift;
my $cnt = $record->{"cnt"};
my @logs = keys %{$record->{"logs"}};
my $logs = $#logs + 1;
$line =~ s@^$common_prefix@@ if defined($common_prefix);
print "$line: $cnt $type in $logs logs\n";
print "\t@logs\n" if $verbose;
}
sub sort_records()
{
my $a = shift;
my $ra = shift;
my $b = shift;
my $rb = shift;
my $logs1 = keys %{$ra->{"logs"}};
my $logs2 = keys %{$rb->{"logs"}};
return 1 if $logs1 < $logs2;
return -1 if $logs1 > $logs2;
return $a cmp $b;
}
sub sort_errors()
{
return &sort_records($a, $errors{$a}, $b, $errors{$b});
}
sub sort_warnings()
{
return &sort_records($a, $warnings{$a}, $b, $warnings{$b});
}
while (defined($ARGV[0])) {
$option = $ARGV[0];
last if not $option =~ /^-/;
if ($option eq '-h' or $option eq '--help') {
&usage();
} elsif ($option eq '-d' or $option eq '--debug') {
$debug = 1;
} elsif ($option eq '-v' or $option eq '--verbose') {
$verbose = 1;
} elsif ($option eq '--') {
shift @ARGV;
last;
} else {
print STDERR "Unknown option $option\n";
&usage();
}
shift @ARGV;
}
&usage if ($#ARGV < 0);
for $file (@ARGV) {
&read_log($file);
}
print "\n*** ERRORS ***\n\n";
for $line (sort sort_errors (keys %errors)) {
&print_record($errors{$line}, $line, "errors");
}
print "\n\n*** WARNINGS ***\n\n";
for $line (sort sort_warnings keys %warnings) {
&print_record($warnings{$line}, $line, "warnings");
}
$errors = keys %errors;
$warnings = keys %warnings;
print "\n\n*** TOTAL: $errors errors and $warnings warnings ***\n\n";