public class HealthStats extends Object
Data Types
Each of the keys references data in one of five data types:
A measurement metric contains a sinlge long
value. That value may
be a count, a time, or some other type of value. The unit for a measurement
(COUNT, MS, etc) will always be in the name of the constant for the key to
retrieve it. For example, the
UidHealthStats.MEASUREMENT_WIFI_TX_MS
value is the number of milliseconds (ms) that were spent transmitting on wifi by an
application. The
UidHealthStats.MEASUREMENT_MOBILE_RX_PACKETS
measurement is the number of packets received on behalf of an application.
The UidHealthStats.MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT
measurement is the number of times the user touched the screen, causing the
screen to stay awake.
A timer metric contains an int
count and a long
time,
measured in milliseconds. Timers track how many times a resource was used, and
the total duration for that usage. For example, the
UidHealthStats.TIMER_FLASHLIGHT
timer tracks how many times the application turned on the flashlight, and for
how many milliseconds total it kept it on.
A measurement map metric is a mapping of String
names to
Long
values. The names typically are application provided names. For
example, the
PackageHealthStats.MEASUREMENTS_WAKEUP_ALARMS_COUNT
measurement map is a mapping of the tag provided to the
AlarmManager
when the alarm is scheduled.
A timer map metric is a mapping of String
names to
TimerStat
objects. The names are typically application
provided names. For example, the
UidHealthStats.TIMERS_WAKELOCKS_PARTIAL
is a mapping of tag provided to the PowerManager
when the
wakelock is created to the number of times and for how long each wakelock was
active.
Lastly, a health stats metric is a mapping of String
names to a recursive HealthStats
object containing
more detailed information. For example, the
UidHealthStats.STATS_PACKAGES
metric is a mapping of the package names for each of the APKs sharing a uid to
the information recorded for that apk. The returned HealthStats objects will
each be associated with a different set of constants. For the HealthStats
returned for UidHealthStats.STATS_PACKAGES, the keys come from the
PackageHealthStats
class.
The keys that are available are subject to change, depending on what a particular device or software version is capable of recording. Applications must handle the absence of data without crashing.
Constructor and Description |
---|
HealthStats(Parcel in)
Construct a health stats object from a parcel.
|
Modifier and Type | Method and Description |
---|---|
String |
getDataType()
Get a name representing the contents of this object.
|
long |
getMeasurement(int key)
Get the measurement for the given key.
|
int |
getMeasurementKeyAt(int index)
Get the key for the measurement at the given index.
|
int |
getMeasurementKeyCount()
Get the number of measurement values in this object.
|
Map<String,Long> |
getMeasurements(int key)
Get the measurements map for the given key.
|
int |
getMeasurementsKeyAt(int index)
Get the key for the measurement map at the given index.
|
int |
getMeasurementsKeyCount()
Get the number of measurement map values in this object.
|
Map<String,HealthStats> |
getStats(int key)
Get the HealthStats map for the given key.
|
int |
getStatsKeyAt(int index)
Get the key for the timer at the given index.
|
int |
getStatsKeyCount()
Get the number of HealthStat map values in this object.
|
TimerStat |
getTimer(int key)
Return a TimerStat object for the given key.
|
int |
getTimerCount(int key)
Get the count for the timer for the given key.
|
int |
getTimerKeyAt(int index)
Get the key for the timer at the given index.
|
int |
getTimerKeyCount()
Get the number of timer values in this object.
|
Map<String,TimerStat> |
getTimers(int key)
Get the TimerStat map for the given key.
|
int |
getTimersKeyAt(int index)
Get the key for the timer map at the given index.
|
int |
getTimersKeyCount()
Get the number of timer map values in this object.
|
long |
getTimerTime(int key)
Get the time for the timer for the given key, in milliseconds.
|
boolean |
hasMeasurement(int key)
Return whether this object contains a measurement for the supplied key.
|
boolean |
hasMeasurements(int key)
Return whether this object contains a measurements map for the supplied key.
|
boolean |
hasStats(int key)
Return whether this object contains a HealthStats map for the supplied key.
|
boolean |
hasTimer(int key)
Return whether this object contains a TimerStat for the supplied key.
|
boolean |
hasTimers(int key)
Return whether this object contains a timers map for the supplied key.
|
public HealthStats(Parcel in)
public String getDataType()
public boolean hasTimer(int key)
public TimerStat getTimer(int key)
TimerStat
object, which may be wasteful. Instead, use
getTimerCount(int)
and getTimerTime(int)
.IndexOutOfBoundsException
- When the key is not present in this object.hasTimer(int) To check if a value for the given key is present.
public int getTimerCount(int key)
IndexOutOfBoundsException
- When the key is not present in this object.hasTimer(int) To check if a value for the given key is present.
public long getTimerTime(int key)
IndexOutOfBoundsException
- When the key is not present in this object.hasTimer(int) To check if a value for the given key is present.
public int getTimerKeyCount()
getTimerKeyAt(int)
public int getTimerKeyAt(int index)
getTimerKeyCount()
.getTimerKeyCount()
public boolean hasMeasurement(int key)
public long getMeasurement(int key)
IndexOutOfBoundsException
- When the key is not present in this object.hasMeasurement(int) To check if a value for the given key is present.
public int getMeasurementKeyCount()
getMeasurementKeyAt(int)
public int getMeasurementKeyAt(int index)
getMeasurementKeyCount()
.getMeasurementKeyCount()
public boolean hasStats(int key)
public Map<String,HealthStats> getStats(int key)
IndexOutOfBoundsException
- When the key is not present in this object.hasStats(int) To check if a value for the given key is present.
public int getStatsKeyCount()
getMeasurementKeyAt(int)
public int getStatsKeyAt(int index)
getStatsKeyCount()
.getStatsKeyCount()
public boolean hasTimers(int key)
public Map<String,TimerStat> getTimers(int key)
IndexOutOfBoundsException
- When the key is not present in this object.hasTimers(int) To check if a value for the given key is present.
public int getTimersKeyCount()
getTimersKeyAt(int)
public int getTimersKeyAt(int index)
getTimersKeyCount()
.getTimersKeyCount()
public boolean hasMeasurements(int key)
public Map<String,Long> getMeasurements(int key)
IndexOutOfBoundsException
- When the key is not present in this object.To check if a value for the given key is present.
public int getMeasurementsKeyCount()
getMeasurementsKeyAt(int)
public int getMeasurementsKeyAt(int index)
getMeasurementsKeyCount()
.getMeasurementsKeyCount()