1 /* 2 * Copyright (C) 2021 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_MITIGATIONSTATSREPORTER_H 18 #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_MITIGATIONSTATSREPORTER_H 19 20 #include <map> 21 #include <string> 22 23 #include <aidl/android/frameworks/stats/IStats.h> 24 #include <hardware/google/pixel/pixelstats/pixelatoms.pb.h> 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 /** 35 * A class to upload Pixel Mitigation Stats metrics 36 */ 37 class MitigationStatsReporter { 38 public: 39 MitigationStatsReporter(); 40 void logMitigationStatsPerHour(const std::shared_ptr<IStats> &stats_client, 41 const std::string &path); 42 43 private: 44 struct MitigationCount { 45 int batoilo_count; 46 int vdroop1_count; 47 int vdroop2_count; 48 int smpl_warn_count; 49 int ocp_cpu1_count; 50 int ocp_cpu2_count; 51 int ocp_tpu_count; 52 int ocp_gpu_count; 53 int soft_ocp_cpu1_count; 54 int soft_ocp_cpu2_count; 55 int soft_ocp_tpu_count; 56 int soft_ocp_gpu_count; 57 }; 58 59 struct MitigationCap { 60 int batoilo_cap; 61 int vdroop1_cap; 62 int vdroop2_cap; 63 int smpl_warn_cap; 64 int ocp_cpu1_cap; 65 int ocp_cpu2_cap; 66 int ocp_tpu_cap; 67 int ocp_gpu_cap; 68 int soft_ocp_cpu1_cap; 69 int soft_ocp_cpu2_cap; 70 int soft_ocp_tpu_cap; 71 int soft_ocp_gpu_cap; 72 }; 73 74 // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so 75 // store everything in the values array at the index of the field number 76 // -2. 77 const int kVendorAtomOffset = 2; 78 struct MitigationCount prev_count; 79 80 bool logMitigationCount(const std::string kMitigationDir, struct MitigationCount *last_count); 81 void logMitigationCap(const std::string kMitigationDir, struct MitigationCap *last_cap); 82 bool ReadFileToInt(const std::string &path, int *val); 83 }; 84 85 } // namespace pixel 86 } // namespace google 87 } // namespace hardware 88 } // namespace android 89 90 #endif // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_MITIGATIONSTATSREPORTER_H 91