1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef HARDWARE_GOOGLE_PIXEL_PIXELSTATS_SYSFSCOLLECTOR_H 18 #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_SYSFSCOLLECTOR_H 19 20 #include <aidl/android/frameworks/stats/IStats.h> 21 #include <hardware/google/pixel/pixelstats/pixelatoms.pb.h> 22 23 #include "BatteryEEPROMReporter.h" 24 #include "BatteryHealthReporter.h" 25 #include "BrownoutDetectedReporter.h" 26 #include "DisplayStatsReporter.h" 27 #include "MitigationDurationReporter.h" 28 #include "MitigationStatsReporter.h" 29 #include "MmMetricsReporter.h" 30 #include "TempResidencyReporter.h" 31 #include "ThermalStatsReporter.h" 32 33 namespace android { 34 namespace hardware { 35 namespace google { 36 namespace pixel { 37 38 using aidl::android::frameworks::stats::IStats; 39 using android::hardware::google::pixel::PixelAtoms::VendorSlowIo; 40 41 class SysfsCollector { 42 public: 43 struct SysfsPaths { 44 const char *const SlowioReadCntPath; 45 const char *const SlowioWriteCntPath; 46 const char *const SlowioUnmapCntPath; 47 const char *const SlowioSyncCntPath; 48 const char *const CycleCountBinsPath; 49 const char *const ImpedancePath; 50 const char *const CodecPath; 51 const char *const Codec1Path; 52 const char *const SpeechDspPath; 53 const char *const BatteryCapacityCC; 54 const char *const BatteryCapacityVFSOC; 55 const char *const UFSLifetimeA; 56 const char *const UFSLifetimeB; 57 const char *const UFSLifetimeC; 58 const char *const F2fsStatsPath; 59 const char *const UserdataBlockProp; 60 const char *const ZramMmStatPath; 61 const char *const ZramBdStatPath; 62 const char *const EEPROMPath; 63 const char *const MitigationPath; 64 const char *const MitigationDurationPath; 65 const char *const BrownoutLogPath; 66 const char *const BrownoutReasonProp; 67 const char *const SpeakerTemperaturePath; 68 const char *const SpeakerExcursionPath; 69 const char *const SpeakerHeartBeatPath; 70 const std::vector<std::string> UFSErrStatsPath; 71 const int BlockStatsLength; 72 const char *const AmsRatePath; 73 const std::vector<std::string> ThermalStatsPaths; 74 const std::vector<std::string> DisplayStatsPaths; 75 const char *const CCARatePath; 76 const std::vector<std::pair<std::string, std::string>> TempResidencyAndResetPaths; 77 const char *const LongIRQMetricsPath; 78 const char *const StormIRQMetricsPath; 79 const char *const IRQStatsResetPath; 80 const char *const ResumeLatencyMetricsPath; 81 const char *const ModemPcieLinkStatsPath; 82 const char *const WifiPcieLinkStatsPath; 83 const char *const PDMStatePath; 84 const char *const WavesPath; 85 const char *const AdaptedInfoCountPath; 86 const char *const AdaptedInfoDurationPath; 87 const char *const PcmLatencyPath; 88 const char *const PcmCountPath; 89 const char *const TotalCallCountPath; 90 }; 91 92 SysfsCollector(const struct SysfsPaths &paths); 93 void collect(); 94 95 private: 96 bool ReadFileToInt(const std::string &path, int *val); 97 bool ReadFileToInt(const char *path, int *val); 98 void aggregatePer5Min(); 99 void logOnce(); 100 void logBrownout(); 101 void logPerDay(); 102 void logPerHour(); 103 104 void logBatteryChargeCycles(const std::shared_ptr<IStats> &stats_client); 105 void logBatteryHealth(const std::shared_ptr<IStats> &stats_client); 106 void logBlockStatsReported(const std::shared_ptr<IStats> &stats_client); 107 void logCodecFailed(const std::shared_ptr<IStats> &stats_client); 108 void logCodec1Failed(const std::shared_ptr<IStats> &stats_client); 109 void logSlowIO(const std::shared_ptr<IStats> &stats_client); 110 void logSpeakerImpedance(const std::shared_ptr<IStats> &stats_client); 111 void logSpeechDspStat(const std::shared_ptr<IStats> &stats_client); 112 void logBatteryCapacity(const std::shared_ptr<IStats> &stats_client); 113 void logUFSLifetime(const std::shared_ptr<IStats> &stats_client); 114 void logUFSErrorStats(const std::shared_ptr<IStats> &stats_client); 115 void logF2fsStats(const std::shared_ptr<IStats> &stats_client); 116 void logF2fsAtomicWriteInfo(const std::shared_ptr<IStats> &stats_client); 117 void logF2fsCompressionInfo(const std::shared_ptr<IStats> &stats_client); 118 void logF2fsGcSegmentInfo(const std::shared_ptr<IStats> &stats_client); 119 void logZramStats(const std::shared_ptr<IStats> &stats_client); 120 void logBootStats(const std::shared_ptr<IStats> &stats_client); 121 void logBatteryEEPROM(const std::shared_ptr<IStats> &stats_client); 122 void logSpeakerHealthStats(const std::shared_ptr<IStats> &stats_client); 123 void logF2fsSmartIdleMaintEnabled(const std::shared_ptr<IStats> &stats_client); 124 void logThermalStats(const std::shared_ptr<IStats> &stats_client); 125 void logMitigationDurationCounts(const std::shared_ptr<IStats> &stats_client); 126 void logDisplayStats(const std::shared_ptr<IStats> &stats_client); 127 void logVendorAudioPdmStatsReported(const std::shared_ptr<IStats> &stats_client); 128 129 void reportSlowIoFromFile(const std::shared_ptr<IStats> &stats_client, const char *path, 130 const VendorSlowIo::IoOperation &operation_s); 131 void logTempResidencyStats(const std::shared_ptr<IStats> &stats_client); 132 void reportZramMmStat(const std::shared_ptr<IStats> &stats_client); 133 void reportZramBdStat(const std::shared_ptr<IStats> &stats_client); 134 int getReclaimedSegments(const std::string &mode); 135 void logVendorAudioHardwareStats(const std::shared_ptr<IStats> &stats_client); 136 void logVendorLongIRQStatsReported(const std::shared_ptr<IStats> &stats_client); 137 void logVendorResumeLatencyStats(const std::shared_ptr<IStats> &stats_client); 138 void logPartitionUsedSpace(const std::shared_ptr<IStats> &stats_client); 139 void logPcieLinkStats(const std::shared_ptr<IStats> &stats_client); 140 void logWavesStats(const std::shared_ptr<IStats> &stats_client); 141 void logAdaptedInfoStats(const std::shared_ptr<IStats> &stats_client); 142 void logPcmUsageStats(const std::shared_ptr<IStats> &stats_client); 143 144 const char *const kSlowioReadCntPath; 145 const char *const kSlowioWriteCntPath; 146 const char *const kSlowioUnmapCntPath; 147 const char *const kSlowioSyncCntPath; 148 const char *const kCycleCountBinsPath; 149 const char *const kImpedancePath; 150 const char *const kCodecPath; 151 const char *const kCodec1Path; 152 const char *const kSpeechDspPath; 153 const char *const kBatteryCapacityCC; 154 const char *const kBatteryCapacityVFSOC; 155 const char *const kUFSLifetimeA; 156 const char *const kUFSLifetimeB; 157 const char *const kUFSLifetimeC; 158 const char *const kF2fsStatsPath; 159 const char *const kZramMmStatPath; 160 const char *const kZramBdStatPath; 161 const char *const kEEPROMPath; 162 const char *const kBrownoutLogPath; 163 const char *const kBrownoutReasonProp; 164 const char *const kPowerMitigationStatsPath; 165 const char *const kPowerMitigationDurationPath; 166 const char *const kSpeakerTemperaturePath; 167 const char *const kSpeakerExcursionPath; 168 const char *const kSpeakerHeartbeatPath; 169 const std::vector<std::string> kUFSErrStatsPath; 170 const int kBlockStatsLength; 171 const char *const kAmsRatePath; 172 const std::vector<std::string> kThermalStatsPaths; 173 const char *const kCCARatePath; 174 const std::vector<std::pair<std::string, std::string>> kTempResidencyAndResetPaths; 175 const char *const kLongIRQMetricsPath; 176 const char *const kStormIRQMetricsPath; 177 const char *const kIRQStatsResetPath; 178 const char *const kResumeLatencyMetricsPath; 179 const char *const kModemPcieLinkStatsPath; 180 const char *const kWifiPcieLinkStatsPath; 181 const std::vector<std::string> kDisplayStatsPaths; 182 const char *const kPDMStatePath; 183 const char *const kWavesPath; 184 const char *const kAdaptedInfoCountPath; 185 const char *const kAdaptedInfoDurationPath; 186 const char *const kPcmLatencyPath; 187 const char *const kPcmCountPath; 188 const char *const kTotalCallCountPath; 189 190 BatteryEEPROMReporter battery_EEPROM_reporter_; 191 MmMetricsReporter mm_metrics_reporter_; 192 MitigationStatsReporter mitigation_stats_reporter_; 193 MitigationDurationReporter mitigation_duration_reporter_; 194 BrownoutDetectedReporter brownout_detected_reporter_; 195 ThermalStatsReporter thermal_stats_reporter_; 196 DisplayStatsReporter display_stats_reporter_; 197 BatteryHealthReporter battery_health_reporter_; 198 TempResidencyReporter temp_residency_reporter_; 199 // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so 200 // store everything in the values array at the index of the field number 201 // -2. 202 const int kVendorAtomOffset = 2; 203 204 bool log_once_reported = false; 205 int64_t prev_huge_pages_since_boot_ = -1; 206 207 struct perf_metrics_data { 208 uint64_t resume_latency_sum_ms; 209 int64_t resume_count; 210 std::vector<int64_t> resume_latency_buckets; 211 int bucket_cnt; 212 }; 213 struct perf_metrics_data prev_data; 214 const int kMaxResumeLatencyBuckets = 36; 215 }; 216 217 } // namespace pixel 218 } // namespace google 219 } // namespace hardware 220 } // namespace android 221 222 #endif // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_SYSFSCOLLECTOR_H 223