tools/trace-malloc/merge.pl

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rwxr-xr-x

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 #!/usr/bin/perl
     2 # This Source Code Form is subject to the terms of the Mozilla Public
     3 # License, v. 2.0. If a copy of the MPL was not distributed with this
     4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     7 $argv = $ARGV[0];
     8 open( bloatFile, $argv ) or die "Can't open $argv: $!\n";
     9 while (<bloatFile>) {
    10     if (/name=/) {
    11         ($td,$name,$func,$a,$ntd) = split(/>/, $_);
    12         ($fname, $memSize) = split( /&nbsp;/, $func );
    13         ($trash, $linkName) = split( /"/, $name );
    14         $namesLinks{$fname} = $linkName;
    15         if ($namesSizes{$fname}) {
    16             $namesSizes{$fname} = $namesSizes{$fname} + $memSize;
    17         }
    18         else {
    19             $namesSizes{$fname} = $memSize;
    20         }
    21     }
    22 }
    24 $argv = $ARGV[1];
    25 if ($argv)
    26 {
    27     open( bloatFile, $argv ) or die "Can't open $argv: $!\n";
    28     while (<bloatFile>) {
    29         if (/name=/) {
    30             ($td,$name,$func,$a,$ntd) = split(/>/, $_);
    31             ($fname, $memSize) = split( /&nbsp;/, $func );
    32             $namesSizes{$fname} = $namesSizes{$fname} - $memSize;
    33         }
    34     }
    35 }
    37 sub byvalue { $namesSizes{$b} <=> $namesSizes{$a} }
    40 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">';
    41 print "\n<html><head>\n";
    42 print "<title>Bloat Blame Delta</title>\n";
    43 print '<link rel="stylesheet" type="text/css" href="blame.css">';
    44 print "\n</head>\n<body>\n<table>\n";
    45 print "<thead><tr><td>Memory Allocated</td><td>Function Name</td><td>Link</td></tr></thead>\n";
    47 foreach $key (sort byvalue keys %namesSizes) {
    48     if ($namesSizes{$key}) 
    49     {
    50         print "<tr>\n";
    51         print '  <td>', $namesSizes{$key},"</td>\n"; 
    52         print "  <td> <a href=\"$ARGV[0]#$namesLinks{$key}\">", $key,  "</a></td>\n";
    53         print "</tr>\n"
    54     }
    55 }
    57 print "</table>\n</body></html>";

mercurial