PowerMetric
@RequiresApi(value = 29)
@ExperimentalMetricApi
public final class PowerMetric extends Metric
Captures the change of power, energy or battery charge metrics over time for specified duration. A configurable output of power, energy, subsystems, and battery charge will be generated. Subsystem outputs will include the sum of all power or energy metrics within it. A metric total will also be generated for power and energy, as well as a metric which is the sum of all unselected metrics.
Summary
Nested types |
|---|
public sealed class PowerMetric.TypeConfigures the PowerMetric request. |
public final class PowerMetric.Type.Battery extends PowerMetric.Type |
public final class PowerMetric.Type.Energy extends PowerMetric.Type |
public final class PowerMetric.Type.Power extends PowerMetric.Type |
Public constructors |
|---|
PowerMetric(@NonNull PowerMetric.Type type) |
Public methods |
|
|---|---|
static final @NonNull PowerMetric.Type.Battery |
Battery() |
static final @NonNull PowerMetric.Type.Energy |
Energy( |
static final @NonNull PowerMetric.Type.Power |
Power( |
static final boolean |
Returns true if |
static final boolean |
Returns true if the current device can be used for high precision |
Public constructors
PowerMetric
public PowerMetric(@NonNull PowerMetric.Type type)
| Parameters | |
|---|---|
@NonNull PowerMetric.Type type |
Either For For The metrics will be stored in the format Power metrics example: powerCategoryDisplayUw min 128.2, median 128.7, max 129.8 Energy metrics example: energyCategoryDisplayUws min 610,086.0, median 623,183.0, max 627,259.0 Battery metrics example: batteryDiffMah min 2.0, median 2.0, max 4.0 This measurement is not available prior to API 29. |
Public methods
Energy
public static final @NonNull PowerMetric.Type.Energy Energy(
@NonNull Map<@NonNull PowerCategory, @NonNull PowerCategoryDisplayLevel> categories
)
Power
public static final @NonNull PowerMetric.Type.Power Power(
@NonNull Map<@NonNull PowerCategory, @NonNull PowerCategoryDisplayLevel> categories
)
deviceBatteryHasMinimumCharge
public static final boolean deviceBatteryHasMinimumCharge()
Returns true if Type.Battery measurements can be performed, based on current device charge.
This can be used to change behavior or throw a clear error before metric configuration, or to skip the test, e.g. with assumeTrue(PowerMetric.deviceBatteryHasMinimumCharge())
deviceSupportsHighPrecisionTracking
public static final boolean deviceSupportsHighPrecisionTracking()
Returns true if the current device can be used for high precision Power and Energy metrics.
This can be used to change behavior or fall back to lower precision tracking:
metrics = listOf(
if (PowerMetric.deviceSupportsHighPrecisionTracking()) {
PowerMetric(Type.Energy()) // high precision tracking
} else {
PowerMetric(Type.Battery()) // fall back to less precise tracking
}
)
Or to skip a test when detailed tracking isn't available:
@Test fun myDetailedPowerBenchmark {
assumeTrue(PowerMetric.deviceSupportsHighPrecisionTracking())
macrobenchmarkRule.measureRepeated (
metrics = listOf(PowerMetric(Type.Energy(...)))
) {
...
}
}