2013-01-14 16:26:47 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2008-03-05 17:28:25 -08:00
|
|
|
|
|
|
|
#include "nsISupports.idl"
|
|
|
|
|
2012-12-11 10:13:29 -08:00
|
|
|
interface nsICancelableRunnable;
|
2013-10-22 14:53:26 -07:00
|
|
|
interface nsIDOMWindow;
|
|
|
|
interface nsIRunnable;
|
|
|
|
interface nsISimpleEnumerator;
|
2008-03-05 17:28:25 -08:00
|
|
|
|
2011-11-27 19:03:14 -08:00
|
|
|
/*
|
2013-10-22 14:53:26 -07:00
|
|
|
* Memory reporters measure Firefox's memory usage. They are primarily used to
|
2011-11-27 19:03:14 -08:00
|
|
|
* generate the about:memory page. You should read
|
|
|
|
* https://wiki.mozilla.org/Memory_Reporting before writing a memory
|
|
|
|
* reporter.
|
|
|
|
*/
|
|
|
|
|
2013-08-27 16:24:51 -07:00
|
|
|
[scriptable, function, uuid(3a61be3b-b93b-461a-a4f8-388214f558b1)]
|
|
|
|
interface nsIMemoryReporterCallback : nsISupports
|
2008-03-05 17:28:25 -08:00
|
|
|
{
|
|
|
|
/*
|
2013-08-27 16:24:51 -07:00
|
|
|
* The arguments to the callback are as follows.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* |process| The name of the process containing this reporter. Each
|
|
|
|
* reporter initially has "" in this field, indicating that it applies to the
|
|
|
|
* current process. (This is true even for reporters in a child process.)
|
|
|
|
* When a reporter from a child process is copied into the main process, the
|
|
|
|
* copy has its 'process' field set appropriately.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* |path| The path that this memory usage should be reported under. Paths
|
|
|
|
* are '/'-delimited, eg. "a/b/c".
|
2012-06-11 20:29:12 -07:00
|
|
|
*
|
|
|
|
* Each reporter can be viewed as representing a leaf node in a tree.
|
|
|
|
* Internal nodes of the tree don't have reporters. So, for example, the
|
|
|
|
* reporters "explicit/a/b", "explicit/a/c", "explicit/d/e", and
|
|
|
|
* "explicit/d/f" define this tree:
|
|
|
|
*
|
|
|
|
* explicit
|
|
|
|
* |--a
|
|
|
|
* | |--b [*]
|
|
|
|
* | \--c [*]
|
|
|
|
* \--d
|
|
|
|
* |--e [*]
|
|
|
|
* \--f [*]
|
|
|
|
*
|
|
|
|
* Nodes marked with a [*] have a reporter. Notice that the internal
|
|
|
|
* nodes are implicitly defined by the paths.
|
|
|
|
*
|
|
|
|
* Nodes within a tree should not overlap measurements, otherwise the
|
|
|
|
* parent node measurements will be double-counted. So in the example
|
|
|
|
* above, |b| should not count any allocations counted by |c|, and vice
|
|
|
|
* versa.
|
|
|
|
*
|
|
|
|
* All nodes within each tree must have the same units.
|
|
|
|
*
|
|
|
|
* If you want to include a '/' not as a path separator, e.g. because the
|
|
|
|
* path contains a URL, you need to convert each '/' in the URL to a '\'.
|
|
|
|
* Consumers of the path will undo this change. Any other '\' character
|
|
|
|
* in a path will also be changed. This is clumsy but hasn't caused any
|
|
|
|
* problems so far.
|
|
|
|
*
|
|
|
|
* The paths of all reporters form a set of trees. Trees can be
|
|
|
|
* "degenerate", i.e. contain a single entry with no '/'.
|
2013-08-27 16:24:51 -07:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* |kind| There are three kinds of memory reporters.
|
2012-01-07 02:45:35 -08:00
|
|
|
*
|
2012-06-11 20:29:12 -07:00
|
|
|
* - HEAP: reporters measuring memory allocated by the heap allocator,
|
|
|
|
* e.g. by calling malloc, calloc, realloc, memalign, operator new, or
|
|
|
|
* operator new[]. Reporters in this category must have units
|
|
|
|
* UNITS_BYTES.
|
2011-06-16 11:34:09 -07:00
|
|
|
*
|
2012-06-11 20:29:12 -07:00
|
|
|
* - NONHEAP: reporters measuring memory which the program explicitly
|
|
|
|
* allocated, but does not live on the heap. Such memory is commonly
|
|
|
|
* allocated by calling one of the OS's memory-mapping functions (e.g.
|
|
|
|
* mmap, VirtualAlloc, or vm_allocate). Reporters in this category
|
|
|
|
* must have units UNITS_BYTES.
|
2012-04-02 19:28:05 -07:00
|
|
|
*
|
2012-06-11 20:29:12 -07:00
|
|
|
* - OTHER: reporters which don't fit into either of these categories.
|
|
|
|
* They can have any units.
|
2012-06-25 17:08:59 -07:00
|
|
|
*
|
|
|
|
* The kind only matters for reporters in the "explicit" tree;
|
|
|
|
* aboutMemory.js uses it to calculate "heap-unclassified".
|
2013-08-27 16:24:51 -07:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* |units| The units on the reporter's amount. One of the following.
|
2011-06-16 11:34:09 -07:00
|
|
|
*
|
|
|
|
* - BYTES: The amount contains a number of bytes.
|
|
|
|
*
|
2011-07-26 06:19:55 -07:00
|
|
|
* - COUNT: The amount is an instantaneous count of things currently in
|
|
|
|
* existence. For instance, the number of tabs currently open would have
|
|
|
|
* units COUNT.
|
2011-07-20 21:08:24 -07:00
|
|
|
*
|
2011-07-24 20:56:50 -07:00
|
|
|
* - COUNT_CUMULATIVE: The amount contains the number of times some event
|
|
|
|
* has occurred since the application started up. For instance, the
|
|
|
|
* number of times the user has opened a new tab would have units
|
|
|
|
* COUNT_CUMULATIVE.
|
|
|
|
*
|
|
|
|
* The amount returned by a reporter with units COUNT_CUMULATIVE must
|
|
|
|
* never decrease over the lifetime of the application.
|
|
|
|
*
|
2011-07-20 21:08:24 -07:00
|
|
|
* - PERCENTAGE: The amount contains a fraction that should be expressed as
|
|
|
|
* a percentage. NOTE! The |amount| field should be given a value 100x
|
|
|
|
* the actual percentage; this number will be divided by 100 when shown.
|
|
|
|
* This allows a fractional percentage to be shown even though |amount| is
|
|
|
|
* an integer. E.g. if the actual percentage is 12.34%, |amount| should
|
|
|
|
* be 1234.
|
2012-04-30 11:27:15 -07:00
|
|
|
*
|
|
|
|
* Values greater than 100% are allowed.
|
2013-08-27 16:24:51 -07:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* |amount| The numeric value reported by this memory reporter. Accesses
|
|
|
|
* can fail if something goes wrong when getting the amount.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* |description| A human-readable description of this memory usage report.
|
2008-03-05 17:28:25 -08:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
void callback(in ACString process, in AUTF8String path, in int32_t kind,
|
|
|
|
in int32_t units, in int64_t amount,
|
2013-10-24 21:39:16 -07:00
|
|
|
in AUTF8String description, in nsISupports data);
|
2011-06-29 16:39:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2013-08-27 16:24:51 -07:00
|
|
|
* An nsIMemoryReporter reports one or more memory measurements via a
|
|
|
|
* callback function which is called once for each measurement.
|
|
|
|
*
|
|
|
|
* An nsIMemoryReporter that reports a single measurement is sometimes called a
|
|
|
|
* "uni-reporter". One that reports multiple measurements is sometimes called
|
|
|
|
* a "multi-reporter".
|
2011-06-29 16:39:32 -07:00
|
|
|
*
|
2013-08-27 16:24:51 -07:00
|
|
|
* aboutMemory.js is the most important consumer of memory reports. It
|
|
|
|
* places the following constraints on reports.
|
|
|
|
*
|
|
|
|
* - There must be an "explicit" tree. It represents non-overlapping
|
|
|
|
* regions of memory that have been explicitly allocated with an
|
|
|
|
* OS-level allocation (e.g. mmap/VirtualAlloc/vm_allocate) or a
|
|
|
|
* heap-level allocation (e.g. malloc/calloc/operator new). Reporters
|
2013-12-03 20:10:59 -08:00
|
|
|
* in this tree must have kind HEAP or NONHEAP, units BYTES.
|
2013-08-27 16:24:51 -07:00
|
|
|
*
|
2013-12-03 20:10:59 -08:00
|
|
|
* - All other reports are unconstrained.
|
|
|
|
*
|
|
|
|
* It is preferred, but not required, that report descriptions use complete
|
|
|
|
* sentences (i.e. start with a capital letter and end with a period, or
|
|
|
|
* similar).
|
2011-06-29 16:39:32 -07:00
|
|
|
*/
|
2013-11-26 18:38:50 -08:00
|
|
|
[scriptable, uuid(0884cd0f-5829-4381-979b-0f53904030ed)]
|
2013-08-27 16:24:51 -07:00
|
|
|
interface nsIMemoryReporter : nsISupports
|
2011-06-29 16:39:32 -07:00
|
|
|
{
|
2012-02-06 17:02:59 -08:00
|
|
|
/*
|
2013-08-27 16:24:51 -07:00
|
|
|
* Run the reporter.
|
2012-02-06 17:02:59 -08:00
|
|
|
*/
|
2013-08-27 16:24:51 -07:00
|
|
|
void collectReports(in nsIMemoryReporterCallback callback,
|
2013-10-24 21:39:16 -07:00
|
|
|
in nsISupports data);
|
2013-08-27 16:24:51 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Kinds. See the |kind| comment in nsIMemoryReporterCallback.
|
|
|
|
*/
|
|
|
|
const int32_t KIND_NONHEAP = 0;
|
|
|
|
const int32_t KIND_HEAP = 1;
|
|
|
|
const int32_t KIND_OTHER = 2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Units. See the |units| comment in nsIMemoryReporterCallback.
|
|
|
|
*/
|
|
|
|
const int32_t UNITS_BYTES = 0;
|
|
|
|
const int32_t UNITS_COUNT = 1;
|
|
|
|
const int32_t UNITS_COUNT_CUMULATIVE = 2;
|
|
|
|
const int32_t UNITS_PERCENTAGE = 3;
|
2011-06-29 16:39:32 -07:00
|
|
|
};
|
|
|
|
|
2013-10-22 22:26:24 -07:00
|
|
|
[scriptable, function, uuid(548b3909-c04d-4ca6-8466-b8bee3837457)]
|
|
|
|
interface nsIFinishReportingCallback : nsISupports
|
|
|
|
{
|
|
|
|
void callback(in nsISupports data);
|
|
|
|
};
|
|
|
|
|
2013-12-01 16:29:37 -08:00
|
|
|
[scriptable, builtinclass, uuid(2b61d644-1520-420a-8f52-d06e615c1ff6)]
|
2008-03-05 17:28:25 -08:00
|
|
|
interface nsIMemoryReporterManager : nsISupports
|
|
|
|
{
|
|
|
|
/*
|
2013-10-22 22:26:24 -07:00
|
|
|
* Initialize.
|
2008-03-05 17:28:25 -08:00
|
|
|
*/
|
2013-10-22 22:26:24 -07:00
|
|
|
void init();
|
2008-03-05 17:28:25 -08:00
|
|
|
|
2011-06-29 16:39:32 -07:00
|
|
|
/*
|
2013-12-01 16:29:37 -08:00
|
|
|
* Register the given nsIMemoryReporter. The Manager service will hold a
|
|
|
|
* strong reference to the given reporter, and will be responsible for freeing
|
|
|
|
* the reporter at shutdown.
|
2008-03-05 17:28:25 -08:00
|
|
|
*/
|
2013-11-06 21:35:30 -08:00
|
|
|
void registerStrongReporter(in nsIMemoryReporter reporter);
|
2008-03-05 17:28:25 -08:00
|
|
|
|
|
|
|
/*
|
2013-11-06 21:35:30 -08:00
|
|
|
* Like registerReporter, but the Manager service will hold a weak reference
|
|
|
|
* to the given reporter. The reporter should be unregistered before
|
|
|
|
* shutdown.
|
2008-03-05 17:28:25 -08:00
|
|
|
*/
|
2013-11-06 21:35:30 -08:00
|
|
|
void registerWeakReporter(in nsIMemoryReporter reporter);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unregister the given memory reporter, which must have been registered with
|
|
|
|
* registerWeakReporter().
|
|
|
|
*/
|
|
|
|
void unregisterWeakReporter(in nsIMemoryReporter reporter);
|
2009-10-03 00:21:34 -07:00
|
|
|
|
2013-09-19 15:52:28 -07:00
|
|
|
/*
|
2013-04-01 21:39:44 -07:00
|
|
|
* These functions should only be used for testing purposes.
|
|
|
|
*/
|
2013-11-06 21:35:30 -08:00
|
|
|
void blockRegistrationAndHideExistingReporters();
|
|
|
|
void unblockRegistrationAndRestoreOriginalReporters();
|
|
|
|
void registerStrongReporterEvenIfBlocked(in nsIMemoryReporter aReporter);
|
2013-04-01 21:39:44 -07:00
|
|
|
|
2013-10-22 22:26:24 -07:00
|
|
|
/*
|
|
|
|
* Get memory reports for the current process and all child processes.
|
|
|
|
* |handleReport| is called for each report, and |finishReporting| is called
|
|
|
|
* once all reports have been handled.
|
|
|
|
*
|
|
|
|
* |finishReporting| is called even if, for example, some child processes
|
|
|
|
* fail to report back. However, calls to this method will silently and
|
|
|
|
* immediately abort -- and |finishReporting| will not be called -- if a
|
|
|
|
* previous getReports() call is still in flight, i.e. if it has not yet
|
|
|
|
* finished invoking |finishReporting|. The silent abort is because the
|
|
|
|
* in-flight request will finish soon, and the caller would very likely just
|
|
|
|
* catch and ignore any error anyway.
|
|
|
|
*/
|
|
|
|
void getReports(in nsIMemoryReporterCallback handleReport,
|
|
|
|
in nsISupports handleReportData,
|
|
|
|
in nsIFinishReportingCallback finishReporting,
|
|
|
|
in nsISupports finishReportingData);
|
2012-01-17 20:23:55 -08:00
|
|
|
|
2013-12-01 16:29:37 -08:00
|
|
|
/*
|
|
|
|
* Get memory reports in the current process only. |handleReport| is called
|
|
|
|
* for each report.
|
|
|
|
*/
|
|
|
|
void getReportsForThisProcess(in nsIMemoryReporterCallback handleReport,
|
|
|
|
in nsISupports handleReportData);
|
|
|
|
|
2013-09-24 20:31:00 -07:00
|
|
|
/*
|
2013-09-19 15:52:28 -07:00
|
|
|
* The memory reporter manager, for the most part, treats reporters
|
|
|
|
* registered with it as a black box. However, there are some
|
|
|
|
* "distinguished" amounts (as could be reported by a memory reporter) that
|
|
|
|
* the manager provides as attributes, because they are sufficiently
|
2013-09-19 15:52:30 -07:00
|
|
|
* interesting that we want external code (e.g. telemetry) to be able to rely
|
|
|
|
* on them.
|
2013-09-19 15:52:28 -07:00
|
|
|
*
|
2013-12-01 16:29:37 -08:00
|
|
|
* Note that these are not reporters and so getReports() and
|
|
|
|
* getReportsForThisProcess() do not look at them. However, distinguished
|
|
|
|
* amounts can be embedded in a reporter.
|
2013-09-19 15:52:28 -07:00
|
|
|
*
|
2013-09-19 15:52:30 -07:00
|
|
|
* Access to these attributes can fail. In particular, some of them are not
|
|
|
|
* available on all platforms.
|
|
|
|
*
|
|
|
|
* If you add a new distinguished amount, please update
|
|
|
|
* toolkit/components/aboutmemory/tests/test_memoryReporters.xul.
|
|
|
|
*
|
|
|
|
* |explicit| (UNITS_BYTES) The total size of explicit memory allocations,
|
2013-09-19 15:52:28 -07:00
|
|
|
* both at the OS-level (eg. via mmap, VirtualAlloc) and at the heap level
|
|
|
|
* (eg. via malloc, calloc, operator new). It covers all heap allocations,
|
|
|
|
* but will miss any OS-level ones not covered by memory reporters.
|
|
|
|
*
|
2013-09-19 15:52:30 -07:00
|
|
|
* |vsize| (UNITS_BYTES) The virtual size, i.e. the amount of address space
|
|
|
|
* taken up.
|
|
|
|
*
|
2013-11-18 22:24:12 -08:00
|
|
|
* |vsizeMaxContiguous| (UNITS_BYTES) The size of the largest contiguous
|
|
|
|
* block of virtual memory.
|
|
|
|
*
|
2013-09-19 15:52:30 -07:00
|
|
|
* |resident| (UNITS_BYTES) The resident size (a.k.a. RSS or physical memory
|
2013-09-19 15:52:28 -07:00
|
|
|
* used).
|
|
|
|
*
|
2013-09-19 15:52:30 -07:00
|
|
|
* |residentFast| (UNITS_BYTES) This is like |resident|, but on Mac OS
|
2013-09-19 15:52:28 -07:00
|
|
|
* |resident| can purge pages, which is slow. It also affects the result of
|
|
|
|
* |residentFast|, and so |resident| and |residentFast| should not be used
|
2013-09-19 15:52:30 -07:00
|
|
|
* together.
|
|
|
|
*
|
|
|
|
* |heapAllocated| (UNITS_BYTES) Memory mapped by the heap allocator.
|
|
|
|
*
|
|
|
|
* |heapOverheadRatio| (UNITS_PERCENTAGE) In the heap allocator, this is the
|
|
|
|
* ratio of committed, unused bytes to allocated bytes. Like all
|
|
|
|
* UNITS_PERCENTAGE measurements, its amount is multiplied by 100x so it can
|
|
|
|
* be represented by an int64_t.
|
|
|
|
*
|
|
|
|
* |JSMainRuntimeGCHeap| (UNITS_BYTES) Size of the main JS runtime's GC
|
|
|
|
* heap.
|
2013-09-19 15:52:28 -07:00
|
|
|
*
|
2013-09-19 15:52:30 -07:00
|
|
|
* |JSMainRuntimeTemporaryPeak| (UNITS_BYTES) Peak size of the transient
|
|
|
|
* storage in the main JSRuntime.
|
|
|
|
*
|
|
|
|
* |JSMainRuntimeCompartments{System,User}| (UNITS_COUNT) The number of
|
2013-09-19 15:52:28 -07:00
|
|
|
* {system,user} compartments in the main JS runtime.
|
2013-09-19 15:52:30 -07:00
|
|
|
*
|
|
|
|
* |imagesContentUsedUncompressed| (UNITS_BYTES) Memory used for decoded
|
|
|
|
* images in content.
|
|
|
|
*
|
|
|
|
* |storageSQLite| (UNITS_BYTES) Memory used by SQLite.
|
|
|
|
*
|
|
|
|
* |lowMemoryEvents{Virtual,Physical}| (UNITS_COUNT_CUMULATIVE) The number
|
|
|
|
* of low-{virtual,physical}-memory events that have occurred since the
|
|
|
|
* process started.
|
|
|
|
*
|
|
|
|
* |ghostWindows| (UNITS_COUNT) The number of ghost windows.
|
|
|
|
*
|
|
|
|
* |pageFaultsHard| (UNITS_COUNT_CUMULATIVE) The number of hard (a.k.a.
|
|
|
|
* major) page faults that have occurred since the process started.
|
2013-09-24 20:31:00 -07:00
|
|
|
*/
|
|
|
|
readonly attribute int64_t explicit;
|
2013-09-19 15:52:30 -07:00
|
|
|
readonly attribute int64_t vsize;
|
2013-11-18 22:24:12 -08:00
|
|
|
readonly attribute int64_t vsizeMaxContiguous;
|
2013-09-19 15:52:28 -07:00
|
|
|
readonly attribute int64_t resident;
|
|
|
|
readonly attribute int64_t residentFast;
|
2013-09-19 15:52:30 -07:00
|
|
|
|
|
|
|
readonly attribute int64_t heapAllocated;
|
|
|
|
readonly attribute int64_t heapOverheadRatio;
|
|
|
|
|
|
|
|
readonly attribute int64_t JSMainRuntimeGCHeap;
|
|
|
|
readonly attribute int64_t JSMainRuntimeTemporaryPeak;
|
2013-09-19 15:52:28 -07:00
|
|
|
readonly attribute int64_t JSMainRuntimeCompartmentsSystem;
|
|
|
|
readonly attribute int64_t JSMainRuntimeCompartmentsUser;
|
2013-09-19 15:52:30 -07:00
|
|
|
|
2013-09-19 15:52:30 -07:00
|
|
|
readonly attribute int64_t imagesContentUsedUncompressed;
|
|
|
|
|
|
|
|
readonly attribute int64_t storageSQLite;
|
|
|
|
|
|
|
|
readonly attribute int64_t lowMemoryEventsVirtual;
|
|
|
|
readonly attribute int64_t lowMemoryEventsPhysical;
|
|
|
|
|
|
|
|
readonly attribute int64_t ghostWindows;
|
|
|
|
|
|
|
|
readonly attribute int64_t pageFaultsHard;
|
|
|
|
|
2012-01-17 20:23:55 -08:00
|
|
|
/*
|
|
|
|
* This attribute indicates if moz_malloc_usable_size() works.
|
|
|
|
*/
|
2012-10-15 19:12:14 -07:00
|
|
|
[infallible] readonly attribute boolean hasMozMallocUsableSize;
|
2012-08-27 18:14:14 -07:00
|
|
|
|
|
|
|
/*
|
2012-10-02 18:19:11 -07:00
|
|
|
* Run a series of GC/CC's in an attempt to minimize the application's memory
|
2012-10-22 12:40:19 -07:00
|
|
|
* usage. When we're finished, we invoke the given runnable if it's not
|
2012-12-11 10:13:29 -08:00
|
|
|
* null. Returns a reference to the runnable used for carrying out the task.
|
2012-10-02 18:19:11 -07:00
|
|
|
*/
|
2012-12-11 10:13:29 -08:00
|
|
|
nsICancelableRunnable minimizeMemoryUsage(in nsIRunnable callback);
|
2013-10-22 14:53:26 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Measure the memory that is known to be owned by this tab, split up into
|
|
|
|
* several broad categories. Note that this will be an underestimate of the
|
|
|
|
* true number, due to imperfect memory reporter coverage (corresponding to
|
|
|
|
* about:memory's "heap-unclassified"), and due to some memory shared between
|
|
|
|
* tabs not being counted.
|
|
|
|
*
|
|
|
|
* The time taken for the measurement (split into JS and non-JS parts) is
|
|
|
|
* also returned.
|
|
|
|
*/
|
|
|
|
void sizeOfTab(in nsIDOMWindow window,
|
|
|
|
out int64_t jsObjectsSize, out int64_t jsStringsSize,
|
|
|
|
out int64_t jsOtherSize, out int64_t domSize,
|
|
|
|
out int64_t styleSize, out int64_t otherSize,
|
|
|
|
out int64_t totalSize,
|
|
|
|
out double jsMilliseconds, out double nonJSMilliseconds);
|
2008-03-05 17:28:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
%{C++
|
|
|
|
|
2013-10-22 14:53:26 -07:00
|
|
|
#include "js/TypeDecls.h"
|
2013-01-14 16:26:47 -08:00
|
|
|
#include "nsStringGlue.h"
|
2013-10-22 22:26:24 -07:00
|
|
|
#include "nsTArray.h"
|
2013-01-14 16:26:47 -08:00
|
|
|
|
2013-10-22 14:53:26 -07:00
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
2013-10-22 22:26:24 -07:00
|
|
|
// nsIHandleReportCallback is a better name, but keep nsIMemoryReporterCallback
|
|
|
|
// around for backwards compatibility.
|
|
|
|
typedef nsIMemoryReporterCallback nsIHandleReportCallback;
|
|
|
|
|
2013-11-06 21:35:30 -08:00
|
|
|
namespace mozilla {
|
2011-12-08 19:09:36 -08:00
|
|
|
|
2013-11-06 21:35:30 -08:00
|
|
|
// Register a memory reporter. The manager service will hold a strong
|
|
|
|
// reference to this reporter.
|
|
|
|
XPCOM_API(nsresult) RegisterStrongMemoryReporter(nsIMemoryReporter* aReporter);
|
2013-11-06 21:35:30 -08:00
|
|
|
|
2013-11-06 21:35:30 -08:00
|
|
|
// Register a memory reporter. The manager service will hold a weak reference
|
|
|
|
// to this reporter.
|
|
|
|
XPCOM_API(nsresult) RegisterWeakMemoryReporter(nsIMemoryReporter* aReporter);
|
|
|
|
|
|
|
|
// Unregister a weak memory reporter.
|
|
|
|
XPCOM_API(nsresult) UnregisterWeakMemoryReporter(nsIMemoryReporter* aReporter);
|
2013-09-19 15:52:28 -07:00
|
|
|
|
|
|
|
// The memory reporter manager provides access to several distinguished
|
|
|
|
// amounts via attributes. Some of these amounts are provided by Gecko
|
|
|
|
// components that cannot be accessed directly from XPCOM code. So we provide
|
|
|
|
// the following functions for those components to be registered with the
|
|
|
|
// manager.
|
|
|
|
|
|
|
|
typedef int64_t (*InfallibleAmountFn)();
|
|
|
|
typedef nsresult (*FallibleAmountFn)(int64_t* aAmount);
|
|
|
|
|
2013-09-19 15:52:30 -07:00
|
|
|
#define DECL_REGISTER_DISTINGUISHED_AMOUNT(kind, name) \
|
2013-09-19 15:52:28 -07:00
|
|
|
nsresult Register##name##DistinguishedAmount(kind##AmountFn aAmountFn);
|
2013-09-19 15:52:30 -07:00
|
|
|
#define DECL_UNREGISTER_DISTINGUISHED_AMOUNT(name) \
|
|
|
|
nsresult Unregister##name##DistinguishedAmount();
|
|
|
|
|
|
|
|
DECL_REGISTER_DISTINGUISHED_AMOUNT(Infallible, JSMainRuntimeGCHeap)
|
|
|
|
DECL_REGISTER_DISTINGUISHED_AMOUNT(Infallible, JSMainRuntimeTemporaryPeak)
|
|
|
|
DECL_REGISTER_DISTINGUISHED_AMOUNT(Infallible, JSMainRuntimeCompartmentsSystem)
|
|
|
|
DECL_REGISTER_DISTINGUISHED_AMOUNT(Infallible, JSMainRuntimeCompartmentsUser)
|
|
|
|
|
|
|
|
DECL_REGISTER_DISTINGUISHED_AMOUNT(Infallible, ImagesContentUsedUncompressed)
|
|
|
|
|
|
|
|
DECL_REGISTER_DISTINGUISHED_AMOUNT(Infallible, StorageSQLite)
|
|
|
|
DECL_UNREGISTER_DISTINGUISHED_AMOUNT(StorageSQLite)
|
|
|
|
|
|
|
|
DECL_REGISTER_DISTINGUISHED_AMOUNT(Infallible, LowMemoryEventsVirtual)
|
|
|
|
DECL_REGISTER_DISTINGUISHED_AMOUNT(Infallible, LowMemoryEventsPhysical)
|
2013-09-19 15:52:28 -07:00
|
|
|
|
2013-09-19 15:52:30 -07:00
|
|
|
DECL_REGISTER_DISTINGUISHED_AMOUNT(Infallible, GhostWindows)
|
2013-09-19 15:52:28 -07:00
|
|
|
|
2013-09-19 15:52:30 -07:00
|
|
|
#undef DECL_REGISTER_DISTINGUISHED_AMOUNT
|
|
|
|
#undef DECL_UNREGISTER_DISTINGUISHED_AMOUNT
|
2013-09-19 15:52:28 -07:00
|
|
|
|
2013-10-22 14:53:26 -07:00
|
|
|
// Likewise for per-tab measurement.
|
|
|
|
|
|
|
|
typedef nsresult (*JSSizeOfTabFn)(JSObject* aObj,
|
|
|
|
size_t* aJsObjectsSize,
|
|
|
|
size_t* aJsStringSize,
|
|
|
|
size_t* aJsPrivateSize,
|
|
|
|
size_t* aJsOtherSize);
|
|
|
|
typedef nsresult (*NonJSSizeOfTabFn)(nsPIDOMWindow* aWindow,
|
|
|
|
size_t* aDomSize,
|
|
|
|
size_t* aStyleSize,
|
|
|
|
size_t* aOtherSize);
|
|
|
|
|
|
|
|
nsresult RegisterJSSizeOfTab(JSSizeOfTabFn aSizeOfTabFn);
|
|
|
|
nsresult RegisterNonJSSizeOfTab(NonJSSizeOfTabFn aSizeOfTabFn);
|
|
|
|
|
2013-09-19 15:52:28 -07:00
|
|
|
}
|
|
|
|
|
2012-12-20 23:03:50 -08:00
|
|
|
#if defined(MOZ_DMD)
|
2012-12-10 16:05:07 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dmd {
|
2013-10-22 22:26:24 -07:00
|
|
|
// This runs all the memory reporters in the current process but does nothing
|
|
|
|
// with the results; i.e. it does the minimal amount of work possible for DMD
|
|
|
|
// to do its thing. It does nothing with child processes.
|
2013-12-01 16:29:37 -08:00
|
|
|
void RunReportersForThisProcess();
|
2012-12-10 16:05:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(MOZ_MEMORY)
|
|
|
|
#error "MOZ_DMD requires MOZ_MEMORY"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "DMD.h"
|
|
|
|
|
2012-12-23 16:59:51 -08:00
|
|
|
#define MOZ_REPORT(ptr) mozilla::dmd::Report(ptr)
|
|
|
|
#define MOZ_REPORT_ON_ALLOC(ptr) mozilla::dmd::ReportOnAlloc(ptr)
|
2012-12-10 16:05:07 -08:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2012-12-23 16:59:51 -08:00
|
|
|
#define MOZ_REPORT(ptr)
|
|
|
|
#define MOZ_REPORT_ON_ALLOC(ptr)
|
2012-12-10 16:05:07 -08:00
|
|
|
|
2012-12-20 23:03:50 -08:00
|
|
|
#endif // defined(MOZ_DMD)
|
2012-12-10 16:05:07 -08:00
|
|
|
|
|
|
|
// Functions generated via this macro should be used by all traversal-based
|
|
|
|
// memory reporters. Such functions return |moz_malloc_size_of(ptr)|; this
|
|
|
|
// will always be zero on some obscure platforms.
|
|
|
|
//
|
2012-12-23 16:59:51 -08:00
|
|
|
// You might be wondering why we have a macro that creates multiple functions
|
2013-12-07 21:38:32 -08:00
|
|
|
// that differ only in their name, instead of a single MallocSizeOf function.
|
|
|
|
// It's mostly to help with DMD integration, though it sometimes also helps
|
|
|
|
// with debugging and temporary ad hoc profiling. The function name chosen
|
|
|
|
// doesn't matter greatly, but it's best to make it similar to the path used by
|
|
|
|
// the relevant memory reporter(s).
|
|
|
|
#define MOZ_DEFINE_MALLOC_SIZE_OF(fn) \
|
2013-08-14 18:19:24 -07:00
|
|
|
static size_t fn(const void* aPtr) \
|
2011-12-08 19:09:36 -08:00
|
|
|
{ \
|
2013-08-14 18:19:24 -07:00
|
|
|
MOZ_REPORT(aPtr); \
|
|
|
|
return moz_malloc_size_of(aPtr); \
|
2011-12-08 19:09:36 -08:00
|
|
|
}
|
2011-11-27 19:03:14 -08:00
|
|
|
|
2012-12-10 16:05:07 -08:00
|
|
|
// Functions generated by the next two macros should be used by wrapping
|
|
|
|
// allocators that report heap blocks as soon as they are allocated and
|
|
|
|
// unreport them as soon as they are freed. Such allocators are used in cases
|
|
|
|
// where we have third-party code that we cannot modify. The two functions
|
|
|
|
// must always be used in tandem.
|
2013-12-07 21:38:32 -08:00
|
|
|
#define MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(fn) \
|
2013-08-14 18:19:24 -07:00
|
|
|
static size_t fn(const void* aPtr) \
|
2011-11-27 19:03:14 -08:00
|
|
|
{ \
|
2013-08-14 18:19:24 -07:00
|
|
|
MOZ_REPORT_ON_ALLOC(aPtr); \
|
|
|
|
return moz_malloc_size_of(aPtr); \
|
2011-11-27 19:03:14 -08:00
|
|
|
}
|
2013-12-07 21:38:32 -08:00
|
|
|
#define MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(fn) \
|
2013-08-14 18:19:24 -07:00
|
|
|
static size_t fn(const void* aPtr) \
|
2012-12-10 16:05:07 -08:00
|
|
|
{ \
|
2013-08-14 18:19:24 -07:00
|
|
|
return moz_malloc_size_of(aPtr); \
|
2012-12-10 16:05:07 -08:00
|
|
|
}
|
2011-11-27 19:03:14 -08:00
|
|
|
|
2013-01-14 16:26:47 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
// The following base class reduces the amount of boilerplate code required for
|
2013-08-27 16:24:51 -07:00
|
|
|
// memory uni-reporters. You just need to provide the following.
|
2013-12-03 20:01:24 -08:00
|
|
|
// - The constant values: path, kind, units, and description. They are
|
|
|
|
// arguments to the MemoryUniReporter constructor.
|
2013-11-05 19:58:20 -08:00
|
|
|
// - A private Amount() or public GetAmount() method. It can use the
|
2013-01-17 16:45:11 -08:00
|
|
|
// MallocSizeOf method if necessary. (There is also
|
|
|
|
// MallocSizeOfOn{Alloc,Free}, which can be useful.) Use Amount() if the
|
|
|
|
// reporter is infallible, and GetAmount() otherwise. (If you fail to
|
|
|
|
// provide one or the other, you'll get assertion failures when the memory
|
|
|
|
// reporter runs.)
|
2013-01-14 16:26:47 -08:00
|
|
|
//
|
2013-12-03 20:01:24 -08:00
|
|
|
// The class name of subclasses should match the path, minus the "explicit" (if
|
|
|
|
// present), and with "Reporter" at the end. For example:
|
|
|
|
// - path == "explicit/dom/xyzzy" --> DOMXyzzyReporter
|
|
|
|
// - path == "js-compartments/system" --> JSCompartmentsSystemReporter
|
2013-01-14 16:26:47 -08:00
|
|
|
//
|
2013-08-27 16:24:51 -07:00
|
|
|
class MemoryUniReporter : public nsIMemoryReporter
|
2013-01-14 16:26:47 -08:00
|
|
|
{
|
|
|
|
public:
|
2013-12-03 20:01:24 -08:00
|
|
|
MemoryUniReporter(const char* aPath, int32_t aKind, int32_t aUnits,
|
2013-08-27 16:24:51 -07:00
|
|
|
const char* aDescription)
|
2013-12-03 20:01:24 -08:00
|
|
|
: mPath(aPath)
|
2013-01-14 16:26:47 -08:00
|
|
|
, mKind(aKind)
|
|
|
|
, mUnits(aUnits)
|
|
|
|
, mDescription(aDescription)
|
|
|
|
{}
|
|
|
|
|
2013-08-27 16:24:51 -07:00
|
|
|
virtual ~MemoryUniReporter() {}
|
2013-01-14 16:26:47 -08:00
|
|
|
|
2013-07-18 19:31:26 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2013-01-14 16:26:47 -08:00
|
|
|
|
2013-08-27 16:24:51 -07:00
|
|
|
NS_IMETHOD CollectReports(nsIMemoryReporterCallback* aCallback,
|
2013-10-24 21:39:16 -07:00
|
|
|
nsISupports* aData)
|
2013-01-14 16:26:47 -08:00
|
|
|
{
|
2013-08-27 16:24:51 -07:00
|
|
|
int64_t amount;
|
|
|
|
nsresult rv = GetAmount(&amount);
|
2013-11-19 13:27:37 -08:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
2013-01-14 16:26:47 -08:00
|
|
|
|
2013-12-03 20:01:24 -08:00
|
|
|
return aCallback->Callback(EmptyCString(), mPath, mKind, mUnits,
|
2013-10-24 21:39:16 -07:00
|
|
|
amount, mDescription, aData);
|
2013-01-14 16:26:47 -08:00
|
|
|
}
|
|
|
|
|
2013-08-27 16:24:51 -07:00
|
|
|
protected:
|
2013-01-14 16:26:47 -08:00
|
|
|
NS_IMETHOD GetAmount(int64_t* aAmount)
|
|
|
|
{
|
|
|
|
*aAmount = Amount();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:02:45 -08:00
|
|
|
virtual int64_t Amount()
|
|
|
|
{
|
|
|
|
// We only reach here if neither GetAmount() nor Amount() was overridden.
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-01-14 16:26:47 -08:00
|
|
|
|
2013-12-07 21:38:32 -08:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
|
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(MallocSizeOfOnAlloc)
|
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(MallocSizeOfOnFree)
|
2013-01-14 16:26:47 -08:00
|
|
|
|
2013-12-03 20:01:24 -08:00
|
|
|
const nsCString mPath;
|
2013-01-14 16:26:47 -08:00
|
|
|
const int32_t mKind;
|
|
|
|
const int32_t mUnits;
|
|
|
|
const nsCString mDescription;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-03-05 17:28:25 -08:00
|
|
|
%}
|