Each time a garbage collection occurs, SpiderMonkey keeps track of how long each phase of the collection took, along with some related data. There are several ways to get access to this data:
- The environment variable
MOZ_GCTIMERcontrols text dumping of GC stats.
MOZ_GCTIMERmay be none, stderr, stdout, or a filename. If a filename is given, data is appended to that file.
When logging to a file is used in combination with multi-process firefox (e10s) it is necessary to set
security.sandbox.content.level = 0, otherwise the content process will crash.
- The browser preference
- The browser preference
Addons can obtain the complete data in JSON format via an observer. The following adds an observer using the JetPack framework.
The toplevel JSON object contains these fields:
integer(microseconds) - Time at which the GC ended, measured from epoch.
number(milliseconds) - The amount of wall time that this GC consumed. Note: this is the sum of all the slice durations, not end time - start time.
integer- The number of compartments that were collected by the GC.
integer- The number of compartments that were present in the system at the end of the GC.
number(milliseconds) - Longest duration pause during the GC.
string- A string representing the reason that an incremental GC was aborted or forced to finish in a single slice. If the incremental GC completed normally, this will be "none".
array of Objects- A list of objects describing each slice in detail.
Object- A map from phase names to the total time taken by each phase: the sum of each field of the map from the slices.
The last two fields require a bit of elaboration. GC work can be divided into phases, such as marking or sweeping. The division into phases is hierarchical, so a phase can be split into subphases. For example, the sweep phase includes the time for the sweep_atoms, sweep_tables, sweep_compartments phases and so on. The times object gives how much time was spent in each phase of the GC, in milliseconds.
Additionally, an incremental GC is divided into a series of slices (the division into slices is completely separate from the division into phases; neither one is a refinment of the other). A little bit of GC work is done in each slice. In between slices, other browser code is allowed to run. The slices array describes how long each slice took and what work was done during the slice. Each element of the slices array is an object with these fields:
integer- The slice index, starting at 0.
number(milliseconds) - The slice duration.
number(milliseconds) - The time this slice started, relative to the first slice's start time.
string- A string describing the API that initiated this GC slice.
integer- Number of page faults incurred during the processing of this slice.
integer(microseconds) - Time of slice start from epoch.
integer(microseconds) - Time of slice end from epoch.
Object- A map from phase names to the total time taken by that phase during this slice.