• 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 enum Update { kUpdateMax, kUpdateMin };
38 
39 /**
40  * A class to upload Pixel Brownout metrics
41  */
42 class BrownoutDetectedReporter {
43   public:
44     void logBrownout(const std::shared_ptr<IStats> &stats_client, const std::string &logFilePath,
45                      const std::string &brownoutReasonProp);
46 
47   private:
48     struct BrownoutDetectedInfo {
49         int triggered_irq_;
50         long triggered_timestamp_;
51         int battery_temp_;
52         int battery_cycle_;
53         int battery_soc_;
54         int voltage_now_;
55         int odpm_value_[ODPM_MAX_IDX];
56         int dvfs_value_[DVFS_MAX_IDX];
57         int brownout_reason_;
58     };
59 
60     void setAtomFieldValue(std::vector<VendorAtomValue> *values, int offset, int content);
61     long parseTimestamp(std::string timestamp);
62     bool updateIfFound(std::string line, std::regex pattern, int *current_value, Update flag);
63     void uploadData(const std::shared_ptr<IStats> &stats_client,
64                     const struct BrownoutDetectedInfo max_value);
65     // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so
66     // store everything in the values array at the index of the field number
67     // -2.
68     const int kVendorAtomOffset = 2;
69 };
70 
71 }  // namespace pixel
72 }  // namespace google
73 }  // namespace hardware
74 }  // namespace android
75 
76 #endif  // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_BROWNOUTDETECTEDREPORTER_H
77