Bug 812070 (part 2) - Speed up fix-linux-stack.pl by adding a cache for previously queried addresses.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 15 Nov 2012 14:38:24 -0800
changeset 118287 e72aeaefb691a9bb1cfb7f6143cdd7918f0a4630
parent 118286 a702c73d82a6e537f8712ecb97500783729d228d
child 118288 4fddb9923ef08fbd94ed76c950f49eb6125ff9ec
push idunknown
push userunknown
push dateunknown
bugs812070
milestone19.0a1
Bug 812070 (part 2) - Speed up fix-linux-stack.pl by adding a cache for previously queried addresses.
tools/rb/fix-linux-stack.pl
--- a/tools/rb/fix-linux-stack.pl
+++ b/tools/rb/fix-linux-stack.pl
@@ -26,16 +26,20 @@ use File::Basename;
 # XXX Hard-coded to gdb defaults (works on Fedora).
 my $global_debug_dir = '/usr/lib/debug';
 
 # We record several things for each file encountered.
 #
 # - {pipe_read}, {pipe_write}: these constitute a bidirectional pipe to an
 #   addr2line process that gives symbol information for a file.
 #
+# - {cache}: this table holds the results of lookups that we've done
+#   previously for (pre-adjustment) addresses, which lets us avoid redundant
+#   calls to addr2line.
+#
 # - {address_adjustment}: addr2line wants offsets relative to the base address
 #   for shared libraries, but it wants addresses including the base address
 #   offset for executables.  This holds the appropriate address adjustment to
 #   add to an offset within file.  See bug 230336.
 #
 my %file_infos;
 
 sub set_address_adjustment($$) {
@@ -223,28 +227,32 @@ while (<>) {
         my $before = $1; # allow preservation of balance trees
         my $badsymbol = $2;
         my $file = $3;
         my $address = hex($4);
         my $after = $5; # allow preservation of counts
 
         if (-f $file) {
             my $file_info = get_file_info($file);
-            $address += $file_info->{address_adjustment};
-
-            my $out = $file_info->{pipe_write};
-            my $in = $file_info->{pipe_read};
-            printf {$out} "0x%X\n", $address;
-            chomp(my $symbol = <$in>);
-            chomp(my $fileandline = <$in>);
-            if (!$symbol || $symbol eq '??') { $symbol = $badsymbol; }
-            if (!$fileandline || $fileandline eq '??:0') {
-                $fileandline = $file;
+            my $result = $file_info->{cache}->{$address};
+            if (not defined $result) {
+                my $address2 = $address + $file_info->{address_adjustment};
+                my $out = $file_info->{pipe_write};
+                my $in = $file_info->{pipe_read};
+                printf {$out} "0x%X\n", $address2;
+                chomp(my $symbol = <$in>);
+                chomp(my $fileandline = <$in>);
+                if (!$symbol || $symbol eq '??') { $symbol = $badsymbol; }
+                if (!$fileandline || $fileandline eq '??:0') {
+                    $fileandline = $file;
+                }
+                $result = "$symbol ($fileandline)";
+                $file_info->{cache}->{$address} = $result;
             }
-            print "$before$symbol ($fileandline)$after\n";
+            print "$before$result$after\n";
         } else {
             print STDERR "Warning: File \"$file\" does not exist.\n";
             print $line;
         }
 
     } else {
         print $line;
     }