diff options
author | Jason Evans <je@facebook.com> | 2010-04-03 01:43:28 (GMT) |
---|---|---|
committer | Jason Evans <je@facebook.com> | 2010-04-03 01:49:34 (GMT) |
commit | ec5344eba282b2bc2f854bdb174e3c97abff83c9 (patch) | |
tree | 1b145ed1c3d3d0ae797b02ada9207a585a741a2c | |
parent | a53610130d06fa55dd84031d127c8c46e3e44711 (diff) | |
download | jemalloc-ec5344eba282b2bc2f854bdb174e3c97abff83c9.zip jemalloc-ec5344eba282b2bc2f854bdb174e3c97abff83c9.tar.gz jemalloc-ec5344eba282b2bc2f854bdb174e3c97abff83c9.tar.bz2 |
Optimize ExtractSymbols (pprof).
Modify ExtractSymbols to operate on sorted PCs and libraries, in order
to reduce computational complexity from O(N*M) to O(N+M).
-rwxr-xr-x | jemalloc/bin/pprof | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/jemalloc/bin/pprof b/jemalloc/bin/pprof index 7b39dc4..73d35dd 100755 --- a/jemalloc/bin/pprof +++ b/jemalloc/bin/pprof @@ -3681,8 +3681,17 @@ sub ExtractSymbols { my $symbols = {}; # Map each PC value to the containing library - my %seen = (); - foreach my $lib (@{$libs}) { + my @pcs = (sort { $a cmp $b } keys(%{$pcset})); + my @slibs = (sort {$a->[1] cmp $b->[1]} @{$libs}); + my $bin = shift(@slibs); + if ($bin->[1] == 0) { + # Move binary to end (starts at address 0). + push(@slibs, $bin); + } else { + unshift(@slibs, $bin); + } + my $pc = shift(@pcs); + foreach my $lib (@slibs) { my $libname = $lib->[0]; my $start = $lib->[1]; my $finish = $lib->[2]; @@ -3690,14 +3699,18 @@ sub ExtractSymbols { # Get list of pcs that belong in this library. my $contained = []; - foreach my $pc (keys(%{$pcset})) { - if (!$seen{$pc} && ($pc ge $start) && ($pc le $finish)) { - $seen{$pc} = 1; - push(@{$contained}, $pc); + while (($pc ge $start) && ($pc le $finish)) { + push(@{$contained}, $pc); + $pc = shift(@pcs); + if (!defined $pc) { + last; } } # Map to symbols MapToSymbols($libname, AddressSub($start, $offset), $contained, $symbols); + if (!defined $pc) { + last; + } } return $symbols; |