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