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 <android/frameworks/stats/1.0/IStats.h> 21 #include <utils/StrongPointer.h> 22 23 using android::sp; 24 using android::frameworks::stats::V1_0::IStats; 25 using android::frameworks::stats::V1_0::SlowIo; 26 27 namespace android { 28 namespace hardware { 29 namespace google { 30 namespace pixel { 31 32 class SysfsCollector { 33 public: 34 struct SysfsPaths { 35 const char *const SlowioReadCntPath; 36 const char *const SlowioWriteCntPath; 37 const char *const SlowioUnmapCntPath; 38 const char *const SlowioSyncCntPath; 39 const char *const CycleCountBinsPath; 40 const char *const ImpedancePath; 41 const char *const CodecPath; 42 const char *const Codec1Path; 43 const char *const SpeechDspPath; 44 const char *const BatteryCapacityCC; 45 const char *const BatteryCapacityVFSOC; 46 }; 47 48 SysfsCollector(const struct SysfsPaths &paths); 49 void collect(); 50 51 private: 52 bool ReadFileToInt(const std::string &path, int *val); 53 bool ReadFileToInt(const char *path, int *val); 54 void logAll(); 55 56 void logBatteryChargeCycles(); 57 void logCodecFailed(); 58 void logCodec1Failed(); 59 void logSlowIO(); 60 void logSpeakerImpedance(); 61 void logSpeechDspStat(); 62 void logBatteryCapacity(); 63 64 void reportSlowIoFromFile(const char *path, const SlowIo::IoOperation &operation_s); 65 66 const char *const kSlowioReadCntPath; 67 const char *const kSlowioWriteCntPath; 68 const char *const kSlowioUnmapCntPath; 69 const char *const kSlowioSyncCntPath; 70 const char *const kCycleCountBinsPath; 71 const char *const kImpedancePath; 72 const char *const kCodecPath; 73 const char *const kCodec1Path; 74 const char *const kSpeechDspPath; 75 const char *const kBatteryCapacityCC; 76 const char *const kBatteryCapacityVFSOC; 77 sp<IStats> stats_; 78 79 // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so 80 // store everything in the values array at the index of the field number 81 // -2. 82 const int kVendorAtomOffset = 2; 83 }; 84 85 } // namespace pixel 86 } // namespace google 87 } // namespace hardware 88 } // namespace android 89 90 #endif // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_SYSFSCOLLECTOR_H 91