Performance:Leak Tools:DiffBloatDump

From MozillaWiki
Jump to: navigation, search

This is the basic "monkey see, monkey do" steps for generating trace-malloc diffbloatdump output. You'll need to compile a specially-instrumented build, capture the trace-malloc logs, and then process the logs. Then you'll have output showing what memory was allocated-but-not-freed between the two log capture points.

Creating an instrumented build

  1. Check out a Mozilla tree as usual
  2. Check out mozilla/tools/
  3. Edit .mozconfig to enable trace-malloc. I also removed my usual --enable-debug, lest debugging code be causing leaks. EG:
ac_add_options --enable-trace-malloc
ac_add_options --disable-optimize --enable-debugger-info-modules

Now build as usual.

Capturing a log

First time:

  1. Create a clean Firefox profile
  2. Install RamBack extension
  3. Disable SafeBrowsing prefs (Preferences -> Security -> "Tell me if..."), since the nsURLClassifier downloads in the background.
  4. Create a HTML file with buttons to trigger the trace-malloc logging:
<script type="text/javascript">
function dumpLog() {
    var filename = window.prompt("Filename to log: ");
    if (filename)
        TraceMallocDumpAllocations(filename);
}
function startLog() {
    TraceMallocEnable();
}
</script>
<button onclick="startLog();">Start Logging</button>
<button onclick="dumpLog();">Dump to Logfile...</button>

The RamBack extension is used to send memory-pressure notifications, which trigger GC and cycle collection. This helps to force things to be deallocated before a taking a sample.

For a session:

  1. Enter objdir.
  2. Start Firefox
  3. Get it to whatever initial state you want to use as a baseline, and with the above HTML page in a tab.
  4. Click Tools->Clear Caches (RamBack extension)
  5. Click "Start Logging" button (from HTML above)
  6. Click "Dump to Logfile" button (from HTML above), enter a filename
  7. ...do some stuff to cause a leak...
  8. Click Tools->Clear Caches (RamBack extension)
  9. Click "Dump to Logfile" button (from HTML above), enter a filename

Processing the log

Assuming the two logs created above are log1 and log2...

  1. Enter objdir.
  2. Run ../tools/trace-malloc/diffbloatdump.pl --use-address --depth=50 log1 log2 > tmpfile
  3. Run ../tools/rb/fix-linux-stack.pl tmpfile > logoutput (or fix-macosx-stack.pl)