• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 HTRACE_HISYSEVENT_PARSER_H
18 #define HTRACE_HISYSEVENT_PARSER_H
19 
20 #include "clock_filter.h"
21 #include "hisysevent_plugin_result.pb.h"
22 #include "htrace_plugin_time_parser.h"
23 #include "json.hpp"
24 #include "trace_data/trace_data_cache.h"
25 #include "trace_streamer_filters.h"
26 #include "ts_common.h"
27 
28 namespace SysTuning {
29 namespace TraceStreamer {
30 class HtraceHisyseventParser : public HtracePluginTimeParser {
31 public:
32     HtraceHisyseventParser(TraceDataCache* dataCache, const TraceStreamerFilters* ctx);
33     ~HtraceHisyseventParser();
34     void Finish();
35     void Parse(HisyseventInfo& tracePacket, uint64_t ts);
36 
37 private:
38     using json = nlohmann::json;
39     typedef struct {
40         std::string eventSource;
41         uint64_t timestamp;
42         std::vector<std::string> appName;
43         std::vector<std::string> appVersions;
44         std::vector<std::string> key;
45         std::vector<json> value;
46     } JsonData;
47 
48 private:
49     void
50         NoArrayDataParse(JsonData jData, std::vector<size_t> noArrayIndex, DataIndex eventSourceIndex, uint64_t serial);
51     void ArrayDataParse(JsonData jData,
52                         std::vector<size_t> arrayIndex,
53                         DataIndex eventSourceIndex,
54                         size_t maxArraySize,
55                         uint64_t serial);
56     void CommonDataParser(JsonData jData, DataIndex eventSourceIndex, uint64_t serial);
57     int32_t JGetData(json& jMessage,
58                      JsonData& jData,
59                      size_t& maxArraySize,
60                      std::vector<size_t>& noArrayIndex,
61                      std::vector<size_t>& arrayIndex);
62 
63     std::vector<std::string> eventsAccordingAppNames = {"POWER_IDE_BATTERY",
64                                                         "POWER_IDE_CPU",
65                                                         "POWER_IDE_LOCATION",
66                                                         "POWER_IDE_GPU",
67                                                         "POWER_IDE_DISPLAY",
68                                                         "POWER_IDE_CAMERA",
69                                                         "POWER_IDE_BLUETOOTH",
70                                                         "POWER_IDE_FLASHLIGHT",
71                                                         "POWER_IDE_AUDIO",
72                                                         "POWER_IDE_WIFISCAN",
73                                                         "BRIGHTNESS_NIT",
74                                                         "SIGNAL_LEVEL",
75                                                         "WIFI_EVENT_RECEIVED",
76                                                         "AUDIO_STREAM_CHANGE",
77                                                         "AUDIO_VOLUME_CHANGE",
78                                                         "WIFI_STATE",
79                                                         "BLUETOOTH_BR_SWITCH_STATE",
80                                                         "LOCATION_SWITCH_STATE",
81                                                         "ENABLE_SENSOR",
82                                                         "DISABLE_SENSOR",
83                                                         "WORK_REMOVE",
84                                                         "WORK_START",
85                                                         "WORK_STOP",
86                                                         "WORK_ADD",
87                                                         "POWER_RUNNINGLOCK",
88                                                         "GNSS_STATE",
89                                                         "ANOMALY_SCREEN_OFF_ENERGY",
90                                                         "ANOMALY_ALARM_WAKEUP",
91                                                         "ANOMALY_KERNEL_WAKELOCK",
92                                                         "ANOMALY_RUNNINGLOCK",
93                                                         "ANORMALY_APP_ENERGY",
94                                                         "ANOMALY_GNSS_ENERGY",
95                                                         "ANOMALY_CPU_HIGH_FREQUENCY",
96                                                         "ANOMALY_CPU_ENERGY",
97                                                         "ANOMALY_WAKEUP"};
98     const uint64_t MSEC_TO_NS = 1000 * 1000;
99     std::vector<uint64_t> hisyseventTS_;
100     bool isDeviceState = true;
101 };
102 } // namespace TraceStreamer
103 } // namespace SysTuning
104 #endif // HTRACE_HISYSEVENT_PARSER_H
105