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).
This commit is contained in:
parent
a53610130d
commit
ec5344eba2
@ -3681,8 +3681,17 @@ sub ExtractSymbols {
|
|||||||
my $symbols = {};
|
my $symbols = {};
|
||||||
|
|
||||||
# Map each PC value to the containing library
|
# Map each PC value to the containing library
|
||||||
my %seen = ();
|
my @pcs = (sort { $a cmp $b } keys(%{$pcset}));
|
||||||
foreach my $lib (@{$libs}) {
|
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 $libname = $lib->[0];
|
||||||
my $start = $lib->[1];
|
my $start = $lib->[1];
|
||||||
my $finish = $lib->[2];
|
my $finish = $lib->[2];
|
||||||
@ -3690,14 +3699,18 @@ sub ExtractSymbols {
|
|||||||
|
|
||||||
# Get list of pcs that belong in this library.
|
# Get list of pcs that belong in this library.
|
||||||
my $contained = [];
|
my $contained = [];
|
||||||
foreach my $pc (keys(%{$pcset})) {
|
while (($pc ge $start) && ($pc le $finish)) {
|
||||||
if (!$seen{$pc} && ($pc ge $start) && ($pc le $finish)) {
|
|
||||||
$seen{$pc} = 1;
|
|
||||||
push(@{$contained}, $pc);
|
push(@{$contained}, $pc);
|
||||||
|
$pc = shift(@pcs);
|
||||||
|
if (!defined $pc) {
|
||||||
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# Map to symbols
|
# Map to symbols
|
||||||
MapToSymbols($libname, AddressSub($start, $offset), $contained, $symbols);
|
MapToSymbols($libname, AddressSub($start, $offset), $contained, $symbols);
|
||||||
|
if (!defined $pc) {
|
||||||
|
last;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $symbols;
|
return $symbols;
|
||||||
|
Loading…
Reference in New Issue
Block a user