Performance:Leak Tools: Difference between revisions

Jump to navigation Jump to search
No edit summary
Line 109: Line 109:
The cycle collector heap dump is useful for figuring out why the cycle collector is keeping an object alive.  These can either be manually or automatically generated.
The cycle collector heap dump is useful for figuring out why the cycle collector is keeping an object alive.  These can either be manually or automatically generated.


To manually generate a CC dump, in any build, enable the Error Console, by going to about:config and setting devtools.errorconsole.enabled to true.  Then open a new window, go to Tools, Web Developer, Error Console.
To manually generate a CC dump, even in a non-debug build, enable the Error Console, by going to about:config and setting devtools.errorconsole.enabled to true.  Then open a new window, go to Tools, Web Developer, Web Console.


Then evaluate this expression:
Then evaluate this expression:
Line 117: Line 117:
     .createInstance(Components.interfaces.nsICycleCollectorListener))
     .createInstance(Components.interfaces.nsICycleCollectorListener))


In version 11 or earlier, you probably want this version, which will run the GC first:
By default, the cycle collector will only log the objects it normally looks at. Sometimes it can be useful to disable the optimizations the cycle collector does in order to get more detailed information. In this case, the method allTraces() can be used:
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  getInterface(Components.interfaces.nsIDOMWindowUtils).
  garbageCollect(Components.classes["@mozilla.org/cycle-collector-logger;1"]
    .createInstance(Components.interfaces.nsICycleCollectorListener))
 
Nightly builds before 2012 defaulted to all traces, newer builds logs the
same edges what cycle collector normally uses.
A new method allTraces() was added so the old behavior can be achieved when
needed:
  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
   getInterface(Components.interfaces.nsIDOMWindowUtils).
   getInterface(Components.interfaces.nsIDOMWindowUtils).
Line 132: Line 123:
     .createInstance(Components.interfaces.nsICycleCollectorListener).allTraces())
     .createInstance(Components.interfaces.nsICycleCollectorListener).allTraces())


This creates a file named cc-edges-NNNN.log and writes a dump of the heap known to the cycle collector, which includes JS objects and also native C++ objects that participate in cycle collection, to the file.
This creates a file named cc-edges-NNNN.log and writes a dump of the heap known to the cycle collector, which includes JS objects and also native C++ objects that participate in cycle collection, to the file.  It will also log the contents of the Javascript heap to a file named gc-edges-NNNN.log.


Since Firefox 18 (night builds after 2012-09-13) one can override the default location of the log files by setting the MOZ_CC_LOG_DIRECTORY environment variable. http://people.mozilla.com/~mleibovic/cc-dump.xpi is an addon for Android Firefox which uses that to save files to /sdcard. The code for this addon is available on [https://github.com/leibovic/skeleton-addon-fxandroid/tree/cc Github].
Since Firefox 18 (night builds after 2012-09-13) one can override the default location of the log files by setting the MOZ_CC_LOG_DIRECTORY environment variable. http://people.mozilla.com/~mleibovic/cc-dump.xpi is an addon for Android Firefox which uses that to save files to /sdcard. The code for this addon is available on [https://github.com/leibovic/skeleton-addon-fxandroid/tree/cc Github].
Line 140: Line 131:
* Older builds created the file in Firefox's current working directory (usually the current working directory where Firefox was started). That meant that on Windows 7 and Vista, you typically had to run Firefox as Administrator to create the file.
* Older builds created the file in Firefox's current working directory (usually the current working directory where Firefox was started). That meant that on Windows 7 and Vista, you typically had to run Firefox as Administrator to create the file.


To automatically generate a cycle collector dump, set gAlwaysLogCCGraphs to true in xpcom/base/nsCycleCollector.cpp. This will make every cycle collection produce a dump. This is primarily useful for debugging shutdown leaks.
To log every cycle collection, set the XPCOM_CC_LOG_ALL environment variable. To log only shutdown collections, set XPCOM_CC_LOG_SHUTDOWN. To make any shutdown CCs AllTraces() at shutdown, set XPCOM_CC_ALL_TRACES_AT_SHUTDOWN. The latter two are useful for debugging shutdown leaks.


To analyze a cycle collector dump, you need the scripts from [https://github.com/amccreight/heapgraph/tree/master/cc Github].  The relevant scripts are find_roots.py and parse_cc_graph.py (which is called by find_roots).  Calling find_roots on a CC file with a specific object or kind of object will produce paths from rooting objects to the specified objects.  Most big leaks include an nsGlobalWindow, so that's a good class to try if you don't have any better idea.
To analyze a cycle collector dump, you need the scripts from [https://github.com/amccreight/heapgraph/tree/master/cc Github].  The relevant scripts are find_roots.py and parse_cc_graph.py (which is called by find_roots).  Calling find_roots on a CC file with a specific object or kind of object will produce paths from rooting objects to the specified objects.  Most big leaks include an nsGlobalWindow, so that's a good class to try if you don't have any better idea.
Line 149: Line 140:
* Simple, ugly, yet rather powerful [https://bugzilla.mozilla.org/show_bug.cgi?id=726346 about:cc]
* Simple, ugly, yet rather powerful [https://bugzilla.mozilla.org/show_bug.cgi?id=726346 about:cc]
* Prettier but a bit slower [https://addons.mozilla.org/en-US/firefox/addon/cycle-collector-analyzer/?src=ss about:ccdump]
* Prettier but a bit slower [https://addons.mozilla.org/en-US/firefox/addon/cycle-collector-analyzer/?src=ss about:ccdump]


=== Leak tools for medium-size object graphs ===
=== Leak tools for medium-size object graphs ===
Confirmed users
626

edits

Navigation menu