• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_BROWNOUTDETECTEDREPORTER_H
18 #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_BROWNOUTDETECTEDREPORTER_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 <regex>
25 #include <string>
26 
27 namespace android {
28 namespace hardware {
29 namespace google {
30 namespace pixel {
31 
32 using aidl::android::frameworks::stats::IStats;
33 using aidl::android::frameworks::stats::VendorAtomValue;
34 
35 #define ODPM_MAX_IDX 24
36 #define DVFS_MAX_IDX 6
37 
38 /*
39  * CsvIdx dictates the indexing of how data aligns with lastmeal.csv.
40  * lastmeal.csv is generated by battery_mitigation upon brownout detection.
41  * The new data added here are the additional data captured by
42  * battery_mitigation during the generation of lastmeal.csv.
43  * filed b/335498252 to make this portion be passed from gs-common.
44  */
45 enum CsvIdx {
46     TIMESTAMP_IDX,
47     IRQ_IDX,
48     SOC_IDX,
49     TEMP_IDX,
50     CYCLE_IDX,
51     VOLTAGE_IDX,
52     CURRENT_IDX,
53     DVFS_CHANNEL_0 = 7,
54     ODPM_CHANNEL_0 = DVFS_CHANNEL_0 + DVFS_MAX_IDX,      /* 13 */
55     MITIGATION_METHOD_0 = ODPM_CHANNEL_0 + ODPM_MAX_IDX, /* 37 */
56     MITIGATION_METHOD_0_COUNT,
57     MITIGATION_METHOD_0_TIME,
58     EVT_CNT_IDX_OILO1,
59     EVT_CNT_IDX_OILO2,
60     EVT_CNT_IDX_UVLO1,
61     EVT_CNT_IDX_UVLO2,
62     MAX_CURR,
63     IDX_VIMON_V,
64     IDX_VIMON_I,
65 };
66 
67 enum Irq {
68     SMPL_WARN,
69     OCP_WARN_CPUCL1,
70     OCP_WARN_CPUCL2,
71     SOFT_OCP_WARN_CPUCL1,
72     SOFT_OCP_WARN_CPUCL2,
73     OCP_WARN_TPU,
74     SOFT_OCP_WARN_TPU,
75     OCP_WARN_GPU,
76     SOFT_OCP_WARN_GPU,
77     PMIC_SOC,
78     UVLO1,
79     UVLO2,
80     BATOILO,
81     BATOILO2,
82     PMIC_120C,
83     PMIC_140C,
84     PMIC_OVERHEAT,
85 };
86 
87 enum Update { kUpdateMax, kUpdateMin };
88 
89 /**
90  * A class to upload Pixel Brownout metrics
91  */
92 class BrownoutDetectedReporter {
93   public:
94     void logBrownout(const std::shared_ptr<IStats> &stats_client, const std::string &logFilePath,
95                      const std::string &brownoutReasonProp);
96     void logBrownoutCsv(const std::shared_ptr<IStats> &stats_client, const std::string &logFilePath,
97                         const std::string &brownoutReasonProp);
98     int brownoutReasonCheck(const std::string &brownoutReasonProp);
99 
100   private:
101     struct BrownoutDetectedInfo {
102         int triggered_irq_;
103         long triggered_timestamp_;
104         int battery_temp_;
105         int battery_cycle_;
106         int battery_soc_;
107         int voltage_now_;
108         int odpm_value_[ODPM_MAX_IDX];
109         int dvfs_value_[DVFS_MAX_IDX];
110         int brownout_reason_;
111         int mitigation_method_0_;
112         int mitigation_method_0_count_;
113         unsigned long long mitigation_method_0_time_us_;
114         int max_curr_;
115         int evt_cnt_uvlo1_;
116         int evt_cnt_uvlo2_;
117         int evt_cnt_oilo1_;
118         int evt_cnt_oilo2_;
119         int vimon_vbatt_;
120         int vimon_ibatt_;
121     };
122 
123     void setAtomFieldValue(std::vector<VendorAtomValue> *values, int offset, int content);
124     long parseTimestamp(std::string timestamp);
125     bool updateIfFound(std::string line, std::regex pattern, int *current_value, Update flag);
126     void uploadData(const std::shared_ptr<IStats> &stats_client,
127                     const struct BrownoutDetectedInfo max_value);
128     // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so
129     // store everything in the values array at the index of the field number
130     // -2.
131     const int kVendorAtomOffset = 2;
132 };
133 
134 }  // namespace pixel
135 }  // namespace google
136 }  // namespace hardware
137 }  // namespace android
138 
139 #endif  // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_BROWNOUTDETECTEDREPORTER_H
140