diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp index 69fbf1f9d8816..9ac888ba2eb58 100644 --- a/cmds/statsd/src/StatsService.cpp +++ b/cmds/statsd/src/StatsService.cpp @@ -1229,70 +1229,81 @@ Status StatsService::sendBinaryPushStateChangedAtom(const android::String16& tra hardware::Return StatsService::reportSpeakerImpedance( const SpeakerImpedance& speakerImpedance) { - LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), speakerImpedance); - mProcessor->OnLogEvent(&event); + android::util::stats_write(android::util::SPEAKER_IMPEDANCE_REPORTED, + speakerImpedance.speakerLocation, speakerImpedance.milliOhms); return hardware::Void(); } hardware::Return StatsService::reportHardwareFailed(const HardwareFailed& hardwareFailed) { - LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), hardwareFailed); - mProcessor->OnLogEvent(&event); + android::util::stats_write(android::util::HARDWARE_FAILED, int32_t(hardwareFailed.hardwareType), + hardwareFailed.hardwareLocation, int32_t(hardwareFailed.errorCode)); return hardware::Void(); } hardware::Return StatsService::reportPhysicalDropDetected( const PhysicalDropDetected& physicalDropDetected) { - LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), physicalDropDetected); - mProcessor->OnLogEvent(&event); + android::util::stats_write(android::util::PHYSICAL_DROP_DETECTED, + int32_t(physicalDropDetected.confidencePctg), physicalDropDetected.accelPeak, + physicalDropDetected.freefallDuration); return hardware::Void(); } hardware::Return StatsService::reportChargeCycles(const ChargeCycles& chargeCycles) { - LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), chargeCycles); - mProcessor->OnLogEvent(&event); + std::vector buckets = chargeCycles.cycleBucket; + int initialSize = buckets.size(); + for (int i = 0; i < 10 - initialSize; i++) { + buckets.push_back(-1); // Push -1 for buckets that do not exist. + } + android::util::stats_write(android::util::CHARGE_CYCLES_REPORTED, buckets[0], buckets[1], + buckets[2], buckets[3], buckets[4], buckets[5], buckets[6], buckets[7], buckets[8], + buckets[9]); return hardware::Void(); } hardware::Return StatsService::reportBatteryHealthSnapshot( const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs) { - LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), - batteryHealthSnapshotArgs); - mProcessor->OnLogEvent(&event); + android::util::stats_write(android::util::BATTERY_HEALTH_SNAPSHOT, + int32_t(batteryHealthSnapshotArgs.type), batteryHealthSnapshotArgs.temperatureDeciC, + batteryHealthSnapshotArgs.voltageMicroV, batteryHealthSnapshotArgs.currentMicroA, + batteryHealthSnapshotArgs.openCircuitVoltageMicroV, + batteryHealthSnapshotArgs.resistanceMicroOhm, batteryHealthSnapshotArgs.levelPercent); return hardware::Void(); } hardware::Return StatsService::reportSlowIo(const SlowIo& slowIo) { - LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), slowIo); - mProcessor->OnLogEvent(&event); + android::util::stats_write(android::util::SLOW_IO, int32_t(slowIo.operation), slowIo.count); return hardware::Void(); } hardware::Return StatsService::reportBatteryCausedShutdown( const BatteryCausedShutdown& batteryCausedShutdown) { - LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), batteryCausedShutdown); - mProcessor->OnLogEvent(&event); + android::util::stats_write(android::util::BATTERY_CAUSED_SHUTDOWN, + batteryCausedShutdown.voltageMicroV); return hardware::Void(); } hardware::Return StatsService::reportUsbPortOverheatEvent( const UsbPortOverheatEvent& usbPortOverheatEvent) { - LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), usbPortOverheatEvent); - mProcessor->OnLogEvent(&event); + android::util::stats_write(android::util::USB_PORT_OVERHEAT_EVENT_REPORTED, + usbPortOverheatEvent.plugTemperatureDeciC, usbPortOverheatEvent.maxTemperatureDeciC, + usbPortOverheatEvent.timeToOverheat, usbPortOverheatEvent.timeToHysteresis, + usbPortOverheatEvent.timeToInactive); return hardware::Void(); } hardware::Return StatsService::reportSpeechDspStat( const SpeechDspStat& speechDspStat) { - LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), speechDspStat); - mProcessor->OnLogEvent(&event); + android::util::stats_write(android::util::SPEECH_DSP_STAT_REPORTED, + speechDspStat.totalUptimeMillis, speechDspStat.totalDowntimeMillis, + speechDspStat.totalCrashCount, speechDspStat.totalRecoverCount); return hardware::Void(); } diff --git a/cmds/statsd/src/logd/LogEvent.cpp b/cmds/statsd/src/logd/LogEvent.cpp index dec36b54a1cea..0430e4ec9a2d0 100644 --- a/cmds/statsd/src/logd/LogEvent.cpp +++ b/cmds/statsd/src/logd/LogEvent.cpp @@ -21,6 +21,7 @@ #include "statslog.h" #include +#include namespace android { namespace os { @@ -201,141 +202,12 @@ LogEvent::LogEvent(const string& trainName, int64_t trainVersionCode, bool requi mValues.push_back(FieldValue(Field(mTagId, getSimpleField(8)), Value(userId))); } -LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const SpeakerImpedance& speakerImpedance) { - mLogdTimestampNs = wallClockTimestampNs; - mElapsedTimestampNs = elapsedTimestampNs; - mTagId = android::util::SPEAKER_IMPEDANCE_REPORTED; - - mValues.push_back( - FieldValue(Field(mTagId, getSimpleField(1)), Value(speakerImpedance.speakerLocation))); - mValues.push_back( - FieldValue(Field(mTagId, getSimpleField(2)), Value(speakerImpedance.milliOhms))); -} - -LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const HardwareFailed& hardwareFailed) { - mLogdTimestampNs = wallClockTimestampNs; - mElapsedTimestampNs = elapsedTimestampNs; - mTagId = android::util::HARDWARE_FAILED; - - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)), - Value(int32_t(hardwareFailed.hardwareType)))); - mValues.push_back( - FieldValue(Field(mTagId, getSimpleField(2)), Value(hardwareFailed.hardwareLocation))); - mValues.push_back( - FieldValue(Field(mTagId, getSimpleField(3)), Value(int32_t(hardwareFailed.errorCode)))); -} - -LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const PhysicalDropDetected& physicalDropDetected) { - mLogdTimestampNs = wallClockTimestampNs; - mElapsedTimestampNs = elapsedTimestampNs; - mTagId = android::util::PHYSICAL_DROP_DETECTED; - - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)), - Value(int32_t(physicalDropDetected.confidencePctg)))); - mValues.push_back( - FieldValue(Field(mTagId, getSimpleField(2)), Value(physicalDropDetected.accelPeak))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(3)), - Value(physicalDropDetected.freefallDuration))); -} - -LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const ChargeCycles& chargeCycles) { - mLogdTimestampNs = wallClockTimestampNs; - mElapsedTimestampNs = elapsedTimestampNs; - mTagId = android::util::CHARGE_CYCLES_REPORTED; - - for (size_t i = 0; i < chargeCycles.cycleBucket.size(); i++) { - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(i + 1)), - Value(chargeCycles.cycleBucket[i]))); - } -} - -LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs) { - mLogdTimestampNs = wallClockTimestampNs; - mElapsedTimestampNs = elapsedTimestampNs; - mTagId = android::util::BATTERY_HEALTH_SNAPSHOT; - - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)), - Value(int32_t(batteryHealthSnapshotArgs.type)))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)), - Value(batteryHealthSnapshotArgs.temperatureDeciC))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(3)), - Value(batteryHealthSnapshotArgs.voltageMicroV))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)), - Value(batteryHealthSnapshotArgs.currentMicroA))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(5)), - Value(batteryHealthSnapshotArgs.openCircuitVoltageMicroV))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(6)), - Value(batteryHealthSnapshotArgs.resistanceMicroOhm))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(7)), - Value(batteryHealthSnapshotArgs.levelPercent))); -} - -LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, const SlowIo& slowIo) { - mLogdTimestampNs = wallClockTimestampNs; - mElapsedTimestampNs = elapsedTimestampNs; - mTagId = android::util::SLOW_IO; - - int pos[] = {1}; - mValues.push_back( - FieldValue(Field(mTagId, getSimpleField(1)), Value(int32_t(slowIo.operation)))); - pos[0]++; - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)), Value(slowIo.count))); -} - -LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const SpeechDspStat& speechDspStat) { - mLogdTimestampNs = wallClockTimestampNs; - mElapsedTimestampNs = elapsedTimestampNs; - mTagId = android::util::SPEECH_DSP_STAT_REPORTED; - - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)), - Value(speechDspStat.totalUptimeMillis))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)), - Value(speechDspStat.totalDowntimeMillis))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(3)), - Value(speechDspStat.totalCrashCount))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)), - Value(speechDspStat.totalRecoverCount))); -} - -LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const BatteryCausedShutdown& batteryCausedShutdown) { - mLogdTimestampNs = wallClockTimestampNs; - mElapsedTimestampNs = elapsedTimestampNs; - mTagId = android::util::BATTERY_CAUSED_SHUTDOWN; - - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)), - Value(batteryCausedShutdown.voltageMicroV))); -} - -LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const UsbPortOverheatEvent& usbPortOverheatEvent) { - mLogdTimestampNs = wallClockTimestampNs; - mElapsedTimestampNs = elapsedTimestampNs; - mTagId = android::util::USB_PORT_OVERHEAT_EVENT_REPORTED; - - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)), - Value(usbPortOverheatEvent.plugTemperatureDeciC))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)), - Value(usbPortOverheatEvent.maxTemperatureDeciC))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(3)), - Value(usbPortOverheatEvent.timeToOverheat))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)), - Value(usbPortOverheatEvent.timeToHysteresis))); - mValues.push_back(FieldValue(Field(mTagId, getSimpleField(5)), - Value(usbPortOverheatEvent.timeToInactive))); -} - LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, const VendorAtom& vendorAtom) { mLogdTimestampNs = wallClockTimestampNs; mElapsedTimestampNs = elapsedTimestampNs; mTagId = vendorAtom.atomId; + mLogUid = AID_STATSD; mValues.push_back( FieldValue(Field(mTagId, getSimpleField(1)), Value(vendorAtom.reverseDomainName))); diff --git a/cmds/statsd/src/logd/LogEvent.h b/cmds/statsd/src/logd/LogEvent.h index 111a619760df5..2fde8b4c027d6 100644 --- a/cmds/statsd/src/logd/LogEvent.h +++ b/cmds/statsd/src/logd/LogEvent.h @@ -107,33 +107,6 @@ public: bool rollbackEnabled, bool requiresLowLatencyMonitor, int32_t state, const std::vector& experimentIds, int32_t userId); - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const SpeakerImpedance& speakerImpedance); - - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const HardwareFailed& hardwareFailed); - - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const PhysicalDropDetected& physicalDropDetected); - - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const ChargeCycles& chargeCycles); - - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs); - - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const SlowIo& slowIo); - - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const BatteryCausedShutdown& batteryCausedShutdown); - - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const UsbPortOverheatEvent& usbPortOverheatEvent); - - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, - const SpeechDspStat& speechDspStat); - explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, const VendorAtom& vendorAtom);