]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Misc fixes for callgrind_annotate
authorJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Tue, 11 Aug 2009 14:45:00 +0000 (14:45 +0000)
committerJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Tue, 11 Aug 2009 14:45:00 +0000 (14:45 +0000)
* Patch from bug 198649 (callgrind_annotate doesn't cumulate counters)
  When there were multiple call sites in one line, the aggregated
  call count/cost numbers in the source annotation were wrong
* Callgrind often produces absolute file names.
  Make it work with relative file names requested for annotation from
  the command lines.
* More in sync with parser in KCachegrind: make summary line optional.
  We can also use the "totals:" line for this.
* Count of numbers in summary can be smaller then number of events given

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10777

callgrind/callgrind_annotate.in

index 5f7393dcd82103099fce82899838074918ebda43..0a8c301285099b61f61f6f64e9a09c8e4bd38761 100644 (file)
@@ -80,6 +80,7 @@ use strict;
 
 # Total counts for summary (an array reference).
 my $summary_CC;
+my $totals_CC;
 
 # Totals for each function, for overall summary.
 # hash(filename:fn_name => CC array)
@@ -349,6 +350,17 @@ sub add_array_a_to_b ($$)
     $^W = 1;
 }
 
+# Is this a line with all events zero?
+sub is_zero ($)
+{
+    my ($CC) = @_;
+    my $isZero = 1;
+    foreach my $i (0 .. (scalar @$CC)-1) {
+       $isZero = 0 if ($CC->[$i] >0);
+    }
+    return $isZero;
+}
+
 # Add each event count to the CC array.  '.' counts become undef, as do
 # missing entries (implicitly).
 sub line_to_CC ($)
@@ -478,6 +490,11 @@ sub read_input_file()
         $thresholds[0] = $single_threshold;
     }
 
+    # Current directory, used to strip from file names if absolute
+    my $pwd = `pwd`;
+    chomp $pwd;
+    $pwd .= '/';
+
     my $curr_obj = "";
     my $curr_file;
     my $curr_fn;
@@ -536,8 +553,14 @@ sub read_input_file()
              $tmp = {} unless defined $tmp;
              $$tmp{$curr_cname} = 1;
              $called_from_line->{$curr_file,$curr_line_num} = $tmp;
-             $call_CCs{$curr_name,$curr_cname,$curr_line_num} = $CC;
-             $call_counter{$curr_name,$curr_cname,$curr_line_num} = $curr_call_counter;
+             if(defined $call_CCs{$curr_name,$curr_cname,$curr_line_num}) {
+               add_array_a_to_b($CC, $call_CCs{$curr_name,$curr_cname,$curr_line_num});
+               $call_counter{$curr_name,$curr_cname,$curr_line_num} += $curr_call_counter;
+              }
+              else {
+               $call_CCs{$curr_name,$curr_cname,$curr_line_num} = $CC;
+               $call_counter{$curr_name,$curr_cname,$curr_line_num} = $curr_call_counter;
+              }
 
              $curr_call_counter = 0;
 
@@ -584,6 +607,7 @@ sub read_input_file()
                 if (defined $curr_file);
 
             $curr_file = uncompressed_name("fl",$1);
+           $curr_file =~ s/^$pwd//;
             $curr_file_ind_CCs = $all_ind_CCs{$curr_file};
             $curr_file_ind_CCs = {} unless (defined $curr_file_ind_CCs);
 
@@ -593,6 +617,7 @@ sub read_input_file()
             $all_ind_CCs{$curr_file} = $curr_file_ind_CCs;
 
             $curr_file = uncompressed_name("fl",$2);
+           $curr_file =~ s/^$pwd//;
             $curr_name = "$curr_file:$curr_fn";
             $curr_file_ind_CCs = $all_ind_CCs{$curr_file};
             $curr_file_ind_CCs = {} unless (defined $curr_file_ind_CCs);
@@ -645,7 +670,7 @@ sub read_input_file()
           # ignore jump information
 
         } elsif (s/^totals:\s+//) {
-         #ignore
+           $totals_CC = line_to_CC($_);
 
         } elsif (s/^summary:\s+//) {
             $summary_CC = line_to_CC($_);
@@ -656,21 +681,21 @@ sub read_input_file()
         }
     }
 
+    if ((not defined $summary_CC) || is_zero($summary_CC)) {
+       $summary_CC = $totals_CC;
+    }
+
     # Check if summary line was present
     if (not defined $summary_CC) {
         warn("WARNING: missing final summary line, no summary will be printed\n");
     }
-    else {
-      # Finish up handling final filename/fn_name counts
-      $fn_totals{"$curr_file:$curr_fn"} = $curr_fn_CC 
+
+    # Finish up handling final filename/fn_name counts
+    $fn_totals{"$curr_file:$curr_fn"} = $curr_fn_CC
        if (defined $curr_file && defined $curr_fn);
-      $all_ind_CCs{$curr_file} = 
+    $all_ind_CCs{$curr_file} =
        $curr_file_ind_CCs if (defined $curr_file);
 
-      (scalar(@$summary_CC) == @events) 
-       or die("Line $.: summary event and total event mismatch\n");
-    }
-
     # Correct inclusive totals
     if ($inclusive) {
       foreach my $name (keys %cfn_totals) {