• 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 TRACE_STDTYPE_H
17 #define TRACE_STDTYPE_H
18 
19 #include <array>
20 #include <deque>
21 #include <limits>
22 #include <map>
23 #include <mutex>
24 #include <optional>
25 #include <sstream>
26 #include <stdexcept>
27 #include <string>
28 #include <unordered_map>
29 #include <vector>
30 #include "log.h"
31 #include "ts_common.h"
32 
33 namespace SysTuning {
34 namespace TraceStdtype {
35 using namespace SysTuning::TraceStreamer;
36 // the supported metadata
37 enum MetaDataItem { METADATA_ITEM_PARSERTOOL_VERSION, METADATA_ITEM_PARSERTOOL_PUBLISH_DATETIME, METADATA_ITEM_MAX };
38 class DemoCacheBase {
39 public:
Size()40     size_t Size() const
41     {
42         return std::max(demoTimeStamps_.size(), demoIds_.size());
43     }
IdsData()44     const std::deque<uint64_t>& IdsData() const
45     {
46         return demoIds_;
47     }
TimeStampData()48     const std::deque<uint64_t>& TimeStampData() const
49     {
50         return demoTimeStamps_;
51     }
InternalTidsData()52     const std::deque<InternalTid>& InternalTidsData() const
53     {
54         return demoInternalTids_;
55     }
Clear()56     virtual void Clear()
57     {
58         demoInternalTids_.clear();
59         demoTimeStamps_.clear();
60         demoIds_.clear();
61     }
62 
63 public:
64     std::deque<InternalTid> demoInternalTids_ = {};
65     std::deque<uint64_t> demoTimeStamps_ = {};
66     std::deque<uint64_t> demoIds_ = {};
67 };
68 
69 class GpuCounterObject : public DemoCacheBase {
70 public:
71     GpuCounterObject() = default;
72     ~GpuCounterObject() = default;
73     void AppendNewData(int32_t counterId, std::string counterName);
74     const std::deque<int32_t>& CounterId() const;
75     const std::deque<std::string>& CounterName() const;
76 
77 private:
78     std::deque<int32_t> counterId_ = {};
79     std::deque<std::string> counterName_ = {};
80 };
81 class GpuCounter : public DemoCacheBase {
82 public:
83     GpuCounter() = default;
84     ~GpuCounter() = default;
85     void AppendNewData(uint64_t ts, int32_t counterId, int32_t value);
86     const std::deque<uint64_t>& TimeStamp() const;
87     const std::deque<int32_t>& CounterId() const;
88     const std::deque<int32_t>& Value() const;
89 
90 private:
91     std::deque<uint64_t> ts_ = {};
92     std::deque<int32_t> counterId_ = {};
93     std::deque<int32_t> value_ = {};
94 };
95 
96 class SliceObject : public DemoCacheBase {
97 public:
98     SliceObject() = default;
99     ~SliceObject() = default;
100     void AppendNewData(int32_t sliceId, std::string sliceName);
101     const std::deque<int32_t>& SliceId() const;
102     const std::deque<std::string>& SliceName() const;
103 
104 private:
105     std::deque<int32_t> sliceId_ = {};
106     std::deque<std::string> sliceName_ = {};
107 };
108 class SliceData : public DemoCacheBase {
109 public:
110     SliceData() = default;
111     ~SliceData() = default;
112     void AppendNewData(int32_t sliceId, uint64_t startTs, uint64_t endTs, int32_t value);
113     const std::deque<int32_t>& SliceId() const;
114     const std::deque<uint64_t>& TimeStamp() const;
115     const std::deque<uint64_t>& EndTs() const;
116     const std::deque<int32_t>& Value() const;
117 
118 private:
119     std::deque<uint64_t> startTs_ = {};
120     std::deque<int32_t> sliceId_ = {};
121     std::deque<uint64_t> endTs_ = {};
122     std::deque<int32_t> value_ = {};
123 };
124 class MetaData : public DemoCacheBase {
125 public:
126     MetaData() = default;
127     ~MetaData() = default;
128     void InitMetaData();
129     void SetParserToolVersion(const std::string& version);
130     void SetParserToolPublishDateTime(const std::string& datetime);
131     const std::string& Value(uint64_t row) const;
132     const std::string& Name(uint64_t row) const;
Clear()133     void Clear() override
134     {
135         columnNames_.clear();
136         values_.clear();
137     }
138 
139 private:
140     const std::string METADATA_ITEM_PARSERTOOL_VERSION_COLNAME = "tool_version";
141     const std::string METADATA_ITEM_PARSERTOOL_PUBLISH_DATETIME_COLNAME = "tool_publish_time";
142     std::deque<std::string> columnNames_ = {};
143     std::deque<std::string> values_ = {};
144 };
145 } // namespace TraceStdtype
146 } // namespace SysTuning
147 
148 #endif // TRACE_STDTYPE_H
149