1 /* 2 * Copyright (C) 2023 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_MITIGATIONDURATIONREPORTER_H 18 #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_MITIGATIONDURATIONREPORTER_H 19 20 #include <aidl/android/frameworks/stats/IStats.h> 21 #include <hardware/google/pixel/pixelstats/pixelatoms.pb.h> 22 23 #include <map> 24 #include <string> 25 26 namespace android { 27 namespace hardware { 28 namespace google { 29 namespace pixel { 30 31 using aidl::android::frameworks::stats::IStats; 32 using aidl::android::frameworks::stats::VendorAtomValue; 33 34 #define MITIGATION_DURATION_MAIN_COUNT 12 35 #define MITIGATION_DURATION_SUB_COUNT 12 36 37 /** 38 * A class to upload Pixel Mitigation Duration metrics 39 */ 40 class MitigationDurationReporter { 41 public: 42 MitigationDurationReporter(); 43 void logMitigationDuration(const std::shared_ptr<IStats> &stats_client, 44 const std::string &path); 45 46 private: 47 struct IrqDurationCounts { 48 int uvlo1_none; 49 int uvlo1_mmwave; 50 int uvlo1_rffe; 51 int uvlo2_none; 52 int uvlo2_mmwave; 53 int uvlo2_rffe; 54 int batoilo_none; 55 int batoilo_mmwave; 56 int batoilo_rffe; 57 int main[MITIGATION_DURATION_MAIN_COUNT]; 58 int sub[MITIGATION_DURATION_SUB_COUNT]; 59 }; 60 61 // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so 62 // store everything in the values array at the index of the field number 63 // -2. 64 const int kVendorAtomOffset = 2; 65 const int kExpectedNumberOfLines = 33; 66 const std::string kGreaterThanTenMsSysfsNode = "/greater_than_10ms_count"; 67 68 void valueAssignmentHelper(std::vector<VendorAtomValue> *values, int *val, int fieldNumber); 69 70 int updateStat(const std::string *line, int *val); 71 72 bool getIrqDurationCountHelper(const std::string kMitigationDurationFile, 73 struct IrqDurationCounts *counts); 74 bool getStatFromLine(const std::string *line, int *val); 75 }; 76 77 } // namespace pixel 78 } // namespace google 79 } // namespace hardware 80 } // namespace android 81 82 #endif // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_MITIGATIONDURATIONREPORTER_H 83