diff options
| author | Maggie White <maggiewhite@google.com> | 2019-04-19 10:23:14 -0700 |
|---|---|---|
| committer | Maggie White <maggiewhite@google.com> | 2019-04-22 18:14:34 -0700 |
| commit | 4122b0cd017bdc5199f5cf76752fc2c0d1cc692a (patch) | |
| tree | 92ed8a74747c05550c7d7e12fb23e70b4e2232f7 /pixelstats | |
| parent | 244e51375e86c225b50380d8055467e6c2632903 (diff) | |
| download | platform_hardware_google_pixel-4122b0cd017bdc5199f5cf76752fc2c0d1cc692a.tar.gz platform_hardware_google_pixel-4122b0cd017bdc5199f5cf76752fc2c0d1cc692a.tar.bz2 platform_hardware_google_pixel-4122b0cd017bdc5199f5cf76752fc2c0d1cc692a.zip | |
pixelstats: Upload alternate battery capacity
Upload an alternative battery capacity calculation once a day via
SysfsCollector.
Bug: 120439050
Test: Decrease log frequency to 30 seconds and observe following log:
statsd : { uid(1066) 1555981987000000000 368264161579 (105002)0x10000->com.google.pixel[S] 0x20000->0[I] 0x30000->0[I] }
Change-Id: Ib62420031a9a529782dc476dffe251dceaa51f8e
Signed-off-by: Maggie White <maggiewhite@google.com>
Diffstat (limited to 'pixelstats')
| -rw-r--r-- | pixelstats/SysfsCollector.cpp | 57 | ||||
| -rw-r--r-- | pixelstats/include/pixelstats/SysfsCollector.h | 12 | ||||
| -rw-r--r-- | pixelstats/pixelatoms.proto | 9 |
3 files changed, 77 insertions, 1 deletions
diff --git a/pixelstats/SysfsCollector.cpp b/pixelstats/SysfsCollector.cpp index c0909b7..f588c41 100644 --- a/pixelstats/SysfsCollector.cpp +++ b/pixelstats/SysfsCollector.cpp @@ -22,6 +22,7 @@ #include <android-base/parseint.h> #include <android-base/strings.h> #include <android/frameworks/stats/1.0/IStats.h> +#include <hardware/google/pixel/pixelstats/pixelatoms.pb.h> #include <utils/Log.h> #include <utils/StrongPointer.h> #include <utils/Timers.h> @@ -42,6 +43,8 @@ using android::frameworks::stats::V1_0::IStats; using android::frameworks::stats::V1_0::SlowIo; using android::frameworks::stats::V1_0::SpeakerImpedance; using android::frameworks::stats::V1_0::SpeechDspStat; +using android::frameworks::stats::V1_0::VendorAtom; +using android::hardware::google::pixel::PixelAtoms::BatteryCapacity; SysfsCollector::SysfsCollector(const struct SysfsPaths &sysfs_paths) : kSlowioReadCntPath(sysfs_paths.SlowioReadCntPath), @@ -52,7 +55,26 @@ SysfsCollector::SysfsCollector(const struct SysfsPaths &sysfs_paths) kImpedancePath(sysfs_paths.ImpedancePath), kCodecPath(sysfs_paths.CodecPath), kCodec1Path(sysfs_paths.Codec1Path), - kSpeechDspPath(sysfs_paths.SpeechDspPath) {} + kSpeechDspPath(sysfs_paths.SpeechDspPath), + kBatteryCapacityCC(sysfs_paths.BatteryCapacityCC), + kBatteryCapacityVFSOC(sysfs_paths.BatteryCapacityVFSOC) {} + +bool SysfsCollector::ReadFileToInt(const std::string &path, int *val) { + return ReadFileToInt(path.c_str(), val); +} + +bool SysfsCollector::ReadFileToInt(const char *const path, int *val) { + std::string file_contents; + + if (!ReadFileToString(path, &file_contents)) { + ALOGE("Unable to read %s - %s", path, strerror(errno)); + return false; + } else if (sscanf(file_contents.c_str(), "%d", val) != 1) { + ALOGE("Unable to convert %s to int - %s", path, strerror(errno)); + return false; + } + return true; +} /** * Read the contents of kCycleCountBinsPath and report them via IStats HAL. @@ -223,6 +245,38 @@ void SysfsCollector::logSpeechDspStat() { stats_->reportSpeechDspStat(dspstat); } +void SysfsCollector::logBatteryCapacity() { + std::string file_contents; + if (kBatteryCapacityCC == nullptr || strlen(kBatteryCapacityCC) == 0) { + ALOGV("Battery Capacity CC path not specified"); + return; + } + if (kBatteryCapacityVFSOC == nullptr || strlen(kBatteryCapacityVFSOC) == 0) { + ALOGV("Battery Capacity VFSOC path not specified"); + return; + } + int delta_cc_sum, delta_vfsoc_sum; + if (!ReadFileToInt(kBatteryCapacityCC, &delta_cc_sum) || + !ReadFileToInt(kBatteryCapacityVFSOC, &delta_vfsoc_sum)) + return; + + // Load values array + std::vector<VendorAtom::Value> values(2); + VendorAtom::Value tmp; + tmp.intValue(delta_cc_sum); + values[BatteryCapacity::kDeltaCcSumFieldNumber - kVendorAtomOffset] = tmp; + tmp.intValue(delta_vfsoc_sum); + values[BatteryCapacity::kDeltaVfsocSumFieldNumber - kVendorAtomOffset] = tmp; + + // Send vendor atom to IStats HAL + VendorAtom event = {.reverseDomainName = PixelAtoms::ReverseDomainNames().pixel(), + .atomId = PixelAtoms::Ids::BATTERY_CAPACITY, + .values = values}; + Return<void> ret = stats_->reportVendorAtom(event); + if (!ret.isOk()) + ALOGE("Unable to report ChargeStats to Stats service"); +} + void SysfsCollector::logAll() { stats_ = IStats::tryGetService(); if (!stats_) { @@ -236,6 +290,7 @@ void SysfsCollector::logAll() { logSlowIO(); logSpeakerImpedance(); logSpeechDspStat(); + logBatteryCapacity(); stats_.clear(); } diff --git a/pixelstats/include/pixelstats/SysfsCollector.h b/pixelstats/include/pixelstats/SysfsCollector.h index 0d475f1..d784ed5 100644 --- a/pixelstats/include/pixelstats/SysfsCollector.h +++ b/pixelstats/include/pixelstats/SysfsCollector.h @@ -41,12 +41,16 @@ class SysfsCollector { const char *const CodecPath; const char *const Codec1Path; const char *const SpeechDspPath; + const char *const BatteryCapacityCC; + const char *const BatteryCapacityVFSOC; }; SysfsCollector(const struct SysfsPaths &paths); void collect(); private: + bool ReadFileToInt(const std::string &path, int *val); + bool ReadFileToInt(const char *path, int *val); void logAll(); void logBatteryChargeCycles(); @@ -55,6 +59,7 @@ class SysfsCollector { void logSlowIO(); void logSpeakerImpedance(); void logSpeechDspStat(); + void logBatteryCapacity(); void reportSlowIoFromFile(const char *path, const SlowIo::IoOperation &operation_s); @@ -67,7 +72,14 @@ class SysfsCollector { const char *const kCodecPath; const char *const kCodec1Path; const char *const kSpeechDspPath; + const char *const kBatteryCapacityCC; + const char *const kBatteryCapacityVFSOC; sp<IStats> stats_; + + // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so + // store everything in the values array at the index of the field number + // -2. + const int kVendorAtomOffset = 2; }; } // namespace pixel diff --git a/pixelstats/pixelatoms.proto b/pixelstats/pixelatoms.proto index 1ab9e30..ab6509f 100644 --- a/pixelstats/pixelatoms.proto +++ b/pixelstats/pixelatoms.proto @@ -36,6 +36,7 @@ enum Ids { // AOSP atom ID range starts at 105000 CHARGE_STATS = 105000; VOLTAGE_TIER_STATS = 105001; + BATTERY_CAPACITY = 105002; // AOSP atom ID range ends at 109999 } @@ -119,3 +120,11 @@ message VoltageTierStats { optional int32 icl_avg = 16; optional int32 icl_max = 17; } + +/* A message containing an alternate proprietary full battery capacity estimate. */ +message BatteryCapacity { + /* Sum of the change in coulomb count. */ + optional int32 delta_cc_sum = 2; + /* Sum of the change in state of charge (battery level). */ + optional int32 delta_vfsoc_sum = 3; +} |
