mirror of
https://github.com/gperftools/gperftools
synced 2025-02-21 06:36:50 +00:00
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
This commit is contained in:
parent
3abb5cb819
commit
4b788656bb
28
src/pprof
28
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user