lib/Text/Cadenceparser.pm

filter: Statementstmt 88.3% 243 / 275 Branchbran 80.1% 93 / 116 Conditioncond 69.0% 29 / 42 MC/DCmcdc 38.1% 8 / 21 Subroutinesub 89.6% 26 / 29 Podpod 100% 9 / 9 totaltotal 82.9% 408 / 492 CC 85 SCAR 23.6
CC
85
Cov
84%
overview
42.0
new
17.3
_sort_data
14.0
CRAP 10.6
↑ Summary script/synth_log.pl »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Text::Cadenceparser;
7 {
8 4 $Text::Cadenceparser::VERSION = '1.12';
9 }
10  
11 4 ▶use Carp qw/croak carp/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 ▶use constant DEBUG => $ENV{TEXT_CADENCEPARSER_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use constant DEBUG1 =>
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 $ENV{TEXT_CADENCEPARSER_DEBUG1}; # more verbose debugging info
17  
18  
19 11 ▶sub new {
Subroutine new: called CC=12 SCAR=28.5
Pod documented
20 11 my ( $pkg, %p ) = @_;
21  
22 11 my $self = bless {
23 _msg => {}, # Internal message hash, will store the report results
24 _files_parsed => 0, # Number of files parsed
25 %p
26 }, $pkg;
27  
28 11 ▶ if ( defined $self->{folder} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'folder'}) { } 3 8 11
29  
30 # When folder is defined, then we need to produce a synthesis report synopsis
31 3 $self->{_files_parsed} = $self->_read_logfiles(); # Gather the data
32 } else {
33  
34 # Gather file info for displaying area/power
35  
36 # First check the input parameters
37 # Key is required
38 8 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"key"} or $self->{"key"} ne "area" and $self->{"key"} ne "active" and $self->{"key"} ne "leakage") 0 8 8
Condition44%4/9
not defined $self->{"key"} or $self->{"key"} ne "area" and $self->{"key"} ne "active" and $self->{"key"} ne "leakage"
l!l&&r!l&&!r
008
$self->{"key"} ne "area" and $self->{"key"} ne "active" and $self->{"key"} ne "leakage"
!ll&&!rl&&r
800
$self->{"key"} ne "area" and $self->{"key"} ne "active"
!ll&&!rl&&r
530
MC/DC0%0/4
not defined $self->{"key"} or $self->{"key"} ne "area" and $self->{"key"} ne "active" and $self->{"key"} ne "leakage"
not defined $self->{"key"} $self->{"key"} ne "area" $self->{"key"} ne "active" $self->{"key"} ne "leakage"
Truth table40%2/5
not(A) or B and C and D
A= not defined $self->{"key"}B= $self->{"key"} ne "area"C= $self->{"key"} ne "active"D= $self->{"key"} ne "leakage"
ABCDresult
1XXX1
01111
00XX0
010X0
01100
39 !defined $self->{key}
40 || ( $self->{key} ne 'area'
41 && $self->{key} ne 'active'
42 && $self->{key} ne 'leakage' )
43 )
44 {
45 0 croak
46 "'key' is a required input parameter and should be 'area', 'active' or 'leakage'";
47 }
48  
49 # Threshold not, defaults to 1 if it is not defined
50 8 ▶ $self->{threshold} = $self->{threshold} || 1;
Condition100%2/2
$self->{'threshold'} || 1
l!l
44
MC/DC100%1/1
$self->{'threshold'} || 1
$self->{'threshold'}
Truth table100%2/2
A
A= $self->{'threshold'}
Aresult
11
00
51  
52 # Sanity check on input files based on the sort key
53 8 ▶ if ( $self->{key} eq 'area' && ( !defined $self->{area_rpt} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"key"} eq "area" and not defined $self->{"area_rpt"}) 0 8 8
Condition66%2/3
$self->{"key"} eq "area" and not defined $self->{"area_rpt"}
!ll&&!rl&&r
350
MC/DC0%0/2
$self->{"key"} eq "area" and not defined $self->{"area_rpt"}
$self->{"key"} eq "area" not defined $self->{"area_rpt"}
Truth table66%2/3
A and not(B)
A= $self->{"key"} eq "area"B= not defined $self->{"area_rpt"}
ABresult
0X0
100
111
54 0 croak
55 "Please specify an area report file if you want to sort according to area";
56 }
57  
58 8 ▶ if ( ( $self->{key} eq 'active' || $self->{key} eq 'leakage' )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"key"} eq "active" || $self->{"key"} eq "leakage" and not defined $self->{"power_rpt"}) 0 8 8
Condition66%4/6
$self->{"key"} eq "active" || $self->{"key"} eq "leakage" and not defined $self->{"power_rpt"}
!ll&&!rl&&r
530
$self->{"key"} eq "active" or $self->{"key"} eq "leakage"
l!l&&r!l&&!r
305
MC/DC0%0/3
$self->{"key"} eq "active" || $self->{"key"} eq "leakage" and not defined $self->{"power_rpt"}
$self->{"key"} eq "active" $self->{"key"} eq "leakage" not defined $self->{"power_rpt"}
Truth table40%2/5
A or B and not(C)
A= $self->{"key"} eq "active"B= $self->{"key"} eq "leakage"C= not defined $self->{"power_rpt"}
ABCresult
00X0
1X00
0100
1X11
0111
59 && ( !defined $self->{power_rpt} ) )
60 {
61 0 croak
62 "Please specify a power report file if you want to sort according to power numbers";
63 }
64  
65 # Read the reports
66 8 $self->{_files_parsed} = $self->_read_reports();
67  
68 # And sort the results
69 7 $self->_sort_data();
70 }
71  
72 10 return $self;
73  
74 }
75  
76  
77 2 ▶sub files_parsed { shift->{_files_parsed} }
Subroutine files_parsed: called CC=1 SCAR=0.0
Pod documented
78  
79 3 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
80 3 my ( $self, $type ) = @_;
81 3 my $count = keys %{ $self->{_msg}->{$type} };
82 3 return $count;
83 }
84  
85  
86 0 ▶sub overview {
Subroutine overview: not called CC=6 SCAR=37.4
Pod documented
87 0 my ( $self, $type ) = @_;
88  
89 # Report slack
90 0 ▶ if ( $self->{_slack}->{_negative} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_slack"}{"_negative"}) 0 0 0
91 0 print "ERROR: ";
92 }
93  
94 0 foreach my $clock ( keys %{ $self->{_slack} } ) {
95 0 ▶ next if ( $clock eq '_negative' ); # Skip housekeeping variable
Branch: 1 branch
BranchTrueFalseTotal
if $clock eq "_negative" 0 0 0
96 0 my $slack = $self->{_slack}->{$clock}->{slack};
97 0 ▶ my $violators = $self->{_slack}->{$clock}->{violators} || 'no';
Condition0%0/2
$self->{'_slack'}{$clock}{'violators'} || 'no'
l!l
00
MC/DC0%0/1
$self->{'_slack'}{$clock}{'violators'} || 'no'
$self->{'_slack'}{$clock}{'violators'}
Truth table0%0/2
A
A= $self->{'_slack'}{$clock}{'violators'}
Aresult
11
00
98 0 say "Clock '$clock' slack is $slack ps. (# $violators nets);";
99 }
100  
101 0 say "-------------";
102  
103 # Report info/warning/errors
104 0 my @types = ( 'info', 'warning', 'error' );
105  
106 0 foreach my $type (@types) {
107 0 my $count = keys %{ $self->{_msg}->{$type} };
108 0 say "$count '$type' messages found";
109 }
110  
111 0 say "-------------";
112  
113 }
114  
115 36 ▶sub get {
Subroutine get: called CC=3 SCAR=11.0
Pod documented
116 36 my ( $self, $type ) = @_;
117  
118 36 ▶ return $self->{_msg}->{$type} if ( $type ~~ [qw(info warning error)] );
Branch: 1 branch
BranchTrueFalseTotal
if $type ~~ ["info", "warning", "error"] 0 36 36
119 return $self->{_data}->{root}->{$type}->{total}
120 36 ▶ if ( $type ~~ [qw(area active leakage)] );
Branch: 1 branch
BranchTrueFalseTotal
if $type ~~ ["area", "active", "leakage"] 34 2 36
121 2 return $self->{$type}; # Enable self-checking of parameters in tests
122 }
123  
124 0 ▶sub list {
Subroutine list: not called CC=3 SCAR=24.8
Pod documented
125 0 my ( $self, $type ) = @_;
126  
127 0 my $messages = $self->get($type);
128  
129 0 ▶ say "* Detected $type messages:" if ( keys %{$messages} );
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$messages;} 0 0 0
130  
131 0 foreach my $key ( keys %{$messages} ) {
132 0 $self->_nice_print( $key, $messages->{$key} );
133 }
134 }
135  
136 1 ▶sub slack {
Subroutine slack: called CC=1 SCAR=0.0
Pod documented
137 1 my ( $self, $clock ) = @_;
138  
139 1 return $self->{_slack}->{$clock}->{slack};
140  
141 }
142  
143 5 ▶sub report {
Subroutine report: called CC=12 SCAR=24.8
Pod documented
144 5 my ( $self, %p ) = @_;
145  
146 5 my $data = $self->{_data};
147  
148 # First report the totals
149 5 ▶ say "Total area : " . $self->get('area') . " um2"
Branch: 1 branch
BranchTrueFalseTotal
if $self->get("area") 3 2 5
150 if ( $self->get('area') );
151 5 ▶ say "Total active : " . $self->get('active') . " mW"
Branch: 1 branch
BranchTrueFalseTotal
if $self->get("active") 4 1 5
152 if ( $self->get('active') );
153 5 ▶ say "Total leakage: " . $self->get('leakage') . " mW"
Branch: 1 branch
BranchTrueFalseTotal
if $self->get("leakage") 4 1 5
154 if ( $self->get('leakage') );
155  
156 5 say "% : " . $self->_format_str("Name") . "\tArea\tActive\tLeakage ";
157 5 say " " . $self->_format_str("") . "\t(um2)\t(mW)\t(mW)";
158 5 say "----------------------------------------------------------------";
159  
160 5 foreach my $procent ( sort { $b <=> $a } keys %{$data->{detail}} ) {
161 30 foreach my $item ( sort keys %{$data->{detail}->{$procent}} ) {
162 234 my $leaf = $data->{detail}->{$procent}->{$item};
163 234 ▶ my $area = $leaf->{area} || '--';
Condition100%2/2
$leaf->{'area'} || '--'
l!l
2268
MC/DC100%1/1
$leaf->{'area'} || '--'
$leaf->{'area'}
Truth table100%2/2
A
A= $leaf->{'area'}
Aresult
11
00
164 234 ▶ my $active = $leaf->{active} || '--';
Condition100%2/2
$leaf->{'active'} || '--'
l!l
124110
MC/DC100%1/1
$leaf->{'active'} || '--'
$leaf->{'active'}
Truth table100%2/2
A
A= $leaf->{'active'}
Aresult
11
00
165 234 ▶ my $leak = $leaf->{leakage} || '--';
Condition100%2/2
$leaf->{'leakage'} || '--'
l!l
124110
MC/DC100%1/1
$leaf->{'leakage'} || '--'
$leaf->{'leakage'}
Truth table100%2/2
A
A= $leaf->{'leakage'}
Aresult
11
00
166  
167 say $self->_format_int($procent) . " : "
168 . $self->_format_str( $leaf->{name} )
169 234 . "\t$area\t$active\t$leak";
170 }
171 }
172  
173 # Output formatting in case the value is zero (file not read)
174 5 ▶ my $stash_area = $data->{stash}->{area} || '--';
Condition100%2/2
$data->{'stash'}{'area'} || '--'
l!l
14
MC/DC100%1/1
$data->{'stash'}{'area'} || '--'
$data->{'stash'}{'area'}
Truth table100%2/2
A
A= $data->{'stash'}{'area'}
Aresult
11
00
175 5 ▶ my $stash_active = $data->{stash}->{active} || '--';
Condition100%2/2
$data->{'stash'}{'active'} || '--'
l!l
14
MC/DC100%1/1
$data->{'stash'}{'active'} || '--'
$data->{'stash'}{'active'}
Truth table100%2/2
A
A= $data->{'stash'}{'active'}
Aresult
11
00
176 5 ▶ my $stash_leakage = $data->{stash}->{leakage} || '--';
Condition100%2/2
$data->{'stash'}{'leakage'} || '--'
l!l
14
MC/DC100%1/1
$data->{'stash'}{'leakage'} || '--'
$data->{'stash'}{'leakage'}
Truth table100%2/2
A
A= $data->{'stash'}{'leakage'}
Aresult
11
00
177  
178 5 say $self->_format_int( $data->{stash}->{percent} ) . " : "
179 . $self->_format_str('<other units>')
180 . "\t$stash_area\t$stash_active\t$stash_leakage";
181  
182 }
183  
184 3 ▶sub get_final {
Subroutine get_final: called CC=1 SCAR=0.0
Pod documented
185 3 my ( $self, $key) = @_;
186  
187 3 return $self->{_final}->{$key};
188  
189 }
190  
191 # Private function to display a single message to STDOUT
192 0 ▶sub _nice_print {
Subroutine _nice_print: not called CC=1 SCAR=6.9
193 0 my ( $self, $key, $message ) = @_;
194  
195 0 my $count = $message->{count};
196 0 my $msg = $message->{message};
197  
198 0 printf "%s\t%4i %s\n", $key, $count, $msg;
199  
200 }
201  
202 # Internal function to read the logfiles from the source folder and place the
203 # messages into the data hash
204 3 ▶sub _read_logfiles {
Subroutine _read_logfiles: called CC=5 SCAR=16.1
205  
206 3 my ( $self, %p ) = @_;
207  
208 # Glob all relevant logfiles (=gather their names)
209 3 my $foldername = $self->{folder};
210  
211 3 ▶ if ( !-e $foldername ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $foldername) 0 3 3
212 0 croak "Result folder '$foldername' does not exist";
213 }
214  
215 4 ▶ my @files = glob( $foldername . "/*.summary" );
Subroutine BEGIN: called CC=1 SCAR=0.0
216  
217 3 print "Going to parse files from folder '$foldername': \n" . Dumper(@files)
218 if DEBUG1;
219  
220 # Go over the files one by one and extract info
221 3 foreach my $file (@files) {
222 6 $self->_gather_entries($file);
223 }
224  
225 3 print "Found: \n" . Dumper( $self->{_msg} ) if DEBUG;
226  
227 3 my @timing_logs = glob( $foldername . "/report_qor_map_*" );
228  
229 # Go over the files one by one and extract slack info
230 3 foreach my $file (@timing_logs) {
231 1 $self->_gather_slack($file);
232 1 push @files, $file;
233 }
234  
235 3 my $final_file = $foldername . "/final.rpt";
236  
237 3 ▶ if (-e $foldername . "/final.rpt") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $foldername . '/final.rpt') 2 1 3
238 2 $self->_gather_final($final_file);
239 2 push @files, $final_file;
240 }
241  
242 3 return scalar @files;
243  
244 }
245  
246 # Internal function to read the power/area reports
247 8 ▶sub _read_reports {
Subroutine _read_reports: called CC=3 SCAR=11.0
248 8 my ( $self, %p ) = @_;
249  
250 8 my @files;
251  
252 8 ▶ push @files, $self->_parse_area() if ( defined $self->{area_rpt} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"area_rpt"} 6 2 8
253 8 ▶ push @files, $self->_parse_power() if ( defined $self->{power_rpt} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"power_rpt"} 7 1 8
254  
255 7 return @files;
256 }
257  
258 # Parse the area log report, expecting Encounter RTL compiler file
259 6 ▶sub _parse_area {
Subroutine _parse_area: called CC=7 SCAR=19.5
260 6 my ( $self, %p ) = @_;
261  
262 6 my $filename = $self->{area_rpt};
263  
264 6 ▶ open my $fh, "<", $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or die "Could not open ${filename}: $!" 6 0 6
265 or die "Could not open $filename: $!";
266  
267 6 say "Parsing area report $filename";
268  
269 6 my $line;
270  
271 # Skip until we enter the 'data' zone
272 6 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 90 0 90
273 90 $line = $_;
274 90 ▶ if ( $line =~ /\-{5}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\-{5}/u) 6 84 90
275 6 last;
276 }
277 }
278  
279 # Now parse :-)
280 6 my $regexp = '(\w+)\s+\w+\s+\d+\s+(\d+)';
281  
282 6 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 8496 6 8502
283 8496 $line = $_;
284 8496 ▶ if ( $line =~ /^$regexp/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^$regexp/u) 6 8490 8496
285  
286 #say "root: $1 \t$2";
287 6 $self->{_data}->{root}->{name} = $1;
288 6 $self->{_data}->{root}->{area}->{total} = $2;
289 6 $self->{_data}->{root}->{area}->{sum_leaves} = 0;
290 }
291 8496 ▶ if ( $line =~ /^\s\s$regexp/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s\s$regexp/u) 654 7842 8496
292 654 my $partial_area = $2;
293 654 $self->{_data}->{leaf}->{$1}->{area} = $partial_area;
294 654 $self->{_data}->{root}->{area}->{sum_leaves} += $partial_area;
295 }
296 }
297  
298 6 close $fh;
299  
300 6 return $filename;
301  
302 }
303  
304 # Parse the power log report, expecting Encouter output file
305 7 ▶sub _parse_power {
Subroutine _parse_power: called CC=10 SCAR=23.0
306 7 my ( $self, %p ) = @_;
307  
308 7 my $filename = $self->{power_rpt};
309  
310 7 ▶ open my $fh, "<", $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or die "Could not open ${filename}: $!" 7 0 7
311 or die "Could not open $filename: $!";
312  
313 7 say "Parsing power report $filename";
314  
315 7 my $line;
316  
317 7 my $file_type = 'normal';
318  
319 # Skip until we enter the 'data' zone
320 7 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 75 1 76
321 75 $line = $_;
322  
323 # Detect if we're reading a file in normal output mode or in verbose mode
324 75 ▶ $file_type = 'verbose' if (/Leakage\s+Internal\s+Net/);
Branch: 1 branch
BranchTrueFalseTotal
if /Leakage\s+Internal\s+Net/u 1 74 75
325  
326 75 ▶ if ( $line =~ /\-{5}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\-{5}/u) 6 69 75
327 6 last;
328 }
329 }
330  
331 # Now parse :-)
332 # Regexp for normal mode parsing
333 7 my $regexp = '(\w+)\s+\w+\s+\d+\s+([0-9]*\.?[0-9]+)\s+([0-9]*\.?[0-9]+)';
334  
335 # In case the file is verbose mode output then we need another regexp!
336 7 ▶ $regexp = '(\w+)\s+\w+\s+\d+\s+([0-9]*\.?[0-9]+)\s+[0-9]*\.?[0-9]+\s+[0-9]*\.?[0-9]+\s+([0-9]*\.?[0-9]+)' if ($file_type eq 'verbose');
Branch: 1 branch
BranchTrueFalseTotal
if $file_type eq "verbose" 1 6 7
337  
338 7 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 5676 7 5683
339 5676 $line = $_;
340 5676 ▶ if ( $line =~ /^$regexp/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^$regexp/u) 6 5670 5676
341  
342 # TODO check for same root name here as a test to see if area and power reports match.
343 #say "root: $1 \t$2";
344 6 $self->{_data}->{root}->{name} = $1;
345 6 $self->{_data}->{root}->{leakage}->{total} = $2;
346 6 $self->{_data}->{root}->{active}->{total} = $3;
347 6 $self->{_data}->{root}->{active}->{sum_leaves} = 0;
348  
349 }
350  
351 5676 ▶ if ( $line =~ /^\s\s$regexp/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s\s$regexp/u) 442 5234 5676
352 442 $self->{_data}->{leaf}->{$1}->{leakage} = $2;
353 442 $self->{_data}->{leaf}->{$1}->{active} = $3;
354 442 $self->{_data}->{root}->{leakage}->{sum_leaves} += $2;
355 442 $self->{_data}->{root}->{active}->{sum_leaves} += $3;
356 }
357 }
358  
359 7 close $fh;
360  
361 7 ▶ croak "Power input report '$filename' was empty, please check it." if (!defined $self->{_data}->{root}->{active}->{total});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_data"}{"root"}{"active"}{"total"} 1 6 7
362  
363 6 return $filename;
364  
365 }
366  
367 # This function gathers the entries from a single logfile and
368 # puts them in the $msg hash
369 6 ▶sub _gather_entries {
Subroutine _gather_entries: called CC=8 SCAR=20.8
370 6 my ( $self, $fname ) = @_;
371  
372 6 print "Gathering messages in file '$fname'\n" if DEBUG;
373  
374 6 ▶ open my $fh, '<', $fname
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $fname or croak("Could not open file '${fname}' for reading: $!") 6 0 6
375 or croak "Could not open file '$fname' for reading: $!";
376  
377 6 my $type;
378 my $code;
379  
380 6 ▶ SKIP_HEADER: while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 28 2 30
381 28 ▶ last if (/-----/);
Branch: 1 branch
BranchTrueFalseTotal
if /-----/u 4 24 28
382 }
383  
384 6 ▶ PARSE_ENTRIES: while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 90 6 96
385  
386 # Typical line we're looking for looks like this:
387 # ' 2 Warning ENC-6 Problems detected during configuration file'
388 90 ▶ if ( $line =~ /^\s*(\d+)\s(\w+)\s([-\w]+)\s+(.+\S)\s+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*(\d+)\s(\w+)\s([-\w]+)\s+(.+\S)\s+/u) 20 70 90
389  
390 # When we encounter such line, make a new entry in the message hash
391 20 my $count = $1;
392 20 $type = lc($2);
393 20 $code = $3;
394 20 my $message = $4;
395 20 print "$count -- $type -- $code -- $message\n" if DEBUG1;
396 20 $self->{_msg}->{$type}->{$code}->{message} = $message;
397 20 $self->{_msg}->{$type}->{$code}->{count} = $count;
398 20 next;
399 }
400  
401 70 ▶ if ( $line =~ /\s*(\S.+\S)\s+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\s*(\S.+\S)\s+/u) 67 3 70
402 67 ▶ croak "Parsing error: found text before info line in '$fname'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 67 67
403 if ( !defined $type );
404  
405 # Append other lines to the last seen message
406 67 $self->{_msg}->{$type}->{$code}->{message} .= " $1";
407 }
408  
409 }
410  
411 6 close $fh;
412 }
413  
414 # This function gathers the slack entries from a single logfile and
415 # puts them in the $msg hash
416 1 ▶sub _gather_slack {
Subroutine _gather_slack: called CC=6 SCAR=18.3
417 1 my ( $self, $fname ) = @_;
418  
419 1 print "Gathering messages in file '$fname'\n" if DEBUG;
420  
421 1 ▶ open my $fh, '<', $fname
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $fname or croak("Could not open file '${fname}' for reading: $!") 1 0 1
422 or croak "Could not open file '$fname' for reading: $!";
423  
424 1 ▶ SKIP_HEADER: while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 24 0 24
425 24 ▶ last if (/Slack/);
Branch: 1 branch
BranchTrueFalseTotal
if /Slack/u 1 23 24
426 }
427  
428 # Skip next line
429 1 my $line = <$fh>;
430  
431 # Next one is the one we need
432 1 $line = <$fh>;
433  
434 # PARSE_ENTRIES: while ( $line = <$fh> ) {
435 1 ▶ if ( $line =~ /\w+\s+(\w+)\s+(-?\d+.?\d*)\s+(\d*)\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\w+\s+(\w+)\s+(-?\d+.?\d*)\s+(\d*)\s/u) { } 1 0 1
436 1 my $group = $1;
437 1 my $slack = $2;
438 1 my $nr_paths = $3;
439  
440 1 $self->{_slack}->{$group}->{slack} = $slack;
441 1 $self->{_slack}->{$group}->{violators} = $nr_paths;
442  
443 1 ▶ if ( $slack < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slack < 0) 1 0 1
444 1 $self->{_slack}->{_negative} = 1;
445 }
446 } else {
447 0 carp "Warning: could not extract slack information from logfiles";
448 }
449  
450 # }
451  
452 1 close $fh;
453  
454 }
455  
456 # Extract the information from the final.rpt file
457 2 ▶sub _gather_final {
Subroutine _gather_final: called CC=7 SCAR=19.5
458 2 my ( $self, $fname ) = @_;
459  
460 2 print "Gathering messages in file '$fname'\n" if DEBUG;
461  
462 2 ▶ open my $fh, '<', $fname
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $fname or croak("Could not open file '${fname}' for reading: $!") 2 0 2
463 or croak "Could not open file '$fname' for reading: $!";
464  
465 2 my $match_col;
466  
467 my $line;
468  
469 # We want to know in what column the total ('final') data is present.
470 # We need to autodetect this because it differes depending on the flow type that was run
471 2 ▶ DETECT_COLUMN: while ($line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh)) 12 0 12
472 12 ▶ if ($line =~ /Metric/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Metric/u) 2 10 12
473 2 my @columns = split /\s+/, $line;
474 # Use an index hash to find what the index is of the column we're looking for
475 2 my %indhash;
476 2 @indhash{@columns} = (0 .. $#columns);
477  
478 2 $match_col = $indhash{'final'};
479  
480 2 last;
481 }
482 }
483  
484 # Data begins until next empty line
485 2 ▶ FETCH_DATA : while ($line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh)) 62 0 62
486 62 ▶ if ($line =~ /====/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /====/u) { } 6 56 62
elsif ($line eq "\n") { } 2 54 56
487 # Skip separator lines
488 6 next;
489 } elsif ($line eq "\n") {
490 # Stop processing on empty line beacuse we need to switch the handling of the data from here on (other format)
491 2 last;
492 } else {
493 # Data -> process it
494 # First the metric (everything before the :)
495 54 my @data = split /:/, $line;
496 54 my $metric = $data[0];
497  
498 # Remove leading spaces in the metric;
499 54 $metric =~ s/^\s+//;
500  
501 # Then the values
502 54 my @columns = split /\s+/, $data[1];
503  
504 54 my $value = $columns[$match_col];
505  
506 54 $self->{_final}->{$metric} = $value;
507 }
508 }
509  
510 # TODO Check if we need to strip the untis from the metric and put them on another place in the hash.
511  
512 # skip 3 lines
513 #$line = <$fh>;
514 #$line = <$fh>;
515 #$line = <$fh>;
516  
517 # TODO Fetch the totals and store them too.
518 #PARSE_TOTALS: while ($line = <$fh>) {
519 # if ($line =~ /^([^:]):\s+(\.+)/) {
520 # $self->{_final}->{$1} = $2;
521 # }
522 #}
523  
524 2 close $fh;
525 }
526  
527 # Nicely print a string
528 249 ▶sub _format_str {
Subroutine _format_str: called CC=1 SCAR=0.0
529 249 my ( $self, $val ) = @_;
530 249 my $len = $self->{_presentation}->{namelength};
531 249 return sprintf( "%-" . $len . "s", $val );
532 }
533  
534 # nicely print an int
535 239 ▶sub _format_int {
Subroutine _format_int: called CC=2 SCAR=6.9
536 239 my ( $self, $val ) = @_;
537 239 ▶ $val = $val || 0; # Catch cases where the val is not initialized
Condition100%2/2
$val || 0
l!l
43196
MC/DC100%1/1
$val || 0
$val
Truth table100%2/2
A
A= $val
Aresult
11
00
538 239 return sprintf( "%2i", $val );
539 }
540  
541 # Sort the data according to the passed key
542 7 ▶sub _sort_data {
Subroutine _sort_data: called CC=14 SCAR=26.4
543  
544 7 my ( $self, %p ) = @_;
545  
546 7 my $key = $self->{key};
547 7 my $threshold = $self->{threshold};
548  
549 7 my $total = $self->get($key);
550 7 my $threshold_abs = $total * $threshold / 100;
551  
552 7 ▶ my $unit = $self->{key} eq 'area' ? 'um2' : 'mW';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'key'} eq 'area' ? : 5 2 7
553  
554 7 say "Sorting on '$key'";
555  
556 7 $self->{_presentation}->{namelength} = 0;
557  
558 # Insert an entry for the toplevel so that it get reported if required
559 7 my ($top_area, $top_active, $top_leakage);
560 7 ▶ $top_area = $self->{_data}->{root}->{area}->{total} - $self->{_data}->{root}->{area}->{sum_leaves} if (defined $self->{_data}->{root}->{area});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_data"}{"root"}{"area"} 5 2 7
561 7 ▶ $top_active = $self->{_data}->{root}->{active}->{total} - $self->{_data}->{root}->{active}->{sum_leaves} if (defined $self->{_data}->{root}->{active});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_data"}{"root"}{"active"} 6 1 7
562 7 ▶ $top_leakage = $self->{_data}->{root}->{leakage}->{total} - $self->{_data}->{root}->{leakage}->{sum_leaves} if (defined $self->{_data}->{root}->{leakage});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_data"}{"root"}{"leakage"} 6 1 7
563  
564 # Ensure the right format is used
565 7 ▶ $top_area = sprintf("%d", $top_area) if (defined $top_area);
Branch: 1 branch
BranchTrueFalseTotal
if defined $top_area 5 2 7
566 7 ▶ $top_active = sprintf("%1.3f", $top_active) if (defined $top_active);
Branch: 1 branch
BranchTrueFalseTotal
if defined $top_active 6 1 7
567 7 ▶ $top_leakage = sprintf("%1.3f", $top_leakage) if (defined $top_leakage);
Branch: 1 branch
BranchTrueFalseTotal
if defined $top_leakage 6 1 7
568  
569 7 $self->{_data}->{leaf}->{'toplevel'}->{area} = $top_area;
570 7 $self->{_data}->{leaf}->{'toplevel'}->{active} = $top_active;
571 7 $self->{_data}->{leaf}->{'toplevel'}->{leakage} = $top_leakage;
572  
573 7 foreach my $entry ( keys %{$self->{_data}->{leaf}} ) {
574 558 my $value = $self->{_data}->{leaf}->{$entry}->{$key};
575 558 my $percentage = $value / $total * 100;
576  
577 558 ▶ if ( $percentage >= $threshold ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($percentage >= $threshold) { } 258 300 558
578  
579 # Store in the 'to be printed with details' hash
580 258 $percentage = int($percentage);
581 258 $self->{_data}->{leaf}->{$entry}->{name} = $entry;
582 258 $self->{_data}->{detail}->{$percentage}->{$entry} = $self->{_data}->{leaf}->{$entry};
583  
584 # Update the length of the name for printing later
585 258 my $namelength = length($entry);
586 $self->{_presentation}->{namelength} = $namelength
587 258 ▶ if ( $self->{_presentation}->{namelength} < $namelength );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_presentation"}{"namelength"} < $namelength 13 245 258
588 } else {
589 300 $self->{_data}->{stash}->{percent} += $percentage;
590 $self->{_data}->{stash}->{area} +=
591 300 ▶ $self->{_data}->{leaf}->{$entry}->{area} || 0;
Condition50%1/2
$self->{'_data'}{'leaf'}{$entry}{'area'} || 0
l!l
3000
MC/DC0%0/1
$self->{'_data'}{'leaf'}{$entry}{'area'} || 0
$self->{'_data'}{'leaf'}{$entry}{'area'}
Truth table50%1/2
A
A= $self->{'_data'}{'leaf'}{$entry}{'area'}
Aresult
11
00
592 $self->{_data}->{stash}->{active} +=
593 300 ▶ $self->{_data}->{leaf}->{$entry}->{active} || 0;
Condition50%1/2
$self->{'_data'}{'leaf'}{$entry}{'active'} || 0
l!l
3000
MC/DC0%0/1
$self->{'_data'}{'leaf'}{$entry}{'active'} || 0
$self->{'_data'}{'leaf'}{$entry}{'active'}
Truth table50%1/2
A
A= $self->{'_data'}{'leaf'}{$entry}{'active'}
Aresult
11
00
594 $self->{_data}->{stash}->{leakage} +=
595 300 ▶ $self->{_data}->{leaf}->{$entry}->{leakage} || 0;
Condition50%1/2
$self->{'_data'}{'leaf'}{$entry}{'leakage'} || 0
l!l
3000
MC/DC0%0/1
$self->{'_data'}{'leaf'}{$entry}{'leakage'} || 0
$self->{'_data'}{'leaf'}{$entry}{'leakage'}
Truth table50%1/2
A
A= $self->{'_data'}{'leaf'}{$entry}{'leakage'}
Aresult
11
00
596 }
597 }
598  
599 }
600 4 1;
601  
602 # ABSTRACT: Perl module to parse Cadence synthesis tool logfiles
603  
604 __END__
↑ Summary script/synth_log.pl »