• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef STATS_UTILS_H
17 #define STATS_UTILS_H
18 
19 #include <string>
20 #include <iosfwd>
21 
22 namespace OHOS {
23 namespace PowerMgr {
24 #define GET_VARIABLE_NAME(name) #name
25 class StatsUtils {
26 public:
27     static constexpr uint8_t DEFAULT_VALUE = 0;
28     static constexpr uint8_t SCREEN_BRIGHTNESS_BIN = 255;
29     static constexpr uint8_t RADIO_SIGNAL_BIN = 5;
30     static constexpr int8_t INVALID_VALUE = -1;
31     static constexpr uint32_t MS_IN_HOUR = 3600000;
32     static constexpr uint32_t MS_IN_SECOND = 1000;
33     static constexpr uint32_t NS_IN_MS = 1000000;
34     static constexpr uint32_t US_IN_MS = 1000;
35 
36     static constexpr const char* CURRENT_INVALID = "invalid";
37     static constexpr const char* CURRENT_BLUETOOTH_BR_ON = "bluetooth_br_on";
38     static constexpr const char* CURRENT_BLUETOOTH_BR_SCAN = "bluetooth_br_scan";
39     static constexpr const char* CURRENT_BLUETOOTH_BLE_ON = "bluetooth_ble_on";
40     static constexpr const char* CURRENT_BLUETOOTH_BLE_SCAN = "bluetooth_ble_scan";
41     static constexpr const char* CURRENT_WIFI_ON = "wifi_on";
42     static constexpr const char* CURRENT_WIFI_SCAN = "wifi_scan";
43     static constexpr const char* CURRENT_RADIO_ON = "radio_on";
44     static constexpr const char* CURRENT_RADIO_DATA = "radio_data";
45     static constexpr const char* CURRENT_CAMERA_ON = "camera_on";
46     static constexpr const char* CURRENT_FLASHLIGHT_ON = "flashlight_on";
47     static constexpr const char* CURRENT_GNSS_ON = "gnss_on";
48     static constexpr const char* CURRENT_SENSOR_GRAVITY = "sensor_gravity_on";
49     static constexpr const char* CURRENT_SENSOR_PROXIMITY = "sensor_proximity_on";
50     static constexpr const char* CURRENT_AUDIO_ON = "audio_on";
51     static constexpr const char* CURRENT_SCREEN_ON = "screen_on";
52     static constexpr const char* CURRENT_SCREEN_BRIGHTNESS = "screen_brightness";
53     static constexpr const char* CURRENT_CPU_AWAKE = "cpu_awake";
54     static constexpr const char* CURRENT_CPU_IDLE = "cpu_idle";
55     static constexpr const char* CURRENT_CPU_CLUSTER = "cpu_clusters";
56     static constexpr const char* CURRENT_CPU_SPEED = "cpu_speed_cluster";
57     static constexpr const char* CURRENT_CPU_ACTIVE = "cpu_active";
58     static constexpr const char* CURRENT_CPU_SUSPEND = "cpu_suspend";
59     static constexpr const char* CURRENT_ALARM_ON = "alarm_on";
60 
61     enum StatsType {
62         STATS_TYPE_INVALID = -1,
63         STATS_TYPE_BLUETOOTH_BR_ON,
64         STATS_TYPE_BLUETOOTH_BR_SCAN,
65         STATS_TYPE_BLUETOOTH_BLE_ON,
66         STATS_TYPE_BLUETOOTH_BLE_SCAN,
67         STATS_TYPE_WIFI_ON,
68         STATS_TYPE_WIFI_SCAN,
69         STATS_TYPE_PHONE_ACTIVE,
70         STATS_TYPE_PHONE_DATA,
71         STATS_TYPE_CAMERA_ON,
72         STATS_TYPE_CAMERA_FLASHLIGHT_ON,
73         STATS_TYPE_FLASHLIGHT_ON,
74         STATS_TYPE_GNSS_ON,
75         STATS_TYPE_SENSOR_GRAVITY_ON,
76         STATS_TYPE_SENSOR_PROXIMITY_ON,
77         STATS_TYPE_AUDIO_ON,
78         STATS_TYPE_DISPLAY,
79         STATS_TYPE_SCREEN_ON,
80         STATS_TYPE_SCREEN_BRIGHTNESS,
81         STATS_TYPE_WAKELOCK_HOLD,
82         STATS_TYPE_PHONE_IDLE,
83         STATS_TYPE_CPU_CLUSTER,
84         STATS_TYPE_CPU_SPEED,
85         STATS_TYPE_CPU_ACTIVE,
86         STATS_TYPE_CPU_SUSPEND,
87         STATS_TYPE_BATTERY,
88         STATS_TYPE_WORKSCHEDULER,
89         STATS_TYPE_THERMAL,
90         STATS_TYPE_DISTRIBUTEDSCHEDULER,
91         STATS_TYPE_ALARM,
92     };
93 
94     enum StatsState {
95         STATS_STATE_INVALID = -1, // Indicates an invalid state
96         STATS_STATE_ACTIVATED, // Indicates subsystem is activated
97         STATS_STATE_DEACTIVATED, // Indicates subsystem is deactivated
98         STATS_STATE_WORKSCHEDULER_SCHEDULED, // Indicates work is scheduled
99         STATS_STATE_WORKSCHEDULER_EXECUTED, // Indicates work is executed
100     };
101 
102     struct StatsData {
103         StatsType type = STATS_TYPE_INVALID;
104         StatsState state = STATS_STATE_INVALID;
105         int32_t uid = INVALID_VALUE;
106         int32_t pid = INVALID_VALUE;
107         std::string eventDataName = "INVALID";
108         std::string eventDebugInfo = "INVALID";
109         int32_t eventDataType = INVALID_VALUE;
110         int32_t eventDataExtra = INVALID_VALUE;
111         int16_t level = INVALID_VALUE;
112         int64_t time = DEFAULT_VALUE;
113         int64_t traffic = DEFAULT_VALUE;
114         std::string deviceId = "";
115     };
116 
117     static std::string ConvertStatsType(StatsType statsType);
118 private:
119     static std::string ConvertTypeForConn(StatsType statsType);
120     static std::string ConvertTypeForCpu(StatsType statsType);
121     static std::string ConvertTypeForCommon(StatsType statsType);
122     static std::string ConvertTypeForDebug(StatsType statsType);
123 };
124 } // namespace PowerMgr
125 } // namespace OHOS
126 #endif // STATS_UTILS_H