|
From: <sv...@va...> - 2010-06-22 03:40:14
|
Author: njn
Date: 2010-06-22 04:40:04 +0100 (Tue, 22 Jun 2010)
New Revision: 11184
Log:
Allow negative numbers in the cachegrind.out.* file. Also protect against
division-by-zero. Both are required for cg_diff (not yet committed) to work
properly.
Modified:
trunk/cachegrind/cg_annotate.in
Modified: trunk/cachegrind/cg_annotate.in
===================================================================
--- trunk/cachegrind/cg_annotate.in 2010-06-22 03:34:54 UTC (rev 11183)
+++ trunk/cachegrind/cg_annotate.in 2010-06-22 03:40:04 UTC (rev 11184)
@@ -168,6 +168,12 @@
# Used in various places of output.
my $fancy = '-' x 80 . "\n";
+sub safe_div($$)
+{
+ my ($x, $y) = @_;
+ return ($y == 0 ? 0 : $x / $y);
+}
+
#-----------------------------------------------------------------------------
# Argument and option handling
#-----------------------------------------------------------------------------
@@ -385,7 +391,7 @@
# Read body of input file.
while (<INPUTFILE>) {
s/#.*$//; # remove comments
- if (s/^(\d+)\s+//) {
+ if (s/^(-?\d+)\s+//) {
my $lineNum = $1;
my $CC = line_to_CC($_);
defined($currFuncCC) || die;
@@ -494,7 +500,7 @@
$x = -1 unless defined $x;
$y = -1 unless defined $y;
- my $cmp = $y <=> $x; # reverse sort
+ my $cmp = abs($y) <=> abs($x); # reverse sort of absolute size
if (0 != $cmp) {
return $cmp;
}
@@ -505,7 +511,7 @@
sub commify ($) {
my ($val) = @_;
- 1 while ($val =~ s/^(\d+)(\d{3})/$1,$2/);
+ 1 while ($val =~ s/^(-?\d+)(\d{3})/$1,$2/);
return $val;
}
@@ -614,7 +620,8 @@
# Stop when we've reached all the thresholds
my $reached_all_thresholds = 1;
foreach my $i (0 .. scalar @thresholds - 1) {
- my $prop = $curr_totals[$i] * 100 / $summary_CC->[$sort_order[$i]];
+ my $prop = safe_div(abs($curr_totals[$i] * 100),
+ abs($summary_CC->[$sort_order[$i]]));
$reached_all_thresholds &&= ($prop >= $thresholds[$i]);
}
last if $reached_all_thresholds;
@@ -874,7 +881,8 @@
foreach (my $i = 0; $i < @$summary_CC; $i++) {
$percent_printed_CC->[$i] =
sprintf("%.0f",
- $printed_totals_CC->[$i] / $summary_CC->[$i] * 100);
+ safe_div(abs($printed_totals_CC->[$i]),
+ abs($summary_CC->[$i] * 100)));
}
my $pp_CC_col_widths = compute_CC_col_widths($percent_printed_CC);
print($fancy);
|