statsd: Add BatteryCycleCount atom
The health HAL specifies a charge cycles path that currently has no
atoms allocated to it. This change will allow statsd to collect this
information. I also ran 'clang-format -i --style=file' on this file.
Bug: 120680509
Test: cts-tradefed run singleCommand cts-dev -m CtsStatsdHostTestCases \
-t android.cts.statsd.atom.HostAtomTests#testBatteryCycleCount
Test: adb shell cmd stats pull-source 10045
Change-Id: I796b275c5d6880e9d7ec5bc468b55d7dc421ac78
Signed-off-by: Maggie White <maggiewhite@google.com>
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index f06914f..66127c9 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -244,6 +244,7 @@
ProcessMemoryHighWaterMark process_memory_high_water_mark = 10042;
BatteryLevel battery_level = 10043;
BuildInformation build_information = 10044;
+ BatteryCycleCount battery_cycle_count = 10045;
}
// DO NOT USE field numbers above 100,000 in AOSP.
@@ -2487,6 +2488,19 @@
optional int32 time_to_inactive_secs = 5;
};
+/**
+ * Logs total effective full charge and discharge cycles on a battery.
+ * Here are some examples of one effective cycle:
+ * 1) the battery charges from 0% to 100% and drains back to 0%,
+ * 2) charging from 50% to 100% and draining back to 50% twice.
+ * Pulled from:
+ * frameworks/base/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
+ */
+message BatteryCycleCount {
+ /* Number of total charge and discharge cycles on the system battery. */
+ optional int32 cycle_count = 1;
+}
+
/*
* Logs when a connection becomes available and lost.
* Logged in StatsCompanionService.java
diff --git a/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp b/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
index b878652..75b63f4 100644
--- a/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
+++ b/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
@@ -24,16 +24,16 @@
#include "ResourceHealthManagerPuller.h"
#include "logd/LogEvent.h"
-#include "statslog.h"
#include "stats_log_util.h"
+#include "statslog.h"
using android::hardware::hidl_vec;
+using android::hardware::Return;
+using android::hardware::Void;
using android::hardware::health::V2_0::get_health_service;
using android::hardware::health::V2_0::HealthInfo;
using android::hardware::health::V2_0::IHealth;
using android::hardware::health::V2_0::Result;
-using android::hardware::Return;
-using android::hardware::Void;
using std::make_shared;
using std::shared_ptr;
@@ -75,35 +75,41 @@
}
if (mTagId == android::util::REMAINING_BATTERY_CAPACITY) {
auto ptr = make_shared<LogEvent>(android::util::REMAINING_BATTERY_CAPACITY,
- wallClockTimestampNs, elapsedTimestampNs);
+ wallClockTimestampNs, elapsedTimestampNs);
ptr->write(v.legacy.batteryChargeCounter);
ptr->init();
data->push_back(ptr);
} else if (mTagId == android::util::FULL_BATTERY_CAPACITY) {
auto ptr = make_shared<LogEvent>(android::util::FULL_BATTERY_CAPACITY,
- wallClockTimestampNs, elapsedTimestampNs);
+ wallClockTimestampNs, elapsedTimestampNs);
ptr->write(v.legacy.batteryFullCharge);
ptr->init();
data->push_back(ptr);
} else if (mTagId == android::util::BATTERY_VOLTAGE) {
- auto ptr = make_shared<LogEvent>(android::util::BATTERY_VOLTAGE,
- wallClockTimestampNs, elapsedTimestampNs);
+ auto ptr = make_shared<LogEvent>(android::util::BATTERY_VOLTAGE, wallClockTimestampNs,
+ elapsedTimestampNs);
ptr->write(v.legacy.batteryVoltage);
ptr->init();
data->push_back(ptr);
} else if (mTagId == android::util::BATTERY_LEVEL) {
- auto ptr = make_shared<LogEvent>(android::util::BATTERY_LEVEL,
- wallClockTimestampNs, elapsedTimestampNs);
- ptr->write(v.legacy.batteryLevel);
- ptr->init();
- data->push_back(ptr);
+ auto ptr = make_shared<LogEvent>(android::util::BATTERY_LEVEL, wallClockTimestampNs,
+ elapsedTimestampNs);
+ ptr->write(v.legacy.batteryLevel);
+ ptr->init();
+ data->push_back(ptr);
+ } else if (mTagId == android::util::BATTERY_CYCLE_COUNT) {
+ auto ptr = make_shared<LogEvent>(android::util::BATTERY_CYCLE_COUNT,
+ wallClockTimestampNs, elapsedTimestampNs);
+ ptr->write(v.legacy.batteryCycleCount);
+ ptr->init();
+ data->push_back(ptr);
} else {
ALOGE("Unsupported tag in ResourceHealthManagerPuller: %d", mTagId);
}
});
if (!result_success || !ret.isOk()) {
ALOGE("getHealthHal() failed: health HAL service not available. Description: %s",
- ret.description().c_str());
+ ret.description().c_str());
if (!ret.isOk() && ret.isDeadObject()) {
gHealthHal = nullptr;
}
diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp
index 4a716cf..19a7389 100644
--- a/cmds/statsd/src/external/StatsPullerManager.cpp
+++ b/cmds/statsd/src/external/StatsPullerManager.cpp
@@ -131,9 +131,12 @@
// battery_voltage
{android::util::BATTERY_VOLTAGE,
{.puller = new ResourceHealthManagerPuller(android::util::BATTERY_VOLTAGE)}},
- // battery_voltage
+ // battery_level
{android::util::BATTERY_LEVEL,
{.puller = new ResourceHealthManagerPuller(android::util::BATTERY_LEVEL)}},
+ // battery_cycle_count
+ {android::util::BATTERY_CYCLE_COUNT,
+ {.puller = new ResourceHealthManagerPuller(android::util::BATTERY_CYCLE_COUNT)}},
// process_memory_state
{android::util::PROCESS_MEMORY_STATE,
{.additiveFields = {4, 5, 6, 7, 8, 9},