diff options
author | Maggie White <maggiewhite@google.com> | 2018-11-01 14:26:00 -0700 |
---|---|---|
committer | Maggie White <maggiewhite@google.com> | 2018-11-14 21:42:59 +0000 |
commit | a30ceaf6a0e26189126cfcc7a3514d2591c09bcd (patch) | |
tree | c69cbfe683c0f4b432082d6fff46c9f3dd6e4efb /health | |
parent | a83752ae2250517c076952de230db4689bf0244b (diff) | |
download | pixel-a30ceaf6a0e26189126cfcc7a3514d2591c09bcd.tar.gz |
pixelstats: Publish events to both tron and stats HAL
Bug: 114316519
Bug: 119490156
Test: Don't see any stats service error logs on blueline
Test: Verified drop and battery snapshot metrics statsd messages
Change-Id: Ia573de875a54f342477b2b9463c04274b8aa59d8
Signed-off-by: Maggie White <maggiewhite@google.com>
Diffstat (limited to 'health')
-rw-r--r-- | health/Android.bp | 9 | ||||
-rw-r--r-- | health/BatteryMetricsLogger.cpp | 116 | ||||
-rw-r--r-- | health/LowBatteryShutdownMetrics.cpp | 12 | ||||
-rw-r--r-- | health/include/pixelhealth/BatteryMetricsLogger.h | 29 | ||||
-rw-r--r-- | health/include/pixelhealth/LowBatteryShutdownMetrics.h | 2 |
5 files changed, 123 insertions, 45 deletions
diff --git a/health/Android.bp b/health/Android.bp index 76b0df66..cff31327 100644 --- a/health/Android.bp +++ b/health/Android.bp @@ -1,6 +1,6 @@ -cc_library_static { +cc_library { name: "libpixelhealth", - vendor_available: true, + vendor: true, export_include_dirs: ["include"], srcs: [ @@ -19,7 +19,12 @@ cc_library_static { "libbatterymonitor", ], + export_shared_lib_headers: [ + "android.frameworks.stats@1.0", + ], + shared_libs: [ + "android.frameworks.stats@1.0", "hardware.google.pixelstats@1.0", "libbase", "libcutils", diff --git a/health/BatteryMetricsLogger.cpp b/health/BatteryMetricsLogger.cpp index e226e1ce..3a9beb5d 100644 --- a/health/BatteryMetricsLogger.cpp +++ b/health/BatteryMetricsLogger.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ +#include <android/frameworks/stats/1.0/IStats.h> #include <pixelhealth/BatteryMetricsLogger.h> namespace hardware { @@ -22,10 +23,10 @@ namespace google { namespace pixel { namespace health { -using ::hardware::google::pixelstats::V1_0::IPixelStats; -using BatteryHealthSnapshotArgs = - ::hardware::google::pixelstats::V1_0::IPixelStats::BatteryHealthSnapshotArgs; using android::sp; +using android::frameworks::stats::V1_0::BatteryHealthSnapshotArgs; +using android::frameworks::stats::V1_0::IStats; +using ::hardware::google::pixelstats::V1_0::IPixelStats; BatteryMetricsLogger::BatteryMetricsLogger(const char *const batt_res, const char *const batt_ocv, int sample_period, int upload_period) @@ -47,30 +48,57 @@ int64_t BatteryMetricsLogger::getTime(void) { return nanoseconds_to_seconds(systemTime(SYSTEM_TIME_BOOTTIME)); } -bool BatteryMetricsLogger::uploadOutlierMetric(sp<IPixelStats> client, sampleType type) { - BatteryHealthSnapshotArgs min_ss = {static_cast<BatterySnapshotType>(0), - min_[type][TEMP], - min_[type][VOLT], - min_[type][CURR], - min_[type][OCV], - min_[type][RES], - min_[type][SOC]}; - BatteryHealthSnapshotArgs max_ss = {static_cast<BatterySnapshotType>(0), - max_[type][TEMP], - max_[type][VOLT], - max_[type][CURR], - max_[type][OCV], - max_[type][RES], - max_[type][SOC]}; - +bool BatteryMetricsLogger::uploadOutlierMetric(sp<IPixelStats> client, sp<IStats> stats_client, + sampleType type) { + IPixelStats::BatteryHealthSnapshotArgs min_ss = { + .type = static_cast<IPixelStats::BatterySnapshotType>(0), + .temperatureDeciC = min_[type][TEMP], + .voltageMicroV = min_[type][VOLT], + .currentMicroA = min_[type][CURR], + .openCircuitVoltageMicroV = min_[type][OCV], + .resistanceMicroOhm = min_[type][RES], + .levelPercent = min_[type][SOC]}; + IPixelStats::BatteryHealthSnapshotArgs max_ss = { + .type = static_cast<IPixelStats::BatterySnapshotType>(0), + .temperatureDeciC = max_[type][TEMP], + .voltageMicroV = max_[type][VOLT], + .currentMicroA = max_[type][CURR], + .openCircuitVoltageMicroV = max_[type][OCV], + .resistanceMicroOhm = max_[type][RES], + .levelPercent = max_[type][SOC]}; + + BatteryHealthSnapshotArgs min_stats_ss = { + .type = static_cast<BatteryHealthSnapshotArgs::BatterySnapshotType>(0), + .temperatureDeciC = min_[type][TEMP], + .voltageMicroV = min_[type][VOLT], + .currentMicroA = min_[type][CURR], + .openCircuitVoltageMicroV = min_[type][OCV], + .resistanceMicroOhm = min_[type][RES], + .levelPercent = min_[type][SOC]}; + BatteryHealthSnapshotArgs max_stats_ss = { + .type = static_cast<BatteryHealthSnapshotArgs::BatterySnapshotType>(0), + .temperatureDeciC = max_[type][TEMP], + .voltageMicroV = max_[type][VOLT], + .currentMicroA = max_[type][CURR], + .openCircuitVoltageMicroV = max_[type][OCV], + .resistanceMicroOhm = max_[type][RES], + .levelPercent = max_[type][SOC]}; if (kSnapshotType[type] < 0) return false; - min_ss.type = (BatterySnapshotType)kSnapshotType[type]; - max_ss.type = (BatterySnapshotType)(kSnapshotType[type] + 1); + min_ss.type = (IPixelStats::BatterySnapshotType)kSnapshotType[type]; + max_ss.type = (IPixelStats::BatterySnapshotType)(kSnapshotType[type] + 1); + + min_stats_ss.type = (BatteryHealthSnapshotArgs::BatterySnapshotType)kStatsSnapshotType[type]; + max_stats_ss.type = + (BatteryHealthSnapshotArgs::BatterySnapshotType)(kStatsSnapshotType[type] + 1); client->reportBatteryHealthSnapshot(min_ss); client->reportBatteryHealthSnapshot(max_ss); + + stats_client->reportBatteryHealthSnapshot(min_stats_ss); + stats_client->reportBatteryHealthSnapshot(max_stats_ss); + return true; } @@ -87,7 +115,13 @@ bool BatteryMetricsLogger::uploadMetrics(void) { if (num_res_samples_) avg_resistance = accum_resistance_ / num_res_samples_; - LOG(INFO) << "Logging metrics to tron"; + LOG(INFO) << "Logging metrics"; + + sp<IStats> stats_client = IStats::tryGetService(); + if (!stats_client) { + LOG(ERROR) << "Unable to connect to Stats service"; + return false; + } sp<IPixelStats> client = IPixelStats::tryGetService(); if (!client) { @@ -108,14 +142,30 @@ bool BatteryMetricsLogger::uploadMetrics(void) { LOG(INFO) << log_min; LOG(INFO) << log_max; // Upload min/max metrics - uploadOutlierMetric(client, static_cast<sampleType>(metric)); + uploadOutlierMetric(client, stats_client, static_cast<sampleType>(metric)); } // Upload average metric - BatteryHealthSnapshotArgs avg_res_ss = { - BatterySnapshotType::AVG_RESISTANCE, 0, 0, 0, 0, avg_resistance, 0}; - if (num_res_samples_) + IPixelStats::BatteryHealthSnapshotArgs avg_res_ss = { + .type = IPixelStats::BatterySnapshotType::AVG_RESISTANCE, + .temperatureDeciC = 0, + .voltageMicroV = 0, + .currentMicroA = 0, + .openCircuitVoltageMicroV = 0, + .resistanceMicroOhm = avg_resistance, + .levelPercent = 0}; + BatteryHealthSnapshotArgs avg_res_ss_stats = { + .type = BatteryHealthSnapshotArgs::BatterySnapshotType::AVG_RESISTANCE, + .temperatureDeciC = 0, + .voltageMicroV = 0, + .currentMicroA = 0, + .openCircuitVoltageMicroV = 0, + .resistanceMicroOhm = avg_resistance, + .levelPercent = 0}; + if (num_res_samples_) { client->reportBatteryHealthSnapshot(avg_res_ss); + stats_client->reportBatteryHealthSnapshot(avg_res_ss_stats); + } // Clear existing data memset(min_, 0, sizeof(min_)); @@ -149,13 +199,13 @@ bool BatteryMetricsLogger::recordSample(struct android::BatteryProperties *props LOG(ERROR) << "Can't parse open-circuit voltage (ocv) value " << ocv_str; } - int32_t sample[NUM_FIELDS] = {time, - resistance, - props->batteryCurrent, - props->batteryVoltage, - props->batteryTemperature, - props->batteryLevel, - ocv}; + int32_t sample[NUM_FIELDS] = {[TIME] = time, + [RES] = resistance, + [CURR] = props->batteryCurrent, + [VOLT] = props->batteryVoltage, + [TEMP] = props->batteryTemperature, + [SOC] = props->batteryLevel, + [OCV] = ocv}; if (props->batteryStatus != android::BATTERY_STATUS_CHARGING) { accum_resistance_ += resistance; num_res_samples_++; diff --git a/health/LowBatteryShutdownMetrics.cpp b/health/LowBatteryShutdownMetrics.cpp index 68645eb6..11b89cd9 100644 --- a/health/LowBatteryShutdownMetrics.cpp +++ b/health/LowBatteryShutdownMetrics.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#include <android/frameworks/stats/1.0/IStats.h> +#include <hardware/google/pixelstats/1.0/IPixelStats.h> #include <pixelhealth/LowBatteryShutdownMetrics.h> namespace hardware { @@ -27,6 +29,8 @@ using android::sp; using android::base::GetProperty; using android::base::ReadFileToString; using android::base::SetProperty; +using android::frameworks::stats::V1_0::BatteryCausedShutdown; +using android::frameworks::stats::V1_0::IStats; using ::hardware::google::pixelstats::V1_0::IPixelStats; LowBatteryShutdownMetrics::LowBatteryShutdownMetrics(const char *const voltage_avg, @@ -44,6 +48,12 @@ bool LowBatteryShutdownMetrics::uploadVoltageAvg(void) { return false; } + sp<IStats> stats_client = IStats::tryGetService(); + if (!stats_client) { + LOG(ERROR) << "Unable to connect to Stats service"; + return false; + } + sp<IPixelStats> client = IPixelStats::tryGetService(); if (!client) { LOG(ERROR) << "Unable to connect to PixelStats service"; @@ -59,6 +69,8 @@ bool LowBatteryShutdownMetrics::uploadVoltageAvg(void) { } LOG(INFO) << "Uploading voltage_avg: " << std::to_string(voltage_avg); client->reportBatteryCausedShutdown(voltage_avg); + BatteryCausedShutdown shutdown = {.voltageMicroV = voltage_avg}; + stats_client->reportBatteryCausedShutdown(shutdown); } // Clear property now that we've uploaded its contents diff --git a/health/include/pixelhealth/BatteryMetricsLogger.h b/health/include/pixelhealth/BatteryMetricsLogger.h index 2c760474..2a92812a 100644 --- a/health/include/pixelhealth/BatteryMetricsLogger.h +++ b/health/include/pixelhealth/BatteryMetricsLogger.h @@ -26,6 +26,7 @@ #include <utils/Timers.h> #include <string> +#include <android/frameworks/stats/1.0/IStats.h> #include <hardware/google/pixelstats/1.0/IPixelStats.h> namespace hardware { @@ -33,7 +34,10 @@ namespace google { namespace pixel { namespace health { -using BatterySnapshotType = ::hardware::google::pixelstats::V1_0::IPixelStats::BatterySnapshotType; +using android::sp; +using android::frameworks::stats::V1_0::BatteryHealthSnapshotArgs; +using android::frameworks::stats::V1_0::IStats; +using ::hardware::google::pixelstats::V1_0::IPixelStats; class BatteryMetricsLogger { public: @@ -55,11 +59,21 @@ class BatteryMetricsLogger { const int kSnapshotType[NUM_FIELDS] = { -1, - (int)BatterySnapshotType::MIN_CURRENT, - (int)BatterySnapshotType::MIN_VOLTAGE, - (int)BatterySnapshotType::MIN_TEMP, - (int)BatterySnapshotType::MIN_BATT_LEVEL, - (int)BatterySnapshotType::MIN_RESISTANCE, + (int)IPixelStats::BatterySnapshotType::MIN_CURRENT, + (int)IPixelStats::BatterySnapshotType::MIN_VOLTAGE, + (int)IPixelStats::BatterySnapshotType::MIN_TEMP, + (int)IPixelStats::BatterySnapshotType::MIN_BATT_LEVEL, + (int)IPixelStats::BatterySnapshotType::MIN_RESISTANCE, + -1, + }; + + const int kStatsSnapshotType[NUM_FIELDS] = { + -1, + (int)BatteryHealthSnapshotArgs::BatterySnapshotType::MIN_CURRENT, + (int)BatteryHealthSnapshotArgs::BatterySnapshotType::MIN_VOLTAGE, + (int)BatteryHealthSnapshotArgs::BatterySnapshotType::MIN_TEMP, + (int)BatteryHealthSnapshotArgs::BatterySnapshotType::MIN_BATT_LEVEL, + (int)BatteryHealthSnapshotArgs::BatterySnapshotType::MIN_RESISTANCE, -1, }; @@ -85,8 +99,7 @@ class BatteryMetricsLogger { int64_t getTime(); bool recordSample(struct android::BatteryProperties *props); bool uploadMetrics(); - bool uploadOutlierMetric(android::sp<::hardware::google::pixelstats::V1_0::IPixelStats> client, - sampleType type); + bool uploadOutlierMetric(sp<IPixelStats> client, sp<IStats> stats_client, sampleType type); }; } // namespace health diff --git a/health/include/pixelhealth/LowBatteryShutdownMetrics.h b/health/include/pixelhealth/LowBatteryShutdownMetrics.h index 2fa7e4b0..7dc3ee6c 100644 --- a/health/include/pixelhealth/LowBatteryShutdownMetrics.h +++ b/health/include/pixelhealth/LowBatteryShutdownMetrics.h @@ -27,8 +27,6 @@ #include <utils/Timers.h> #include <string> -#include <hardware/google/pixelstats/1.0/IPixelStats.h> - namespace hardware { namespace google { namespace pixel { |