1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/.
8 * Supported resource statistics
16 * List of system services supporting resource statistics
23 dictionary ResourceStatsOptions
26 * |component| specifies which component's resource usage will be returned.
27 * If null or undefined, sum of all components' usage is returned.
29 * |component| is expressed in "<component>:<id>", where <component> is the
30 * name of the component and <id> is used to identify different entities.
32 * The <id> field is mainly used in specifying the identity of different SIMs
33 * when quering mobile network usage, e.g. "mobile:<iccid>".
35 * Quering statistics of other components should specify the |component| to
36 * "<component>:0", such as "cpu:0" or "wifi:0".
38 DOMString? component = null;
41 * |manifestURL| specifies the manifestURL of an application.
42 * |systemService| specifies the system service.
44 * If both |systemService| and |manifestURL| are null or undefined, then a
45 * system-wide resource statistics is returned.
47 * If |manifestURL| is specified, then the resource statistics of the
48 * specified application is returned.
50 * If |systemService| is specified, then the resource statistics of the
51 * specified system service is returned.
53 * If |systemService| and |manifestURL| are both specified, then the return
54 * statistics indicates the resources that the system service consumed for
57 SystemService? serviceType = null;
58 DOMString? manifestURL = null;
61 dictionary ResourceStatsAlarmOptions
64 * |startTime| indicates the start time of counting the resource usage.
66 * |data| is used to reflect in the alarm object when the alarm is triggered.
67 * |data| should be copied using the structured clone algorithm.
69 [EnforceRange] DOMTimeStamp startTime; // time in milliseconds since Epoch
73 [CheckPermissions="resourcestats-manage",
74 Pref="dom.resource_stats.enabled",
75 AvailableIn="CertifiedApps",
76 JSImplementation="@mozilla.org/resourceStatsAlarm;1"]
77 interface ResourceStatsAlarm
82 readonly attribute unsigned long alarmId;
85 * Type of resource this alarm monitor
87 readonly attribute ResourceType type;
90 * The target component this alarm monitor.
92 readonly attribute DOMString? component;
95 * |manifestURL| specifies the manifestURL of an application.
96 * |systemService| specifies the system service.
98 * Both attributes are null means that this alarm monitors a system-wide
101 readonly attribute SystemService? serviceType;
102 readonly attribute DOMString? manifestURL;
105 * |threshold| specifies the limit of resource usage.
107 readonly attribute unsigned long long threshold;
110 * |data| is used to reflect in the alarm object when the alarm is triggered.
112 readonly attribute any data;
115 [CheckPermissions="resourcestats-manage",
116 Pref="dom.resource_stats.enabled",
117 Constructor(ResourceType type),
118 AvailableIn="CertifiedApps",
119 JSImplementation="@mozilla.org/resourceStatsManager;1"]
120 interface ResourceStatsManager
123 * Query resource statistics.
125 * |statsOptions| specifies the detail of statistics of interest.
127 * |start| and |end| specifies the time range of interest, both included.
128 * If |start| is null or undefined, retrieve the stats since measurements.
129 * If |end| is null or undefined. retrieve the stats until the current time.
131 * If success, the fulfillment value is a ResourceStats object.
133 Promise<ResourceStats> getStats(optional ResourceStatsOptions statsOptions,
134 [EnforceRange] optional DOMTimeStamp? start = null,
135 [EnforceRange] optional DOMTimeStamp? end = null);
138 * Clear resource statistics stored in database.
140 * |statsOptions| specifies the detail of statistics to delete.
142 * |start| and |end| specifies the time range of interest, both included.
143 * If |start| is null or undefined, delete the stats since measurements.
144 * If |end| is null or undefined. delete the stats until the current time.
146 // XXXbz What is this promise resolved with?
147 Promise<any> clearStats(optional ResourceStatsOptions statsOptions,
148 [EnforceRange] optional DOMTimeStamp? start = null,
149 [EnforceRange] optional DOMTimeStamp? end = null);
152 * Clear all resource statistics stored in database.
154 // XXXbz What is this promise resolved with?
155 Promise<any> clearAllStats();
158 * Install an alarm to monitor resource usage.
160 * The |threshold| specifies the limit of resource usage. When resource
161 * usage reaches the threshold, a "resourceStats-alarm" system message
162 * is sent to the application.
164 * |statsOptions| specifies the detail of statistics of interest.
166 * |alarmOptions| is a ResourceStatsAlarmOptions object.
168 * If success, the fulfillment value is an alarm ID.
170 Promise<unsigned long> addAlarm([EnforceRange] unsigned long long threshold,
171 optional ResourceStatsOptions statsOptions,
172 optional ResourceStatsAlarmOptions alarmOptions);
177 * If |statsOptions| is provided, then only the alarms monitoring that
178 * resource are returned. Otherwise, all alarms set for this resource type
181 * If success, the fulfillment value is an array of ResourceStatsAlarm.
183 Promise<sequence<ResourceStatsAlarm>> getAlarms(optional ResourceStatsOptions statsOptions);
186 * Remove the specified alarm.
188 * |alarmId| specifies the alarm to be removed.
190 // XXXbz What is this promise resolved with?
191 Promise<any> removeAlarm([EnforceRange] unsigned long alarmId);
196 // XXXbz What is this promise resolved with?
197 Promise<any> removeAllAlarms();
200 * Enumerate components that have stored statistics in database.
202 * If success, the fulfillment value is an array of DOMString.
204 Promise<sequence<DOMString>> getAvailableComponents();
207 * Return supporting resource statistics, i.e. ["Network", "Power"]
209 * This should be specified as static attribute after Bug 863952 is resolved.
212 readonly attribute sequence<DOMString> resourceTypes;
215 * Time in milliseconds between statistics stored in database.
217 * This should be specified as static attribute after Bug 863952 is resolved.
219 readonly attribute unsigned long sampleRate;
222 * Time in milliseconds recorded by the API until present time. All
223 * statistics older than maxStorageAge from now are deleted.
225 * This should be specified as static attribute after Bug 863952 is resolved.
227 readonly attribute unsigned long long maxStorageAge;