Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/tools/bloatview/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 18 kB image not shown  
');
}

function writeClassTableRow(d, row, base, modeName) {
 if (modeName) {
  d.writeln('\n');
 } else {
  d.writeln('\n');
  var v = row[1];
  d.writeln('');
 }
 for (var i = 0; i != 2; i++) {
  var c = base + i;
  for (var j = 0; j <= nFiles; j++) {
   v = row[c];
   var style = 'num';
   if (j != nFiles)
    if (v > 0) {
     style = 'pos';
     v = '+'+v;
    } else
     style = 'neg';
   d.writeln('');
   c += 6;
  }
 }
 d.writeln('');
}

function writeClassTable(d) {
 var base = 2 + showMode*2;

 // Make a copy because a sort is destructive.
 var table = classTables.concat();
 table.sort(sortCompare);

 d.writeln('

Impressum bloattable.pl   Sprache: Shell

 
#!/usr/bin/perl -w
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# bloattable [-debug] [-source] [-byte n|-obj n|-ref n] <file1> <file2> ... <filen> > <html-file>
#
# file1, file2, ... filen should be successive BloatView files generated from the same run.
# Summarize them in an HTML table.  Output the HTML to the standard output.
#
# If -debug is set, create a slightly larger html file which is more suitable for debugging this script.
# If -source is set, create an html file that prints the html source as the output
# If -byte n, -obj n, or -ref n is given, make the page default to showing byte, object, or reference statistics,
#    respectively, and sort by the nth column (n is zero-based, so the first column has n==0).
#
# See http://lxr.mozilla.org/mozilla/source/xpcom/doc/MemoryTools.html

use 5.004;
use strict;
use diagnostics;
use File::Basename;
use Getopt::Long;

# The generated HTML is almost entirely generated by a script.  Only the <HTML>, <HEAD>, and <BODY> elements are explicit
# because a <SCRIPT> element cannot officially be a direct descendant of an <HTML> element.
# The script itself is almost all generated by an eval of a large string.  This allows the script to reproduce itself
# when making a new page using document.write's.  Re-sorting the page causes it to regenerate itself in this way.



# Return the file's modification date.
sub fileModDate($) {
 my ($pathName) = @_;
 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) =
  stat $pathName or die "Can't stat '$pathName'";
 return $mtime;
}


sub fileCoreName($) {
 my ($pathName) = @_;
 my $fileName = basename($pathName, "");
 $fileName =~ s/\..*//;
 return $fileName;
}


# Convert a raw string into a single-quoted JavaScript string.
sub singleQuoteString($) {
 local ($_) = @_;
 s/\\/\\\\/g;
 s/'/\\'/g;
 s/\n/\\n/g;
 s/<\//<\\\//g;
 return "'$_'";
}


# Convert a raw string into a double-quoted JavaScript string.
sub doubleQuoteString($) {
 local ($_) = @_;
 s/\\/\\\\/g;
 s/"/\\"/g;
 s/\n/\\n/g;
 s/<\//<\\\//g;
 return "\"$_\"";
}


# Quote special HTML characters in the string.
sub quoteHTML($) {
 local ($_) = @_;
 s/\&/&/g;
 s/</</g;
 s/>/>/g;
 s/ / /g;
 s/\n/<BR>\n/g;
 return $_;
}


# Write the generated page to the standard output.
# The script source code is read from this file past the __END__ marker
# @$scriptData is the JavaScript source for the tables passed to JavaScript.  Each entry is one line of JavaScript.
# @$persistentScriptData is the same as @scriptData, but persists when the page reloads itself.
# If $debug is true, generate the script directly instead of having it eval itself.
# If $source is true, generate a script that displays the page's source instead of the page itself.
sub generate(\@\@$$$$) {
 my ($scriptData, $persistentScriptData, $debug, $source, $showMode, $sortColumn) = @_;

 my @scriptSource = <DATA>;
 chomp @scriptSource;
 print <<'EOS';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<SCRIPT type="text/javascript">
EOS

 foreach (@$scriptData) {print "$_\n";}
 print "\n";

 print "var srcArray = [\n";
 my @quotedScriptSource = map {
  my $line = $_;
  $line =~ s/^\s+//g;
  # $line =~ s/^\/\/SOURCE\s+//g if $source;
  $line =~ s/^\/\/.*//g;
  $line =~ s/\s+$//g;
  $line eq "" ? () : $line
 } @$persistentScriptData, @scriptSource;
 my $lastQuotedLine = pop @quotedScriptSource;
 foreach (@quotedScriptSource) {print doubleQuoteString($_), ",\n";}
 print doubleQuoteString($lastQuotedLine), "];\n\n";

 if ($debug) {
  push @quotedScriptSource, $lastQuotedLine;
  foreach (@quotedScriptSource) {
   s/<\//<\\\//g; # This fails if a regexp ends with a '<'.  Oh well....
   print "$_\n";
  }
  print "\n";
 } else {
  print "eval(srcArray.join(\"\\n\"));\n\n";
 }
 print "showMode = $showMode;\n";
 print "sortColumn = $sortColumn;\n";
 if ($source) {
  print <<'EOS';
function writeQuotedHTML(s) {
 document.write(quoteHTML(s.toString()).replace(/\n/g, '
\n'
));
}

var quotingDocument = {
  write: function () {
  for (var i = 0; i < arguments.length; i++)
   writeQuotedHTML(arguments[i]);
 },
  writeln: function () {
  for (var i = 0; i < arguments.length; i++)
   writeQuotedHTML(arguments[i]);
  document.writeln('
'
);
 }
};
EOS
 } else {
  print "showHead(document);\n";
 }
 print "\n";
 print "\n\n";
 print "\n";
 if ($source) {
  print "

";
  print quoteHTML "-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n";
  print quoteHTML "\n";
  print quoteHTML "\n";
  print "\n";
  print quoteHTML "\n\n";
  print quoteHTML "\n";
  print "\n";
  print quoteHTML "\n";
  print quoteHTML "\n";
  print "

\n"
;
 } else {
  print "\n";
 }
 print "\n";
 print "\n";
}



# Read the bloat file into hash table $h.  The hash table is indexed by class names;
# each entry is a list with the following elements:
# bytesAlloc Total number of bytes allocated
# bytesNet Total number of bytes allocated but not deallocated
# objectsAlloc Total number of objects allocated
# objectsNet Total number of objects allocated but not deallocated
# refsAlloc Total number of references AddRef'd
# refsNet Total number of references AddRef'd but not Released
# Except for TOTAL, all hash table entries refer to mutually exclusive data.
# $sizes is a hash table indexed by class names.  Each entry of that table contains the class's instance size.
sub readBloatFile($\%\%) {
 my ($file, $h, $sizes) = @_;
 local $_; # Needed for 'while (<FILE>)' below.

 my $readSomething = 0;
 open FILE, $file;
 while (<FILE>) {
  if (my ($name, $size, $bytesNet, $objectsAlloc, $objectsNet, $refsAlloc, $refsNet) =
      /^\s*(?:\d+)\s+([\w:]+)\s+(\d+)\s+(-?\d+)\s+(\d+)\s+(-?\d+)\s*\([^()]*\)\s*(\d+)\s+(-?\d+)\s*\([^()]*\)\s*$/) {
   my $bytesAlloc;
   if ($name eq "TOTAL") {
    $size = "undefined";
    $bytesAlloc = "undefined";
   } else {
    $bytesAlloc = $objectsAlloc * $size;
    if ($bytesNet != $objectsNet * $size) {
     print STDERR "In '$file', class $name bytesNet != objectsNet * size: $bytesNet != $objectsNet * $size\n";
    }
   }
   print STDERR "Duplicate entry $name in '$file'\n" if $$h{$name};
   $$h{$name} = [$bytesAlloc, $bytesNet, $objectsAlloc, $objectsNet, $refsAlloc, $refsNet];
   
   my $oldSize = $$sizes{$name};
   print STDERR "Mismatch of sizes of class $name: $oldSize and $size\n" if defined($oldSize) && $size ne $oldSize;
   $$sizes{$name} = $size;
   $readSomething = 1;
  } elsif (/^\s*(?:\d+)\s+([\w:]+)\s/) {
   print STDERR "Unable to parse '$file' line: $_";
  }
 }
 close FILE;
 print STDERR "No data in '$file'\n" unless $readSomething;
 return $h;
}


my %sizes;   # <class-name> => <instance-size>
my %tables;   # <file-name> => <bloat-table>; see readBloatFile for format of <bloat-table>

# Generate the JavaScript source code for the row named $c.  $l can contain the initial entries of the row.
sub genTableRowSource($$) {
 my ($l, $c) = @_;
 my $lastE;
 foreach (@ARGV) {
  my $e = $tables{$_}{$c};
  if (defined($lastE) && !defined($e)) {
   $e = [0,0,0,0,0,0];
   print STDERR "Class $c is defined in an earlier file but not in '$_'\n";
  }
  if (defined $e) {
   if (defined $lastE) {
    for (my $i = 0; $i <= $#$e; $i++) {
     my $n = $$e[$i];
     $l .= ($n eq "undefined" ? "undefined" : $n - $$lastE[$i]) . ",";
    }
    $l .= " ";
   } else {
    $l .= join(",", @$e) . ", ";
   }
   $lastE = $e;
  } else {
   $l .= "0,0,0,0,0,0, ";
  }
 }
 $l .= join(",", @$lastE);
 return "[$l]";
}



my $debug;
my $source;
my $showMode;
my $sortColumn;
my @modeOptions;

GetOptions("debug" => \$debug, "source" => \$source, "byte=i" => \$modeOptions[0], "obj=i" => \$modeOptions[1], "ref=i" => \$modeOptions[2]);
for (my $i = 0; $i != 3; $i++) {
 my $modeOption = $modeOptions[$i];
 if ($modeOption) {
  die "Only one of -byte, -obj, or -ref may be given" if defined $showMode;
  my $nFileColumns = scalar(@ARGV) + 1;
  die "-byte, -obj, or -ref column number out of range" if $modeOption < 0 || $modeOption >= 2 + 2*$nFileColumns;
  $showMode = $i;
  if ($modeOption >= 2) {
   $modeOption -= 2;
   $sortColumn = 2 + $showMode*2;
   if ($modeOption >= $nFileColumns) {
    $sortColumn++;
    $modeOption -= $nFileColumns;
   }
   $sortColumn += $modeOption*6;
  } else {
   $sortColumn = $modeOption;
  }
 }
}
unless (defined $showMode) {
 $showMode = 0;
 $sortColumn = 0;
}

# Read all of the bloat files.
foreach (@ARGV) {
 unless ($tables{$_}) {
  my $f = $_;
  my %table;
  
  readBloatFile $_, %table, %sizes;
  $tables{$_} = \%table;
 }
}
die "No input" unless %sizes;

my @scriptData; # JavaScript source for the tables passed to JavaScript.  Each entry is one line of JavaScript.
my @persistentScriptData; # Same as @scriptData, but persists the page reloads itself.

# Print a list of bloat file names.
push @persistentScriptData, "var nFiles = " . scalar(@ARGV) . ";";
push @persistentScriptData, "var fileTags = [" . join(", ", map {singleQuoteString substr(fileCoreName($_), -10)} @ARGV) . "];";
push @persistentScriptData, "var fileNames = [" . join(", ", map {singleQuoteString $_} @ARGV) . "];";
push @persistentScriptData, "var fileDates = [" . join(", ", map {singleQuoteString localtime fileModDate $_} @ARGV) . "];";

# Print the bloat tables.
push @persistentScriptData, "var totals = " . genTableRowSource('"TOTAL", undefined, '"TOTAL") . ";";
push @scriptData, "var classTables = [";
delete $sizes{"TOTAL"};
my @classes = sort(keys %sizes);
for (my $i = 0; $i <= $#classes; $i++) {
 my $c = $classes[$i];
 push @scriptData, genTableRowSource(doubleQuoteString($c).", ".$sizes{$c}.", ", $c) . ($i == $#classes ? "];" : ",");
}

generate(@scriptData, @persistentScriptData, $debug, $source, $showMode, $sortColumn);
1;


# The source of the eval'd JavaScript follows.
# Comments starting with // that are alone on a line are stripped by the Perl script.
__END__

// showMode: 0=bytes, 1=objects, 2=references
var showMode;
var modeName;
var modeNameUpper;

var sortColumn;

// Sort according to the sortColumn.  Column 0 is sorted alphabetically in ascending order.
// All other columns are sorted numerically in descending order, with column 0 used for a secondary sort.
// Undefined is always listed last.
function sortCompare(x, y) {
 if (sortColumn) {
  var xc = x[sortColumn];
  var yc = y[sortColumn];
  if (xc < yc || xc === undefined && yc !== undefined) return 1;
  if (yc < xc || yc === undefined && xc !== undefined) return -1;
 }
 
 var x0 = x[0];
 var y0 = y[0];
 if (x0 > y0 || x0 === undefined && y0 !== undefined) return 1;
 if (y0 > x0 || y0 === undefined && x0 !== undefined) return -1;
 return 0;
}


// Quote special HTML characters in the string.
function quoteHTML(s) {
 s = s.replace(/&/g, '&');
 // Can't use /</g' as ending the script!
 s = s.replace(/\x3C/g, '<');
 s = s.replace(/>/g, '>');
 s = s.replace(/ /g, ' ');
 return s;
}


function writeFileTable(d) {
 d.writeln('');
 d.writeln('\n\n\n\n');
 for (var i = 0; i < nFiles; i++)
  d.writeln('\n\n\n\n');
 d.writeln('
NameFileDate
'+quoteHTML(fileTags[i])+''+quoteHTML(fileNames[i])+''+quoteHTML(fileDates[i])+'
'
);
}


function writeReloadLink(d, column, s, rowspan) {
 d.write(rowspan == 1 ? '
' : ''>');
 if (column != sortColumn)
  d.write('');
 d.write(s);
 if (column != sortColumn)
  d.write('
');
 d.writeln('
'+modeName+'
'+quoteHTML(row[0])+''+(v === undefined ? '' : v)+''>'+(v === undefined ? '' : v)+'
');

 d.writeln('');
 writeReloadLink(d, 0, 'Class Name', 2);
 writeReloadLink(d, 1, 'Instance
Size'
, 2);
 d.writeln('');
 d.writeln('\n');
 d.writeln('');
 for (var i = 0; i != 2; i++) {
  var c = base + i;
  for (var j = 0; j <= nFiles; j++) {
   writeReloadLink(d, c, j == nFiles ? 'Total' : quoteHTML(fileTags[j]), 1);
   c += 6;
  }
 }
 d.writeln('');

 writeClassTableRow(d, totals, base, 0);
 for (var r = 0; r < table.length; r++)
  writeClassTableRow(d, table[r], base, 0);

 d.writeln('
'>'+modeNameUpper+'s allocated'>'+modeNameUpper+'s allocated but not freed
');
}


var modeNames = ["byte""object""reference"];
var modeNamesUpper = ["Byte""Object""Reference"];
var styleSheet = '';


function showHead(d) {
 modeName = modeNames[showMode];
 modeNameUpper = modeNamesUpper[showMode];
 d.writeln(''</span>+modeNameUpper+<span style='color:blue'>' Bloats');
 d.writeln(styleSheet);
}

function showBody(d) {
 d.writeln('

'+modeNameUpper+' Bloats

'
);
 writeFileTable(d);
 d.write('
');
 for (var i = 0; i != 3; i++)
  if (i != showMode) {
   var newSortColumn = sortColumn;
   if (sortColumn >= 2)
    newSortColumn = sortColumn + (i-showMode)*2;
   d.write('');
  }
 d.writeln(''
);
 d.writeln('

The numbers do not include malloc\'d data such as string contents.</P>');
 d.writeln('

Click on a column heading to sort by that column. Click on a class name to see details for that class.

'
);
 writeClassTable(d);
}


function showRowDetail(rowName) {
 var row;
 var i;

 if (rowName == "TOTAL")
  row = totals;
 else {
  for (i = 0; i < classTables.length; i++)
   if (rowName == classTables[i][0]) {
    row = classTables[i];
    break;
   }
 }
 if (row) {
  var w = window.open("""ClassTableRowDetails");
  var d = w.document;
  d.open();
  d.writeln('http://www.w3.org/TR/REC-html40/loose.dtd">');
  d.writeln('\n\n'</span>+quoteHTML(rowName)+<span style='color:blue'>' bloat details');
  d.writeln(styleSheet);
  d.writeln('\n\n');
  d.writeln('

'+quoteHTML(rowName)+'

'
);
  if (row[1] !== undefined)
   d.writeln('

Each instance has '+row[1]+' bytes.

'
);

  d.writeln('');
  d.writeln('\n\n');
  d.writeln('\n');
  d.writeln('\n');
  for (i = 0; i != 2; i++)
   for (var j = 0; j <= nFiles; j++)
    d.writeln('');
  d.writeln('');

  for (i = 0; i != 3; i++)
   writeClassTableRow(d, row, 2+i*2, modeNamesUpper[i]+'s');

  d.writeln('
'>Allocated'>Allocated but not freed
'+(j == nFiles ? 'Total' : quoteHTML(fileTags[j]))+'
\n\n'
);
  d.close();
 }
 return undefined;
}


function stringSource(s) {
 s = s.replace(/\\/g, '\\\\');
 s = s.replace(/"/g, '\\"');
 s = s.replace(/<\//g, '<\\/');
 return '"'+s+'"';
}

function reloadSelf(n,m) {
 // Need to cache these because globals go away on document.open().
 var sa = srcArray;
 var ss = stringSource;
 var ct = classTables;
 var i;

 document.open();
 // Uncomment this and comment the document.open() line above to see the reloaded page's source.
 //var w = window.open("""NewDoc");
 //var d = w.document;
 //var document = new Object;
 //document.write = function () {
 // for (var i = 0; i < arguments.length; i++) {
 //  var s = arguments[i].toString();
 //  s = s.replace(/&/g, '&');
 //  s = s.replace(/\x3C/g, '<');
 //  s = s.replace(/>/g, '>');
 //  s = s.replace(/ /g, ' ');
 //  d.write(s);
 // }
 //};
 //document.writeln = function () {
 // for (var i = 0; i < arguments.length; i++) {
 //  var s = arguments[i].toString();
 //  s = s.replace(/&/g, '&');
 //  s = s.replace(/\x3C/g, '<');
 //  s = s.replace(/>/g, '>');
 //  s = s.replace(/ /g, ' ');
 //  d.write(s);
 // }
 // d.writeln('
'
);
 //};

 document.writeln('http://www.w3.org/TR/REC-html40/loose.dtd">');
 document.writeln('\n\n\n\n\n\n\n\n');
 document.close();
 return undefined;
}

41%


¤ Dauer der Verarbeitung: 0.99 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.