• 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 #include "sdk_plugin_data_parser.h"
16 #include <string>
17 #include "sdk/ts_sdk_api.h"
18 
19 namespace SysTuning {
20 namespace TraceStreamer {
21 extern "C" {
sdk_plugin_init_table_name()22 void sdk_plugin_init_table_name()
23 {
24     SDK_SetTableName("counter_table", "gpu_counter_object", "slice_table", "slice_object_table");
25 }
sdk_plugin_data_parser(const uint8_t * data,int32_t len)26 int32_t sdk_plugin_data_parser(const uint8_t* data, int32_t len)
27 {
28     std::unique_ptr<uint8_t[]> buf = std::make_unique<uint8_t[]>(len);
29     std::copy(data, data + len, buf.get());
30     MockDataArr mockDataArr;
31     mockDataArr.ParseFromArray(buf.get(), len);
32     int32_t size = mockDataArr.mockdata_size();
33     if (size > 1) {
34         for (auto m = 0; m < size; m++) {
35             auto mockData = mockDataArr.mockdata().at(m);
36             sdk_plugin_parser(data, len, mockData);
37         }
38     } else {
39         MockData mockData;
40         mockData.ParseFromArray(buf.get(), len);
41         sdk_plugin_parser(data, len, mockData);
42     }
43     return 0;
44 }
45 
sdk_plugin_parser(const uint8_t * data,int32_t len,MockData mockData)46 int32_t sdk_plugin_parser(const uint8_t* data, int32_t len, MockData mockData)
47 {
48     // parser counterObject
49     for (auto i = 0; i < mockData.counterobj_size(); i++) {
50         int32_t counterId = mockData.counterobj(i).id();
51         std::string counterName = mockData.counterobj(i).name();
52         SDK_AppendCounterObject(counterId, counterName.c_str());
53     }
54 
55     // parsercounterInfo
56     for (auto i = 0; i < mockData.counterinfo_size(); i++) {
57         CounterInfo counterInfo;
58         counterInfo = mockData.counterinfo(i);
59         SDK_AppendCounter(counterInfo.key(), counterInfo.ts(), counterInfo.value());
60     }
61 
62     // parserSliceObj
63     for (auto i = 0; i < mockData.sliceobj_size(); i++) {
64         int32_t sliceId = mockData.sliceobj(i).id();
65         std::string sliceName = mockData.sliceobj(i).name();
66         SDK_AppendSliceObject(sliceId, sliceName.c_str());
67     }
68 
69     // parserSliceInfo
70     for (auto i = 0; i < mockData.sliceinfo_size(); i++) {
71         int32_t sliceKey = mockData.sliceinfo(i).id();
72         int32_t sliceValue = mockData.sliceinfo(i).value();
73         uint64_t startTime = mockData.sliceinfo(i).start_time();
74         uint64_t endTime = mockData.sliceinfo(i).end_time();
75         SDK_AppendSlice(sliceKey, startTime, endTime, sliceValue);
76     }
77     return 0;
78 }
79 }
80 } // namespace TraceStreamer
81 } // namespace SysTuning
82