• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "BatteryTTFReporter.h"
26 #include "BrownoutDetectedReporter.h"
27 #include "DisplayStatsReporter.h"
28 #include "MitigationDurationReporter.h"
29 #include "MitigationStatsReporter.h"
30 #include "MmMetricsReporter.h"
31 #include "TempResidencyReporter.h"
32 #include "ThermalStatsReporter.h"
33 
34 namespace android {
35 namespace hardware {
36 namespace google {
37 namespace pixel {
38 
39 using aidl::android::frameworks::stats::IStats;
40 using android::hardware::google::pixel::PixelAtoms::VendorSlowIo;
41 
42 class SysfsCollector {
43   public:
44     struct SysfsPaths {
45         const char *const SlowioReadCntPath;
46         const char *const SlowioWriteCntPath;
47         const char *const SlowioUnmapCntPath;
48         const char *const SlowioSyncCntPath;
49         const char *const CycleCountBinsPath;
50         const char *const ImpedancePath;
51         const char *const CodecPath;
52         const char *const Codec1Path;
53         const char *const SpeechDspPath;
54         const char *const BatteryCapacityCC;
55         const char *const BatteryCapacityVFSOC;
56         const char *const UFSLifetimeA;
57         const char *const UFSLifetimeB;
58         const char *const UFSLifetimeC;
59         const char *const F2fsStatsPath;
60         const char *const UserdataBlockProp;
61         const char *const ZramMmStatPath;
62         const char *const ZramBdStatPath;
63         const char *const EEPROMPath;
64         const char *const MitigationPath;
65         const char *const MitigationDurationPath;
66         const char *const BrownoutCsvPath;
67         const char *const BrownoutLogPath;
68         const char *const BrownoutReasonProp;
69         const char *const SpeakerTemperaturePath;
70         const char *const SpeakerExcursionPath;
71         const char *const SpeakerHeartBeatPath;
72         const std::vector<std::string> UFSErrStatsPath;
73         const int BlockStatsLength;
74         const char *const AmsRatePath;
75         const std::vector<std::string> ThermalStatsPaths;
76         const std::vector<std::string> DisplayStatsPaths;
77         const std::vector<std::string> DisplayPortStatsPaths;
78         const std::vector<std::string> HDCPStatsPaths;
79         const char *const CCARatePath;
80         const std::vector<std::pair<std::string, std::string>> TempResidencyAndResetPaths;
81         const char *const LongIRQMetricsPath;
82         const char *const StormIRQMetricsPath;
83         const char *const IRQStatsResetPath;
84         const char *const ResumeLatencyMetricsPath;
85         const char *const ModemPcieLinkStatsPath;
86         const char *const WifiPcieLinkStatsPath;
87         const char *const PDMStatePath;
88         const char *const WavesPath;
89         const char *const AdaptedInfoCountPath;
90         const char *const AdaptedInfoDurationPath;
91         const char *const PcmLatencyPath;
92         const char *const PcmCountPath;
93         const char *const TotalCallCountPath;
94         const char *const OffloadEffectsIdPath;
95         const char *const OffloadEffectsDurationPath;
96         const char *const BluetoothAudioUsagePath;
97         const std::vector<std::string> GMSRPath;
98         const std::vector<std::string> FGModelLoadingPath;
99         const std::vector<std::string> FGLogBufferPath;
100         const char *const SpeakerVersionPath;
101     };
102 
103     SysfsCollector(const struct SysfsPaths &paths);
104     void collect();
105 
106   private:
107     bool ReadFileToInt(const std::string &path, int *val);
108     bool ReadFileToInt(const char *path, int *val);
109     void aggregatePer5Min();
110     void logOnce();
111     void logBrownout();
112     void logPerDay();
113     void logPerHour();
114 
115     void logBatteryChargeCycles(const std::shared_ptr<IStats> &stats_client);
116     void logBatteryHealth(const std::shared_ptr<IStats> &stats_client);
117     void logBatteryTTF(const std::shared_ptr<IStats> &stats_client);
118     void logBlockStatsReported(const std::shared_ptr<IStats> &stats_client);
119     void logCodecFailed(const std::shared_ptr<IStats> &stats_client);
120     void logCodec1Failed(const std::shared_ptr<IStats> &stats_client);
121     void logSlowIO(const std::shared_ptr<IStats> &stats_client);
122     void logSpeakerImpedance(const std::shared_ptr<IStats> &stats_client);
123     void logSpeechDspStat(const std::shared_ptr<IStats> &stats_client);
124     void logBatteryCapacity(const std::shared_ptr<IStats> &stats_client);
125     void logUFSLifetime(const std::shared_ptr<IStats> &stats_client);
126     void logUFSErrorStats(const std::shared_ptr<IStats> &stats_client);
127     void logF2fsStats(const std::shared_ptr<IStats> &stats_client);
128     void logF2fsAtomicWriteInfo(const std::shared_ptr<IStats> &stats_client);
129     void logF2fsCompressionInfo(const std::shared_ptr<IStats> &stats_client);
130     void logF2fsGcSegmentInfo(const std::shared_ptr<IStats> &stats_client);
131     void logZramStats(const std::shared_ptr<IStats> &stats_client);
132     void logBootStats(const std::shared_ptr<IStats> &stats_client);
133     void logBatteryEEPROM(const std::shared_ptr<IStats> &stats_client);
134     void logSpeakerHealthStats(const std::shared_ptr<IStats> &stats_client);
135     void logF2fsSmartIdleMaintEnabled(const std::shared_ptr<IStats> &stats_client);
136     void logThermalStats(const std::shared_ptr<IStats> &stats_client);
137     void logMitigationDurationCounts(const std::shared_ptr<IStats> &stats_client);
138     void logDisplayStats(const std::shared_ptr<IStats> &stats_client);
139     void logDisplayPortStats(const std::shared_ptr<IStats> &stats_client);
140     void logHDCPStats(const std::shared_ptr<IStats> &stats_client);
141     void logVendorAudioPdmStatsReported(const std::shared_ptr<IStats> &stats_client);
142 
143     void reportSlowIoFromFile(const std::shared_ptr<IStats> &stats_client, const char *path,
144                               const VendorSlowIo::IoOperation &operation_s);
145     void logTempResidencyStats(const std::shared_ptr<IStats> &stats_client);
146     void reportZramMmStat(const std::shared_ptr<IStats> &stats_client);
147     void reportZramBdStat(const std::shared_ptr<IStats> &stats_client);
148     int getReclaimedSegments(const std::string &mode);
149     void logVendorAudioHardwareStats(const std::shared_ptr<IStats> &stats_client);
150     void logVendorLongIRQStatsReported(const std::shared_ptr<IStats> &stats_client);
151     void logVendorResumeLatencyStats(const std::shared_ptr<IStats> &stats_client);
152     void logPartitionUsedSpace(const std::shared_ptr<IStats> &stats_client);
153     void logPcieLinkStats(const std::shared_ptr<IStats> &stats_client);
154     void logWavesStats(const std::shared_ptr<IStats> &stats_client);
155     void logAdaptedInfoStats(const std::shared_ptr<IStats> &stats_client);
156     void logPcmUsageStats(const std::shared_ptr<IStats> &stats_client);
157     void logOffloadEffectsStats(const std::shared_ptr<IStats> &stats_client);
158     void logBluetoothAudioUsage(const std::shared_ptr<IStats> &stats_client);
159     void logBatteryGMSR(const std::shared_ptr<IStats> &stats_client);
160     void logBatteryHistoryValidation();
161 
162     const char *const kSlowioReadCntPath;
163     const char *const kSlowioWriteCntPath;
164     const char *const kSlowioUnmapCntPath;
165     const char *const kSlowioSyncCntPath;
166     const char *const kCycleCountBinsPath;
167     const char *const kImpedancePath;
168     const char *const kCodecPath;
169     const char *const kCodec1Path;
170     const char *const kSpeechDspPath;
171     const char *const kBatteryCapacityCC;
172     const char *const kBatteryCapacityVFSOC;
173     const char *const kUFSLifetimeA;
174     const char *const kUFSLifetimeB;
175     const char *const kUFSLifetimeC;
176     const char *const kF2fsStatsPath;
177     const char *const kZramMmStatPath;
178     const char *const kZramBdStatPath;
179     const char *const kEEPROMPath;
180     const char *const kBrownoutCsvPath;
181     const char *const kBrownoutLogPath;
182     const char *const kBrownoutReasonProp;
183     const char *const kPowerMitigationStatsPath;
184     const char *const kPowerMitigationDurationPath;
185     const char *const kSpeakerTemperaturePath;
186     const char *const kSpeakerExcursionPath;
187     const char *const kSpeakerHeartbeatPath;
188     const std::vector<std::string> kUFSErrStatsPath;
189     const int kBlockStatsLength;
190     const char *const kAmsRatePath;
191     const std::vector<std::string> kThermalStatsPaths;
192     const char *const kCCARatePath;
193     const std::vector<std::pair<std::string, std::string>> kTempResidencyAndResetPaths;
194     const char *const kLongIRQMetricsPath;
195     const char *const kStormIRQMetricsPath;
196     const char *const kIRQStatsResetPath;
197     const char *const kResumeLatencyMetricsPath;
198     const char *const kModemPcieLinkStatsPath;
199     const char *const kWifiPcieLinkStatsPath;
200     const std::vector<std::string> kDisplayStatsPaths;
201     const std::vector<std::string> kDisplayPortStatsPaths;
202     const std::vector<std::string> kHDCPStatsPaths;
203     const char *const kPDMStatePath;
204     const char *const kWavesPath;
205     const char *const kAdaptedInfoCountPath;
206     const char *const kAdaptedInfoDurationPath;
207     const char *const kPcmLatencyPath;
208     const char *const kPcmCountPath;
209     const char *const kTotalCallCountPath;
210     const char *const kOffloadEffectsIdPath;
211     const char *const kOffloadEffectsDurationPath;
212     const char *const kBluetoothAudioUsagePath;
213     const std::vector<std::string> kGMSRPath;
214     const char *const kMaxfgHistoryPath;
215     const std::vector<std::string> kFGModelLoadingPath;
216     const std::vector<std::string> kFGLogBufferPath;
217     const char *const kSpeakerVersionPath;
218 
219     BatteryEEPROMReporter battery_EEPROM_reporter_;
220     MmMetricsReporter mm_metrics_reporter_;
221     MitigationStatsReporter mitigation_stats_reporter_;
222     MitigationDurationReporter mitigation_duration_reporter_;
223     BrownoutDetectedReporter brownout_detected_reporter_;
224     ThermalStatsReporter thermal_stats_reporter_;
225     DisplayStatsReporter display_stats_reporter_;
226     BatteryHealthReporter battery_health_reporter_;
227     BatteryTTFReporter battery_time_to_full_reporter_;
228     TempResidencyReporter temp_residency_reporter_;
229     // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so
230     // store everything in the values array at the index of the field number    // -2.
231     const int kVendorAtomOffset = 2;
232 
233     bool log_once_reported = false;
234     int64_t prev_huge_pages_since_boot_ = -1;
235 
236     struct perf_metrics_data {
237         uint64_t resume_latency_sum_ms;
238         int64_t resume_count;
239         std::vector<int64_t> resume_latency_buckets;
240         int bucket_cnt;
241     };
242     struct perf_metrics_data prev_data;
243     const int kMaxResumeLatencyBuckets = 36;
244 };
245 
246 }  // namespace pixel
247 }  // namespace google
248 }  // namespace hardware
249 }  // namespace android
250 
251 #endif  // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_SYSFSCOLLECTOR_H
252