Hi there,

As you may know that battery life has always been one of the important
concerns for users on
mobile devices. Our intern student Gavin Lai and I propose APIs and
framework on FFOS to help to
gather power consumption statistic information. Our goal is to provide
power consumption information
from gecko. The application can use these information to calculate the
power consumption per app.

We classify the power consumption into two groups:
Application and System.

For each application, there are several parts are included as follows:
1. CPU
2. WiFi Active (WiFi traffic)
3. Radio Active (Radio traffic)
4. Wakelock

Some events or components are hard to distinguish into each app.
We classify this kind of power consumption into System.
1. Screen
2. WiFi On
3. WiFi Scan
4. Idle
5. Bluetooth On
6. Audio
7. Video
8. GPS
(Not sure)9. Bluetooth Active (Bluetooth traffic)

The UI of Power Meter Application we imagine would be like this:
------------------------------------
Total Power Consumption|||||||| 70% |
-----------Application--------------------|
App1 Icon|||||                               10% |
  CPU|||                                          3% |
  WiFi||||||                                        7% |
App2 Icon||||||||                            20% |
  CPU||||||||||||                               20% |
-----------System------------------------|
Screen||||||||||||||||                         25% |
Idle||||||||                                       10% |
WiFi On||                                        5% |
-------------------------------------

To provide the statistic information, we implement a framework in Gecko.
The architecture is shown in attached file (Architecture V2).


PowerStatsManager is responsible for sending messages and results.
We provide 4 DOM APIs.

  /**
   * return a JSON object contains all the statistic information the
   * applications and the system.
   */
  nsIDOMDOMRequest   load();

  /**
   * return a JSON object contains the statistic information of the
   * specific application.
   */
  nsIDOMDOMRequest   load(in DOMString manifest);

  /**
   * return a JSON object contains the statistic information of the
   * specific component. For example, load("WifiOn").
  nsIDOMDOMRequest   load(in DOMString component);

  /**
   * update the information in Gecko.
   */
  nsIDOMDOMRequest   refresh();

  /**
   * read the average power consumption of item in power profile.
   */
  readonly attribute jsval readProfile(in DOMString item);

PowerStatsService is responsible for 4 jobs.
1. save/load PowerStatsDB
   PowerStatsService stores the statistic informaiton in PowerStatsDB before
   system shutdown and loads the statistic informaiton from PowerStatsDB
after
   the system boots up.

2. power consumption per app
   Each statistic information of an application contains manifest url, pid,
cpu,
   wifi traffic, radio traffic, wakelock time.

   For power consumption contributes by cpu, our idea is that the
PowerStatsService
   records the process id(pid) of an application when an application
is launched.
We can
   get application's user time and system time from linux kernel's proc
entry in /proc/<pid>/stats.

   For power consumption contributes by wifi and radio, our idea is
to estimate the power
   consumption from the help of statistic of network traffic by wifi and
radio interfaces. Once we have the
   transmit/receive bytes and connected speed, we can convert these
information to active time used by
   wifi and radio components.

3. Power consumption per component
   To estimate the power consumption of a component, we need to measure the
   duration of a component by listening to some special events in
PowerStatsService. The special events
   include wifi is on/scaning, screen is on/off.....
   In order to minimize the hardware resource usage for measurement, we use
system clock time as a
   timestamp to record the start time and the end time. The statistic
information is stored in JSON format.
   We need the support from components (e.g. WiFi, radio,
Bluetooth, screen[brightnessLevel]) to help
   record the timestamp. Then, a component transfers the timestamp to
PowerStatsService via NotifyObservers.
   The interfaces for transferring timestamp are as follows:

NotifyObservers(nsISupports PowerStats, string component, string startTime)
NotifyObservers(nsISupports PowerStats, string component, string endTime)

4. ProfileReader
   To estimate the power consumption of each component (e.g. CPU, Wifi), we
need
   the average power of each component which need information from chip
vendors or
   OEM partners. We gather the average power in a file called PowerProfile.
   The unit of each value is mA. The contents would be like this:

<item name="screen.on">256</item>

<item name="screen.full">318</item>

<item name="wifi.on">2.9</item>

<item name="wifi.active">31.0</item>

<item name="wifi.scan">100</item>

   We also need a DOM API to provide the power profile of each component in
Gaia.
   The API can be something like,
       readProfile(in DOMString item)


With all these statistic information, the Power Meter Application can
estimate
the power consumption. Also, developers can implement power-related
applications.

The meta bug for power metering is filed in Bug 854200. Any feedback on our
approach is welcome.


Vincent Chang(vchang on IRC),
Software Engineer of Mozilla Taiwan
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to