1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 "hiperf_stdtype.h"
16
17 namespace SysTuning {
18 namespace TraceStdtype {
AppendNewPerfCallChain(const PerfCallChainRow & context)19 size_t PerfCallChain::AppendNewPerfCallChain(const PerfCallChainRow &context)
20 {
21 ids_.emplace_back(Size());
22 callChainIds_.emplace_back(context.callChainId);
23 depths_.emplace_back(context.depth);
24 ips_.emplace_back(context.ip);
25 vaddrInFiles_.emplace_back(context.vaddrInFile);
26 fileIds_.emplace_back(context.fileId);
27 symbolIds_.emplace_back(context.symbolId);
28 names_.emplace_back(INVALID_UINT64);
29 return Size() - 1;
30 }
CallChainIds() const31 const std::deque<uint32_t> &PerfCallChain::CallChainIds() const
32 {
33 return callChainIds_;
34 }
Depths() const35 const std::deque<uint32_t> &PerfCallChain::Depths() const
36 {
37 return depths_;
38 }
Ips() const39 const std::deque<uint64_t> &PerfCallChain::Ips() const
40 {
41 return ips_;
42 }
VaddrInFiles() const43 const std::deque<uint64_t> &PerfCallChain::VaddrInFiles() const
44 {
45 return vaddrInFiles_;
46 }
FileIds() const47 const std::deque<uint64_t> &PerfCallChain::FileIds() const
48 {
49 return fileIds_;
50 }
SymbolIds() const51 const std::deque<uint64_t> &PerfCallChain::SymbolIds() const
52 {
53 return symbolIds_;
54 }
55
Names() const56 const std::deque<DataIndex> &PerfCallChain::Names() const
57 {
58 return names_;
59 }
SetName(uint64_t index,DataIndex name)60 void PerfCallChain::SetName(uint64_t index, DataIndex name)
61 {
62 names_[index] = name;
63 }
Clear()64 void PerfCallChain::Clear()
65 {
66 CacheBase::Clear();
67 callChainIds_.clear();
68 depths_.clear();
69 ips_.clear();
70 vaddrInFiles_.clear();
71 fileIds_.clear();
72 symbolIds_.clear();
73 names_.clear();
74 }
UpdateSymbolId(size_t index,DataIndex symbolId)75 void PerfCallChain::UpdateSymbolId(size_t index, DataIndex symbolId)
76 {
77 if (index < Size()) {
78 symbolIds_[index] = symbolId;
79 }
80 }
UpdateSymbolRelatedData(size_t index,uint64_t vaddrInFile,uint64_t symbolId,DataIndex nameIndex)81 void PerfCallChain::UpdateSymbolRelatedData(size_t index, uint64_t vaddrInFile, uint64_t symbolId, DataIndex nameIndex)
82 {
83 if (index < Size()) {
84 vaddrInFiles_[index] = vaddrInFile;
85 symbolIds_[index] = symbolId;
86 names_[index] = nameIndex;
87 }
88 }
AppendNewPerfFiles(uint64_t fileIds,uint32_t serial,DataIndex symbols,DataIndex filePath)89 size_t PerfFiles::AppendNewPerfFiles(uint64_t fileIds, uint32_t serial, DataIndex symbols, DataIndex filePath)
90 {
91 ids_.emplace_back(Size());
92 fileIds_.emplace_back(fileIds);
93 serials_.emplace_back(serial);
94 symbols_.emplace_back(symbols);
95 filePaths_.emplace_back(filePath);
96 return Size() - 1;
97 }
FileIds() const98 const std::deque<uint64_t> &PerfFiles::FileIds() const
99 {
100 return fileIds_;
101 }
102
Serials() const103 const std::deque<uint32_t> &PerfFiles::Serials() const
104 {
105 return serials_;
106 }
Symbols() const107 const std::deque<DataIndex> &PerfFiles::Symbols() const
108 {
109 return symbols_;
110 }
FilePaths() const111 const std::deque<DataIndex> &PerfFiles::FilePaths() const
112 {
113 return filePaths_;
114 }
115
EraseFileIdSameData(uint64_t fileId)116 bool PerfFiles::EraseFileIdSameData(uint64_t fileId)
117 {
118 uint64_t start = INVALID_UINT64;
119 uint64_t end = INVALID_UINT64;
120 for (auto row = 0; row < Size(); row++) {
121 if (fileIds_[row] == fileId) {
122 if (start == INVALID_UINT64) {
123 start = row;
124 end = row;
125 } else {
126 end = row;
127 }
128 }
129 }
130 end++;
131 if (start <= end && end < Size()) {
132 ids_.erase(ids_.begin() + start, ids_.begin() + end);
133 fileIds_.erase(fileIds_.begin() + start, fileIds_.begin() + end);
134 serials_.erase(serials_.begin() + start, serials_.begin() + end);
135 symbols_.erase(symbols_.begin() + start, symbols_.begin() + end);
136 filePaths_.erase(filePaths_.begin() + start, filePaths_.begin() + end);
137 return true;
138 }
139 return false;
140 }
Clear()141 void PerfFiles::Clear()
142 {
143 CacheBase::Clear();
144 fileIds_.clear();
145 serials_.clear();
146 symbols_.clear();
147 filePaths_.clear();
148 }
149
AppendNewPerfSample(const PerfSampleRow & perfSampleRow)150 size_t PerfSample::AppendNewPerfSample(const PerfSampleRow &perfSampleRow)
151 {
152 ids_.emplace_back(Size());
153 sampleIds_.emplace_back(perfSampleRow.sampleId);
154 timeStamps_.emplace_back(perfSampleRow.timeStamp);
155 tids_.emplace_back(perfSampleRow.tid);
156 eventCounts_.emplace_back(perfSampleRow.eventCount);
157 eventTypeIds_.emplace_back(perfSampleRow.eventTypeId);
158 timestampTraces_.emplace_back(perfSampleRow.timestampTrace);
159 cpuIds_.emplace_back(perfSampleRow.cpuId);
160 threadStates_.emplace_back(perfSampleRow.threadState);
161 return Size() - 1;
162 }
SampleIds() const163 const std::deque<uint32_t> &PerfSample::SampleIds() const
164 {
165 return sampleIds_;
166 }
Tids() const167 const std::deque<uint32_t> &PerfSample::Tids() const
168 {
169 return tids_;
170 }
EventCounts() const171 const std::deque<uint64_t> &PerfSample::EventCounts() const
172 {
173 return eventCounts_;
174 }
EventTypeIds() const175 const std::deque<uint64_t> &PerfSample::EventTypeIds() const
176 {
177 return eventTypeIds_;
178 }
TimestampTraces() const179 const std::deque<uint64_t> &PerfSample::TimestampTraces() const
180 {
181 return timestampTraces_;
182 }
CpuIds() const183 const std::deque<uint64_t> &PerfSample::CpuIds() const
184 {
185 return cpuIds_;
186 }
ThreadStates() const187 const std::deque<DataIndex> &PerfSample::ThreadStates() const
188 {
189 return threadStates_;
190 }
191
Clear()192 void PerfSample::Clear()
193 {
194 CacheBase::Clear();
195 sampleIds_.clear();
196 tids_.clear();
197 eventCounts_.clear();
198 eventTypeIds_.clear();
199 timestampTraces_.clear();
200 cpuIds_.clear();
201 threadStates_.clear();
202 }
203
AppendNewPerfThread(uint32_t pid,uint32_t tid,DataIndex threadName)204 size_t PerfThread::AppendNewPerfThread(uint32_t pid, uint32_t tid, DataIndex threadName)
205 {
206 ids_.emplace_back(Size());
207 pids_.emplace_back(pid);
208 tids_.emplace_back(tid);
209 threadNames_.emplace_back(threadName);
210 return Size() - 1;
211 }
Pids() const212 const std::deque<uint32_t> &PerfThread::Pids() const
213 {
214 return pids_;
215 }
Tids() const216 const std::deque<uint32_t> &PerfThread::Tids() const
217 {
218 return tids_;
219 }
ThreadNames() const220 const std::deque<DataIndex> &PerfThread::ThreadNames() const
221 {
222 return threadNames_;
223 }
Clear()224 void PerfThread::Clear()
225 {
226 CacheBase::Clear();
227 tids_.clear();
228 pids_.clear();
229 threadNames_.clear();
230 }
AppendNewPerfReport(DataIndex type,DataIndex value)231 size_t PerfReport::AppendNewPerfReport(DataIndex type, DataIndex value)
232 {
233 ids_.emplace_back(Size());
234 types_.emplace_back(type);
235 values_.emplace_back(value);
236 return Size() - 1;
237 }
Types() const238 const std::deque<DataIndex> &PerfReport::Types() const
239 {
240 return types_;
241 }
Values() const242 const std::deque<DataIndex> &PerfReport::Values() const
243 {
244 return values_;
245 }
AppendNewPerfNapiAsync(const PerfNapiAsyncRow & perfNapiAsyncRow)246 size_t PerfNapiAsync::AppendNewPerfNapiAsync(const PerfNapiAsyncRow &perfNapiAsyncRow)
247 {
248 ids_.emplace_back(Size());
249 timeStamps_.emplace_back(perfNapiAsyncRow.timeStamp);
250 traceids_.emplace_back(perfNapiAsyncRow.traceid);
251 cpuIds_.emplace_back(perfNapiAsyncRow.cpuId);
252 internalTids_.emplace_back(perfNapiAsyncRow.threadId);
253 processIds_.emplace_back(perfNapiAsyncRow.processId);
254 callerCallchainids_.emplace_back(perfNapiAsyncRow.callerCallchainid);
255 calleeCallchainids_.emplace_back(perfNapiAsyncRow.calleeCallchainid);
256 perfSampleIds_.emplace_back(perfNapiAsyncRow.perfSampleId);
257 eventCounts_.emplace_back(perfNapiAsyncRow.eventCount);
258 eventTypeIds_.emplace_back(perfNapiAsyncRow.eventTypeId);
259 return Size() - 1;
260 }
Traceids() const261 const std::deque<DataIndex> &PerfNapiAsync::Traceids() const
262 {
263 return traceids_;
264 }
CpuIds() const265 const std::deque<uint8_t> &PerfNapiAsync::CpuIds() const
266 {
267 return cpuIds_;
268 }
ProcessIds() const269 const std::deque<uint32_t> &PerfNapiAsync::ProcessIds() const
270 {
271 return processIds_;
272 }
CallerCallchainids() const273 const std::deque<uint32_t> &PerfNapiAsync::CallerCallchainids() const
274 {
275 return callerCallchainids_;
276 }
CalleeCallchainids() const277 const std::deque<uint32_t> &PerfNapiAsync::CalleeCallchainids() const
278 {
279 return calleeCallchainids_;
280 }
PerfSampleIds() const281 const std::deque<uint64_t> &PerfNapiAsync::PerfSampleIds() const
282 {
283 return perfSampleIds_;
284 }
EventCounts() const285 const std::deque<uint64_t> &PerfNapiAsync::EventCounts() const
286 {
287 return eventCounts_;
288 }
EventTypeIds() const289 const std::deque<uint64_t> &PerfNapiAsync::EventTypeIds() const
290 {
291 return eventTypeIds_;
292 }
Clear()293 void PerfNapiAsync::Clear()
294 {
295 CacheBase::Clear();
296 traceids_.clear();
297 processIds_.clear();
298 callerCallchainids_.clear();
299 calleeCallchainids_.clear();
300 perfSampleIds_.clear();
301 eventCounts_.clear();
302 eventTypeIds_.clear();
303 }
304 } // namespace TraceStdtype
305 } // namespace SysTuning
306