summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pasieka <michael.pasieka@highwinds.com>2014-07-13 18:09:35 -0700
committerAliaksey Kandratsenka <alk@tut.by>2014-07-13 18:15:20 -0700
commit4b788656bb9c480640d917d27d8a94a5eae436f5 (patch)
tree29fa20fbadc5708e6a43384f7eac20abacfcf115
parent3abb5cb819bafe7004363f041c194afd827cb053 (diff)
downloadgperftools-4b788656bb9c480640d917d27d8a94a5eae436f5.tar.gz
added option to display stack traces in output for heap checker
Quoting from email: I had the same question as William posted to stack overflow back on Dec 9,2013: How to display symbols in stack trace of google-perftools heap profiler (*). I dug into the source and realized the functionality was not there but could be added. I am hoping that someone else will find this useful/helpful. The patch I created will not attach so I am adding below. Enjoy! -- Michael * http://stackoverflow.com/questions/20476918/how-to-display-symbols-in-stack-trace-of-google-perftools-heap-profiler
-rwxr-xr-xsrc/pprof28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/pprof b/src/pprof
index 26860f5..d23d4be 100755
--- a/src/pprof
+++ b/src/pprof
@@ -140,6 +140,8 @@ my @prefix_list = ();
my $sep_symbol = '_fini';
my $sep_address = undef;
+my @stackTraces;
+
##### Argument parsing #####
sub usage_string {
@@ -191,6 +193,7 @@ Reporting Granularity:
Output type:
--text Generate text report
+ --stacks Generate stack traces similar to the heap profiler (requires --text)
--callgrind Generate callgrind format to stdout
--gv Generate Postscript and display
--evince Generate PDF and display
@@ -313,6 +316,7 @@ sub Init() {
$main::opt_lib_prefix = "";
$main::opt_text = 0;
+ $main::opt_stacks = 0;
$main::opt_callgrind = 0;
$main::opt_list = "";
$main::opt_disasm = "";
@@ -383,6 +387,7 @@ sub Init() {
"addresses!" => \$main::opt_addresses,
"files!" => \$main::opt_files,
"text!" => \$main::opt_text,
+ "stacks!" => \$main::opt_stacks,
"callgrind!" => \$main::opt_callgrind,
"list=s" => \$main::opt_list,
"disasm=s" => \$main::opt_disasm,
@@ -1175,6 +1180,25 @@ sub PrintText {
my $cumulative = shift;
my $line_limit = shift;
+ if ($main::opt_stacks && @stackTraces) {
+ foreach (sort { (split " ", $b)[1] <=> (split " ", $a)[1]; } @stackTraces) {
+ print "$_\n" if $main::opt_debug;
+ my ($n1, $s1, $n2, $s2, @addrs) = split;
+ print "Leak of $s1 bytes in $n1 objects allocated from:\n";
+ foreach my $pcstr (@addrs) {
+ $pcstr =~ s/^0x//;
+ my $sym;
+ if (! defined $symbols->{$pcstr}) {
+ $sym = "unknown";
+ } else {
+ $sym = "$symbols->{$pcstr}[0] $symbols->{$pcstr}[1]";
+ }
+ print "\t@ $pcstr $sym\n";
+ }
+ }
+ print "\n";
+ }
+
my $total = TotalProfile($flat);
# Which profile to sort by?
@@ -4059,7 +4083,9 @@ sub ReadHeapProfile {
}
my @counts = ($n1, $s1, $n2, $s2);
- AddEntries($profile, $pcs, FixCallerAddresses($stack), $counts[$index]);
+ $stack = FixCallerAddresses($stack);
+ push @stackTraces, "$n1 $s1 $n2 $s2 $stack";
+ AddEntries($profile, $pcs, $stack, $counts[$index]);
}
}