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 /pixelstats | |
| parent | a83752ae2250517c076952de230db4689bf0244b (diff) | |
| download | platform_hardware_google_pixel-a30ceaf6a0e26189126cfcc7a3514d2591c09bcd.tar.gz platform_hardware_google_pixel-a30ceaf6a0e26189126cfcc7a3514d2591c09bcd.tar.bz2 platform_hardware_google_pixel-a30ceaf6a0e26189126cfcc7a3514d2591c09bcd.zip | |
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 'pixelstats')
| -rw-r--r-- | pixelstats/Android.bp | 4 | ||||
| -rw-r--r-- | pixelstats/DropDetect.cpp | 29 | ||||
| -rw-r--r-- | pixelstats/SysfsCollector.cpp | 38 | ||||
| -rw-r--r-- | pixelstats/UeventListener.cpp | 28 | ||||
| -rw-r--r-- | pixelstats/include/pixelstats/SysfsCollector.h | 14 |
5 files changed, 88 insertions, 25 deletions
diff --git a/pixelstats/Android.bp b/pixelstats/Android.bp index b2fe18d..c98c634 100644 --- a/pixelstats/Android.bp +++ b/pixelstats/Android.bp @@ -28,6 +28,7 @@ cc_library { "-Werror", ], shared_libs: [ + "android.frameworks.stats@1.0", "hardware.google.pixelstats@1.0", "libbase", "libbinder", @@ -37,6 +38,9 @@ cc_library { "liblog", "libutils", ], + export_shared_lib_headers: [ + "android.frameworks.stats@1.0", + ], static_libs: ["chre_client"], header_libs: ["chre_api"], } diff --git a/pixelstats/DropDetect.cpp b/pixelstats/DropDetect.cpp index a46edb1..e61d1ee 100644 --- a/pixelstats/DropDetect.cpp +++ b/pixelstats/DropDetect.cpp @@ -19,6 +19,7 @@ #include <chre_host/host_protocol_host.h> #include <chre_host/socket_client.h> +#include <android/frameworks/stats/1.0/IStats.h> #include <hardware/google/pixelstats/1.0/IPixelStats.h> #define LOG_TAG "pixelstats-vendor" #include <log/log.h> @@ -29,6 +30,9 @@ using android::sp; using android::chre::HostProtocolHost; using android::chre::IChreMessageHandlers; using android::chre::SocketClient; +using android::frameworks::stats::V1_0::IStats; +using android::frameworks::stats::V1_0::PhysicalDropDetected; +using ::hardware::google::pixelstats::V1_0::IPixelStats; // following convention of CHRE code. namespace fbs = ::chre::fbs; @@ -122,19 +126,26 @@ void DropDetect::handleNanoappMessage(const fbs::NanoappMessageT &message) { message.message.size() < sizeof(struct DropEventPayload)) return; message_struct = (struct DropEventPayload *)&message.message[0]; - /* - * ALOGI("Received drop detect message! Confidence %f Peak %f Duration %g", - * message_struct->confidence, message_struct->accel_magnitude_peak, - * message_struct->free_fall_duration_ns / 1e9); - */ - int32_t confidence = message_struct->confidence * 100; - confidence = std::min(confidence, 100); - confidence = std::max(0, confidence); + ALOGI("Received drop detect message! Confidence %f Peak %f Duration %g", + message_struct->confidence, message_struct->accel_magnitude_peak, + message_struct->free_fall_duration_ns / 1e9); + uint8_t confidence = message_struct->confidence * 100; + confidence = std::min<int>(confidence, 100); + confidence = std::max<int>(0, confidence); int32_t accel_magnitude_peak_1000ths_g = message_struct->accel_magnitude_peak * 1000.0; int32_t free_fall_duration_ms = message_struct->free_fall_duration_ns / 1000000; - using ::hardware::google::pixelstats::V1_0::IPixelStats; + sp<IStats> stats_client = IStats::tryGetService(); + if (stats_client) { + PhysicalDropDetected drop = {confidence, accel_magnitude_peak_1000ths_g, + free_fall_duration_ms}; + Return<void> ret = stats_client->reportPhysicalDropDetected(drop); + if (!ret.isOk()) + ALOGE("Unable to report physical drop to Stats service"); + } else + ALOGE("Unable to connect to Stats service"); + sp<IPixelStats> client = IPixelStats::tryGetService(); if (!client) { ALOGE("Unable to connect to PixelStats service"); diff --git a/pixelstats/SysfsCollector.cpp b/pixelstats/SysfsCollector.cpp index 1886192..e086698 100644 --- a/pixelstats/SysfsCollector.cpp +++ b/pixelstats/SysfsCollector.cpp @@ -21,6 +21,7 @@ #include <android-base/file.h> #include <android-base/parseint.h> #include <android-base/strings.h> +#include <android/frameworks/stats/1.0/IStats.h> #include <hardware/google/pixelstats/1.0/IPixelStats.h> #include <utils/Log.h> #include <utils/StrongPointer.h> @@ -36,6 +37,11 @@ namespace pixel { using android::sp; using android::base::ReadFileToString; +using android::frameworks::stats::V1_0::ChargeCycles; +using android::frameworks::stats::V1_0::HardwareFailed; +using android::frameworks::stats::V1_0::IStats; +using android::frameworks::stats::V1_0::SlowIo; +using android::frameworks::stats::V1_0::SpeakerImpedance; using ::hardware::google::pixelstats::V1_0::IPixelStats; SysfsCollector::SysfsCollector(const struct SysfsPaths &sysfs_paths) @@ -83,13 +89,18 @@ void SysfsCollector::logCodecFailed() { if (file_contents == "0") { return; } else { + HardwareFailed failed = {.hardwareType = HardwareFailed::HardwareType::CODEC, + .hardwareLocation = 0, + .errorCode = HardwareFailed::HardwareErrorCode::COMPLETE}; + stats_->reportHardwareFailed(failed); pixelstats_->reportHardwareFailed(IPixelStats::HardwareType::CODEC, 0, IPixelStats::HardwareErrorCode::COMPLETE); } } void SysfsCollector::reportSlowIoFromFile(const char *path, - const IPixelStats::IoOperation &operation) { + const IPixelStats::IoOperation &operation, + const SlowIo::IoOperation &operation_s) { std::string file_contents; if (strlen(path) == 0) { ALOGV("slow_io path not specified"); @@ -103,6 +114,8 @@ void SysfsCollector::reportSlowIoFromFile(const char *path, if (sscanf(file_contents.c_str(), "%d", &slow_io_count) != 1) { ALOGE("Unable to parse %s from file %s to int.", file_contents.c_str(), path); } else if (slow_io_count > 0) { + SlowIo slowio = {.operation = operation_s, .count = slow_io_count}; + stats_->reportSlowIo(slowio); pixelstats_->reportSlowIo(operation, slow_io_count); } // Clear the stats @@ -116,10 +129,14 @@ void SysfsCollector::reportSlowIoFromFile(const char *path, * Check for slow IO operations. */ void SysfsCollector::logSlowIO() { - reportSlowIoFromFile(kSlowioReadCntPath, IPixelStats::IoOperation::READ); - reportSlowIoFromFile(kSlowioWriteCntPath, IPixelStats::IoOperation::WRITE); - reportSlowIoFromFile(kSlowioUnmapCntPath, IPixelStats::IoOperation::UNMAP); - reportSlowIoFromFile(kSlowioSyncCntPath, IPixelStats::IoOperation::SYNC); + reportSlowIoFromFile(kSlowioReadCntPath, IPixelStats::IoOperation::READ, + SlowIo::IoOperation::READ); + reportSlowIoFromFile(kSlowioWriteCntPath, IPixelStats::IoOperation::WRITE, + SlowIo::IoOperation::WRITE); + reportSlowIoFromFile(kSlowioUnmapCntPath, IPixelStats::IoOperation::UNMAP, + SlowIo::IoOperation::UNMAP); + reportSlowIoFromFile(kSlowioSyncCntPath, IPixelStats::IoOperation::SYNC, + SlowIo::IoOperation::SYNC); } /** @@ -141,11 +158,22 @@ void SysfsCollector::logSpeakerImpedance() { ALOGE("Unable to parse speaker impedance %s", file_contents.c_str()); return; } + SpeakerImpedance left_obj = {.speakerLocation = 0, + .milliOhms = static_cast<int32_t>(left * 1000)}; + SpeakerImpedance right_obj = {.speakerLocation = 0, + .milliOhms = static_cast<int32_t>(right * 1000)}; + stats_->reportSpeakerImpedance(left_obj); + stats_->reportSpeakerImpedance(right_obj); pixelstats_->reportSpeakerImpedance(0, left * 1000); pixelstats_->reportSpeakerImpedance(1, right * 1000); } void SysfsCollector::logAll() { + stats_ = IStats::tryGetService(); + if (!stats_) { + ALOGE("Unable to connect to Stats service"); + return; + } pixelstats_ = IPixelStats::tryGetService(); if (!pixelstats_) { ALOGE("Unable to connect to PixelStats service"); diff --git a/pixelstats/UeventListener.cpp b/pixelstats/UeventListener.cpp index 02477b1..0908382 100644 --- a/pixelstats/UeventListener.cpp +++ b/pixelstats/UeventListener.cpp @@ -21,6 +21,7 @@ #include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/strings.h> +#include <android/frameworks/stats/1.0/IStats.h> #include <cutils/uevent.h> #include <hardware/google/pixelstats/1.0/IPixelStats.h> #include <log/log.h> @@ -29,6 +30,11 @@ #include <unistd.h> #include <thread> +using android::sp; +using android::frameworks::stats::V1_0::HardwareFailed; +using android::frameworks::stats::V1_0::IStats; +using ::hardware::google::pixelstats::V1_0::IPixelStats; + namespace android { namespace hardware { namespace google { @@ -38,7 +44,6 @@ constexpr int32_t UEVENT_MSG_LEN = 2048; // it's 2048 in all other users. // Report connection & disconnection of devices into the USB-C connector. void UeventListener::ReportUsbConnectorUevents(const char *power_supply_typec_mode) { - using ::hardware::google::pixelstats::V1_0::IPixelStats; if (!power_supply_typec_mode) { // No mode reported -> No reporting. return; @@ -51,7 +56,7 @@ void UeventListener::ReportUsbConnectorUevents(const char *power_supply_typec_mo } is_usb_attached_ = attached; - android::sp<IPixelStats> client = IPixelStats::tryGetService(); + sp<IPixelStats> client = IPixelStats::tryGetService(); if (!client) { ALOGE("Unable to connect to PixelStats service"); return; @@ -105,7 +110,6 @@ void UeventListener::ReportUsbAudioUevents(const char *driver, const char *produ * it on disconnect. This also means we will only report the first USB audio device attached * to the system. Only attempt to connect to the HAL when reporting an event. */ - using ::hardware::google::pixelstats::V1_0::IPixelStats; if (!attached_product_ && !strcmp(action, "ACTION=add")) { if (!driver || strcmp(driver, "DRIVER=snd-usb-audio")) { return; @@ -113,7 +117,7 @@ void UeventListener::ReportUsbAudioUevents(const char *driver, const char *produ usb_audio_connect_time_ = android::base::Timer(); attached_product_ = strdup(product); - android::sp<IPixelStats> client = IPixelStats::tryGetService(); + sp<IPixelStats> client = IPixelStats::tryGetService(); if (!client) { ALOGE("Couldn't connect to PixelStats service for audio connect"); return; @@ -127,7 +131,7 @@ void UeventListener::ReportUsbAudioUevents(const char *driver, const char *produ free(attached_product_); attached_product_ = NULL; - android::sp<IPixelStats> client = IPixelStats::tryGetService(); + sp<IPixelStats> client = IPixelStats::tryGetService(); if (!client) { ALOGE("Couldn't connect to PixelStats service for audio disconnect"); return; @@ -141,8 +145,18 @@ void UeventListener::ReportMicBroken(const char *devpath, const char *mic_break_ return; if (!strcmp(devpath, ("DEVPATH=" + kAudioUevent).c_str()) && !strcmp(mic_break_status, "MIC_BREAK_STATUS=true")) { - using ::hardware::google::pixelstats::V1_0::IPixelStats; - android::sp<IPixelStats> client = IPixelStats::tryGetService(); + sp<IStats> stats_client = IStats::tryGetService(); + if (stats_client) { + HardwareFailed failure = {.hardwareType = HardwareFailed::HardwareType::MICROPHONE, + .hardwareLocation = 0, + .errorCode = HardwareFailed::HardwareErrorCode::COMPLETE}; + Return<void> ret = stats_client->reportHardwareFailed(failure); + if (!ret.isOk()) + ALOGE("Unable to report physical drop to Stats service"); + } else + ALOGE("Unable to connect to Stats service"); + + sp<IPixelStats> client = IPixelStats::tryGetService(); if (!client) { ALOGE("Couldn't connect to PixelStats service for mic break"); return; diff --git a/pixelstats/include/pixelstats/SysfsCollector.h b/pixelstats/include/pixelstats/SysfsCollector.h index 75df1cf..b415508 100644 --- a/pixelstats/include/pixelstats/SysfsCollector.h +++ b/pixelstats/include/pixelstats/SysfsCollector.h @@ -17,9 +17,15 @@ #ifndef HARDWARE_GOOGLE_PIXEL_PIXELSTATS_SYSFSCOLLECTOR_H #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_SYSFSCOLLECTOR_H +#include <android/frameworks/stats/1.0/IStats.h> #include <hardware/google/pixelstats/1.0/IPixelStats.h> #include <utils/StrongPointer.h> +using android::sp; +using android::frameworks::stats::V1_0::IStats; +using android::frameworks::stats::V1_0::SlowIo; +using ::hardware::google::pixelstats::V1_0::IPixelStats; + namespace android { namespace hardware { namespace google { @@ -48,9 +54,8 @@ class SysfsCollector { void logSlowIO(); void logSpeakerImpedance(); - void reportSlowIoFromFile( - const char *path, - const ::hardware::google::pixelstats::V1_0::IPixelStats::IoOperation &operation); + void reportSlowIoFromFile(const char *path, const IPixelStats::IoOperation &operation, + const SlowIo::IoOperation &operation_s); const char *const kSlowioReadCntPath; const char *const kSlowioWriteCntPath; @@ -59,7 +64,8 @@ class SysfsCollector { const char *const kCycleCountBinsPath; const char *const kImpedancePath; const char *const kCodecPath; - android::sp<::hardware::google::pixelstats::V1_0::IPixelStats> pixelstats_; + sp<IPixelStats> pixelstats_; + sp<IStats> stats_; }; } // namespace pixel |
