|
1 #! perl |
|
2 |
|
3 # Copyright (c) 2010 Symbian Foundation Ltd |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Symbian Foundation Ltd - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # Perl script to summarise GCC logs |
|
16 |
|
17 use strict; |
|
18 use Getopt::Long; |
|
19 |
|
20 sub Usage($) |
|
21 { |
|
22 my ($msg) = @_; |
|
23 |
|
24 print "$msg\n\n" if ($msg ne ""); |
|
25 |
|
26 print <<'EOF'; |
|
27 summarise_gcc_errors.pl - simple script for analysing gcc error logs |
|
28 |
|
29 This script will read a collection of GCC output logs and summarise |
|
30 the error messages in various useful ways. |
|
31 |
|
32 Options: |
|
33 |
|
34 -warnings process warnings as well as errors |
|
35 -verbose list the files associated with each error |
|
36 |
|
37 EOF |
|
38 exit (1); |
|
39 } |
|
40 |
|
41 my $warnings = 0; |
|
42 my $verbose = 0; |
|
43 |
|
44 # Analyse the rest of command-line parameters |
|
45 if (!GetOptions( |
|
46 "w|warnings" => \$warnings, |
|
47 "v|verbose" => \$verbose, |
|
48 )) |
|
49 { |
|
50 Usage("Invalid argument"); |
|
51 } |
|
52 |
|
53 my %files; |
|
54 my %errors_by_file; |
|
55 my %error_count_by_file; |
|
56 my %errors; |
|
57 my %message_ids; |
|
58 my %files_by_message_id; |
|
59 my %messages_by_id; |
|
60 my %unique_message_counts; |
|
61 my %all_message_counts; |
|
62 my $next_message_id = 1; |
|
63 |
|
64 my $line; |
|
65 while ($line = <>) |
|
66 { |
|
67 # M:/epoc32/include/elements/nm_interfaces.h:255: warning: dereferencing type-punned pointer will break strict-aliasing rules |
|
68 # M:/epoc32/include/f32file.h:2169: warning: invalid access to non-static data member 'TVolFormatParam::iUId' of NULL object |
|
69 # M:/epoc32/include/f32file.h:2169: warning: (perhaps the 'offsetof' macro was used incorrectly) |
|
70 # M:/epoc32/include/comms-infras/ss_nodemessages.h:301: error: wrong number of template arguments (3, should be 4) |
|
71 # M:/epoc32/include/elements/nm_signatures.h:496: error: provided for 'template<class TSIGNATURE, int PAYLOADATTRIBOFFSET, class TATTRIBUTECREATIONPOLICY, int PAYLOADBUFFERMAXLEN> class Messages::TSignatureWithPolymorphicPayloadMetaType' |
|
72 # M:/epoc32/include/comms-infras/ss_nodemessages.h:301: error: invalid type in declaration before ';' token |
|
73 |
|
74 if ($line =~ /(^...*):(\d+): ([^:]+): (.*)$/) |
|
75 { |
|
76 my $filename = $1; |
|
77 my $lineno = $2; |
|
78 my $messagetype = $3; |
|
79 my $message = $4; |
|
80 |
|
81 if ($messagetype eq "note") |
|
82 { |
|
83 next; # ignore notes |
|
84 } |
|
85 if ($messagetype eq "warning" && !$warnings) |
|
86 { |
|
87 next; # ignore warnings |
|
88 } |
|
89 |
|
90 $filename =~ s/^.://; # remove drive letter |
|
91 |
|
92 $message =~ s/&/&/g; |
|
93 $message =~ s/>/>/g; |
|
94 $message =~ s/</</g; |
|
95 $message =~ s/'/'/g; |
|
96 my $generic_message = "$messagetype: $message"; |
|
97 $generic_message =~ s/'offsetof'/"offsetof"/; |
|
98 $generic_message =~ s/'([^a-zA-Z])'/"\1"/g; # don't catch ';' in next substitution |
|
99 $generic_message =~ s/['`][^']+'/XX/g; # suppress quoted bits of the actual instance |
|
100 |
|
101 my $message_id = $next_message_id; |
|
102 if (!defined $message_ids{$generic_message}) |
|
103 { |
|
104 $next_message_id++; |
|
105 $message_ids{$generic_message} = $message_id; |
|
106 $messages_by_id{$message_id} = $generic_message; |
|
107 $all_message_counts{$message_id} = 1; |
|
108 } |
|
109 else |
|
110 { |
|
111 $message_id = $message_ids{$generic_message}; |
|
112 $all_message_counts{$message_id} += 1; |
|
113 } |
|
114 my $instance = sprintf("%s:%d: %s-#%d", $filename, $lineno, $messagetype, $message_id); |
|
115 |
|
116 if (defined $files{$instance}) |
|
117 { |
|
118 # already seen this one |
|
119 next; |
|
120 } |
|
121 else |
|
122 { |
|
123 if (!defined $unique_message_counts{$message_id}) |
|
124 { |
|
125 $unique_message_counts{$message_id} = 1; |
|
126 } |
|
127 else |
|
128 { |
|
129 $unique_message_counts{$message_id} += 1; |
|
130 } |
|
131 $files{$instance} = $message; |
|
132 |
|
133 if (!defined $files_by_message_id{$message_id}) |
|
134 { |
|
135 $files_by_message_id{$message_id} = $filename; |
|
136 } |
|
137 else |
|
138 { |
|
139 $files_by_message_id{$message_id} .= "\n$filename"; |
|
140 } |
|
141 |
|
142 my $error = sprintf "%-5d: %s: %s", $lineno, $messagetype, $message; |
|
143 if (!defined $errors_by_file{$filename}) |
|
144 { |
|
145 $errors_by_file{$filename} = $error; |
|
146 $error_count_by_file{$filename} = 1; |
|
147 } |
|
148 else |
|
149 { |
|
150 $errors_by_file{$filename} .= "\n$error"; |
|
151 $error_count_by_file{$filename} += 1; |
|
152 } |
|
153 } |
|
154 next; |
|
155 } |
|
156 } |
|
157 |
|
158 # clean up the file lists |
|
159 my %filecount_by_message_id; |
|
160 foreach my $id (keys %files_by_message_id) |
|
161 { |
|
162 my @longlist = split /\n/, $files_by_message_id{$id}; |
|
163 my %uniq; |
|
164 foreach my $file (@longlist) |
|
165 { |
|
166 $uniq{$file} = 1; |
|
167 } |
|
168 my $uniqlist = join( "\n\t", sort keys %uniq); |
|
169 $files_by_message_id{$id} = $uniqlist; |
|
170 $filecount_by_message_id{$id} = scalar keys %uniq; |
|
171 } |
|
172 |
|
173 print "\n\n====Occurrences of messages (distinct, all)\n"; |
|
174 foreach my $id ( sort {$unique_message_counts{$b} <=> $unique_message_counts{$a}} keys %unique_message_counts) |
|
175 { |
|
176 printf "%-6d\t%-6d\t%s\n", $unique_message_counts{$id}, $all_message_counts{$id}, $messages_by_id{$id}; |
|
177 } |
|
178 |
|
179 print "\n\n====Files affected per message\n"; |
|
180 foreach my $id ( sort {$filecount_by_message_id{$b} <=> $filecount_by_message_id{$a}} keys %filecount_by_message_id) |
|
181 { |
|
182 printf "%-6d\t%s\n", $filecount_by_message_id{$id}, $messages_by_id{$id}; |
|
183 if ($verbose) |
|
184 { |
|
185 print "\t", $files_by_message_id{$id}; |
|
186 } |
|
187 } |
|
188 |
|
189 print "\n\n====Affected files by package\n"; |
|
190 my $current_package = ""; |
|
191 my @currentfiles; |
|
192 foreach my $file (sort keys %error_count_by_file) |
|
193 { |
|
194 my ($root, $sf, $layer, $packagename, @rest) = split /[\/\\]/, $file; |
|
195 my $package = "$sf/$layer/$packagename"; |
|
196 if ($layer eq "include") |
|
197 { |
|
198 $package = "$sf/$layer"; |
|
199 } |
|
200 if ($package ne $current_package) |
|
201 { |
|
202 if ($current_package ne "") |
|
203 { |
|
204 printf "%-6d\t%s\n", scalar @currentfiles, $current_package; |
|
205 print join("\n",@currentfiles); |
|
206 print "\n"; |
|
207 } |
|
208 $current_package = $package; |
|
209 @currentfiles = (); |
|
210 } |
|
211 my $filedetails = sprintf "\t%-6d\t%s", $error_count_by_file{$file}, $file; |
|
212 push @currentfiles, $filedetails; |
|
213 } |
|
214 printf "%-6d\t%s\n", scalar @currentfiles, $current_package; |
|
215 print join("\n",@currentfiles); |
|
216 print "\n"; |
|
217 |
|
218 print "\n\n====Messages by file\n"; |
|
219 foreach my $file ( sort keys %error_count_by_file) |
|
220 { |
|
221 my @details = split "\n", $errors_by_file{$file}; |
|
222 printf "%-6d\t%s\n\t", $error_count_by_file{$file}, $file; |
|
223 print join("\n\t", @details); |
|
224 print "\n"; |
|
225 } |
|
226 |