• 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 SDK_DATA_PARSER_H
17 #define SDK_DATA_PARSER_H
18 
19 #include <functional>
20 #include <mutex>
21 #include <clock_filter.h>
22 #include "file.h"
23 #include "htrace_plugin_time_parser.h"
24 #include "table/demo_table_base.h"
25 #include "trace_streamer/trace_streamer_selector.h"
26 
27 namespace SysTuning {
28 namespace TraceStreamer {
29 enum Third_Party_Wasm_Id {
30     DATA_TYPE_MOCK_PLUGIN = 0,
31     DATA_TYPE_CLOCK = 100,
32 };
33 class SDKDataParser : public HtracePluginTimeParser {
34 public:
35     using TraceRangeCallbackFunction = std::function<void(const std::string)>;
36     using QueryResultCallbackFunction = std::function<void(const std::string /* result */, int32_t, int32_t)>;
37     explicit SDKDataParser(TraceDataCache* dataCache);
~SDKDataParser()38     ~SDKDataParser(){};
39 
40     // third_party
41     int32_t CreateTableByJson();
42     int32_t SetTableName(const char* counterTableName,
43                          const char* counterObjectTableName,
44                          const char* sliceTableName,
45                          const char* sliceObjectName);
46     int32_t GetJsonConfig(QueryResultCallbackFunction queryResultCallbackFunction);
47     int32_t GetPluginName(std::string pluginName);
48     int32_t ParseDataOver(TraceRangeCallbackFunction traceRangeCallbackFunction);
49     int32_t ParserData(const uint8_t* data, int32_t len, int32_t componentId);
50     int32_t AppendCounterObject(int32_t counterId, const char* columnName);
51     int32_t AppendCounter(int32_t counterId, uint64_t ts, int32_t value);
52     int32_t AppendSliceObject(int32_t sliceId, const char* columnName);
53     int32_t AppendSlice(int32_t sliceId, uint64_t ts, uint64_t endTs, int32_t value);
54 
55 private:
56     int32_t CreateCounterObjectTable(const std::string& tableName);
57     int32_t CreateCounterTable(const std::string& tableName);
58     int32_t CreateSliceObjectTable(const std::string& tableName);
59     int32_t CreateSliceTable(const std::string& tableName);
60     int32_t ParserClock(const uint8_t* data, int32_t len);
61     int32_t UpdateJson();
62 
63 public:
64     std::string counterTableName_ = "counter_table";
65     std::string counterObjectTableName_ = "gpu_counter_object";
66     std::string sliceTableName_ = "slice_table";
67     std::string sliceObjectName_ = "slice_object_table";
68     std::string jsonConfig_ =
69         "{\"tableConfig\":{\"showType\":[{\"tableName\":\"counter_table\",\"inner\":{\"tableName\":\"gpu_counter_"
70         "object\","
71         "\"columns\":[{\"column\":\"counter_name\",\"type\":\"STRING\",\"displayName\":\"\",\"showType\":[0]},{"
72         "\"column\":"
73         "\"counter_id\",\"type\":\"INTEGER\",\"displayName\":\"\",\"showType\":[0]}]},\"columns\":[{\"column\":\"ts\","
74         "\"type\":\"INTEGER\",\"displayName\":\"TimeStamp\",\"showType\":[1,3]},{\"column\":\"counter_id\",\"type\":"
75         "\"INTEGER\",\"displayName\":\"MonitorValue\",\"showType\":[1,3]},{\"column\":\"value\",\"type\":\"INTEGER\","
76         "\"displayName\":\"Value\",\"showType\":[1,3]}]},{\"tableName\":\"slice_table\",\"inner\":{\"tableName\":"
77         "\"slice_"
78         "object_table\",\"columns\":[{\"column\":\"slice_name\",\"type\":\"STRING\",\"displayName\":\"\",\"showType\":["
79         "0]},"
80         "{\"column\":\"slice_id\",\"type\":\"INTEGER\",\"displayName\":\"\",\"showType\":[0]}]},\"columns\":[{"
81         "\"column\":"
82         "\"start_ts\",\"type\":\"INTEGER\",\"displayName\":\"startts\",\"showType\":[2,3]},{\"column\":\"end_ts\","
83         "\"type\":"
84         "\"INTEGER\",\"displayName\":\"endts\",\"showType\":[2,3]},{\"column\":\"slice_id\",\"type\":\"INTEGER\","
85         "\"displayName\":\"slice_id\",\"showType\":[2,3]},{\"column\":\"value\",\"type\":\"INTEGER\",\"displayName\":"
86         "\"Value\",\"showType\":[2,3]}]}]},\"settingConfig\":{\"name\":\"mailG77\",\"configuration\":{\"version\":{"
87         "\"type\":\"number\",\"default\":\"1\",\"description\":\"gatordversion\"},\"counters\":{\"type\":\"string\","
88         "\"enum\":[\"ARM_Mali-TTRx_JS1_ACTIVE\",\"ARM_Mali-TTRx_JS0_ACTIVE\",\"ARM_Mali-TTRx_GPU_ACTIVE\",\"ARM_Mali-"
89         "TTRx_FRAG_ACTIVE\"]},\"stop_gator\":{\"type\":\"boolean\",\"default\":\"true\",\"description\":\"stop_gator\"}"
90         "}}}";
91 
92 private:
93     TraceDataCache* traceDataCache_ = nullptr;
94     std::unique_ptr<ClockFilter> clockFilter_ = {};
95 };
96 } // namespace TraceStreamer
97 } // namespace SysTuning
98 #endif // SDK_DATA_PARSER_H
99