Hi all:
Thank you guys for the great suggestions.
The revised ResourceStats API proposal is attached at the end of this mail.
Please left your comments if anyone has other thoughts.
Thanks a lot!
Modification note:
1. Use the factory design as suggested by Salvador. So, I separate the original interface to two:
-- ResourceStatsFactory is used to instantiate a ResourceStatsManger for a specific resource
-- ResourceStatsManager is used to query statistics and add resource alarms
2. Merge PowerStatsOptions and NetworkStatsOptions to one ResourceStatsOptions dictionary.
And, define several enums to represent resource types, components and system services.
3. Provide methods to get/clear "all" stats/alarms, which includes:
clearAllStats, getAllAlarms, and removeAllAlarm.
== Proposal Start ==
/**
* Supported resource statistics
*/
enum ResourceType {
"network",
"power"
};
/**
* List of components supporting power statistics
*/
enum PowerComponent {
"cpu",
"screen",
"mobile",
"wifi",
"bluetooth",
"gps"
};
/**
* List of components supporting network statistics.
*
* Note that a query for mobile network usage should use a DOMString to specify
* the ICC ID of the SIM card rather than specify a NetworkComponent enum type.
*/
enum NetworkComponent {
"wifi"
};
/**
* List of system services supporting resource statistics
*/
enum SystemService {
"ota",
"tethering"
};
typedef (PowerComponent or NetworkComponent or DOMString) ResourceStatsComponent;
dictionary ResourceStatsOptions
{
/**
* For power stats, |component| specifies which component's power consumption
* will be returned. If null, total power consumption is returned.
*
* For network stats, |component| specifies the network interface. DOMString
* is used to specify an ICC ID when querying the usage of mobile network.
* To query the stats of other network interfaces, a NetworkComponent enum
* type should be specified. If null, total network usage (Wi-Fi + mobile) is
* returned.
*/
ResourceStatsComponent component;
/**
* |manifestURL| specifies the manifestURL of an application.
* |systemService| specifies the system service.
*
* If both |systemService| and |manifestURL| are null, then a system-wide
* resource statistics is returned.
*
* If |manifestURL| is specified, then the resource statistics of the
* specified application is returned.
*
* If |systemService| is specified, then the resource statistics of the
* specified system service is returned.
*
* If both |systemService| and |manifestURL| are specified, then the return
* statistics indicates the resources that the system service consumed for
* the application.
*/
SystemService systemService;
DOMString manifestURL;
};
dictionary ResourceStatsAlarmOptions
{
/**
* |startTime| indicates the start time of counting the resource usage.
*
* |data| is used to reflect in the alarm object when the alarm is triggered.
*/
unsigned long long startTime; // time in milliseconds since Epoch
any data;
};
[JSImplementation="@
mozilla.org/resourceStatsAlarm;1", Pref="dom.mozResourceStats.enabled"]
interface MozResourceStatsAlarm
{
readonly attribute unsigned long alarmId;
readonly attribute ResourceType type;
readonly attribute any statsOptions; // ResourceStatsOptions
readonly attribute any threshold;
readonly attribute any data;
};
[Constructor(ResourceType type), JSImplementation="@
mozilla.org/resourceStatsManager;1", Pref="dom.mozResourceStats.enabled"]
interface ResourceStatsManager
{
/**
* Query resource statistics.
*
* |start| and |end| specifies the time range of interest, both included.
* If |start| is 0, retrieves the stats since measurements.
* If |end| is 0. retrieves the stats until the current time.
*
* |statsOptions| specifies the detial of statistics of interest.
*
* If success, the |result| field keeps statistics.
* For networkStatsManager, the |result| is an array of NetworkStats object.
* For powerStatsManager, the |result| is an array of PowerStats object.
*/
Promise getStats(unsigned long long start,
unsigned long long end,
optional ResourceStatsOptions statsOptions);
/**
* Clear resource statistics stored in database.
*
* If |statsOptions| is provided, then only the statistics associated to that
* |statsOptions| is deleted. Otherwise, all statistics of this resource type
* is deleted.
*/
Promise clearStats(optional ResourceStatsOptions statsOptions);
/**
* Clear all resource statistics stored in database.
*/
Promise clearAllStats();
/**
* Install an alarm to monitor resource usage.
*
* The |threshold| is an object specified the limit of resource usage. When
* resource usage reaches the threshold, a "resourceStats-alarm" system
* message is sent to the application.
*
* |statsOptions| specifies the detial of statistics of interest.
*
* |alarmOptions| is a ResourceStatsAlarmOptions object.
*
* If success, the |result| field keeps the alarm Id.
*/
Promise addAlarm(any threshold,
optional ResourceStatsOptions statsOptions,
optional ResourceStatsAlarmOptions alarmOptions);
/**
* Obtain alarms.
*
* If |statsOptions| is provided, then only the alarms monitoring that
* resource are returned. Otherwise, all alarms set for this resource type
* is returned.
*
* If success, the |result| is an array of ResourceStatsAlarm.
*/
Promise getAlarms(optional ResourceStatsOptions statsOptions);
/**
* Obtain all alarms.
*
* If success, the |result| is an array of ResourceStatsAlarm.
*/
Promise getAllAlarms();
/**
* Remove alarms.
*
* If an |alarmId| is provided, then only that alarm is removed.
*/
Promise removeAlarm(optional long alarmId);
/**
* Remove all alarms.
*/
Promise removeAllAlarm();
/**
* Return available resource stats options stored in database.
*
* If success, the |result| is an array of ResourceStatsOptions.
*/
Promise getResourceStatsOptions();
/**
* Return the type of resource statistics provided by this manager.
*/
readonly attribute DOMString resourceType;
};
[JSImplementation="@
mozilla.org/resourceStatsFactory;1", NavigatorProperty="mozResourceStats", Pref="dom.mozResourceStats.enabled"]
interface ResourceStatsFactory
{
/**
* Get the resourceStatsManager for a resource type.
*
* |type| specifies the type of resourceStatsManager we want to obtain.
* This value should be one of those returned by resourceTypes attribute.
*
* If success, this method returns an object of ResourceStatsManager.
* Otherwise, null is resturned
*/
ResourceStatsManager getResourceStatsManager(ResourceType type);
/**
* Return the name of supported resource statistics types.
* Currently, 'network' and 'power' statistics are supported.
*/
readonly attribute any resourceTypes; // array of DOMString
/**
* Time in milliseconds between statistics stored in database.
*/
readonly attribute unsigned long long sampleRate;
/**
* Time in milliseconds recorded by the API until present time. All
* statistics older than maxStorageAge from now are deleted.
*/
readonly attribute unsigned long long maxStorageAge;
};
== Proposal End ==
Cheers,
Borting