• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     offsetToVaddrs_.emplace_back(context.offsetToVaddr);
27     fileIds_.emplace_back(context.fileId);
28     symbolIds_.emplace_back(context.symbolId);
29     names_.emplace_back(INVALID_UINT64);
30     sourceFileIds_.emplace_back(INVALID_DATAINDEX);
31     lineNumbers_.emplace_back(INVALID_UINT64);
32     return Size() - 1;
33 }
CallChainIds() const34 const std::deque<uint32_t> &PerfCallChain::CallChainIds() const
35 {
36     return callChainIds_;
37 }
Depths() const38 const std::deque<uint32_t> &PerfCallChain::Depths() const
39 {
40     return depths_;
41 }
Ips() const42 const std::deque<uint64_t> &PerfCallChain::Ips() const
43 {
44     return ips_;
45 }
VaddrInFiles() const46 const std::deque<uint64_t> &PerfCallChain::VaddrInFiles() const
47 {
48     return vaddrInFiles_;
49 }
OffsetToVaddrs() const50 const std::deque<uint64_t> &PerfCallChain::OffsetToVaddrs() const
51 {
52     return offsetToVaddrs_;
53 }
FileIds() const54 const std::deque<uint64_t> &PerfCallChain::FileIds() const
55 {
56     return fileIds_;
57 }
SymbolIds() const58 const std::deque<uint64_t> &PerfCallChain::SymbolIds() const
59 {
60     return symbolIds_;
61 }
62 
Names() const63 const std::deque<DataIndex> &PerfCallChain::Names() const
64 {
65     return names_;
66 }
SourceFileIds() const67 const std::deque<DataIndex> &PerfCallChain::SourceFileIds() const
68 {
69     return sourceFileIds_;
70 }
LineNumbers() const71 const std::deque<uint64_t> &PerfCallChain::LineNumbers() const
72 {
73     return lineNumbers_;
74 }
SetName(uint64_t index,DataIndex name)75 void PerfCallChain::SetName(uint64_t index, DataIndex name)
76 {
77     names_[index] = name;
78 }
Clear()79 void PerfCallChain::Clear()
80 {
81     CacheBase::Clear();
82     callChainIds_.clear();
83     depths_.clear();
84     ips_.clear();
85     vaddrInFiles_.clear();
86     offsetToVaddrs_.clear();
87     fileIds_.clear();
88     symbolIds_.clear();
89     names_.clear();
90     sourceFileIds_.clear();
91     lineNumbers_.clear();
92 }
UpdateSymbolId(size_t index,DataIndex symbolId)93 void PerfCallChain::UpdateSymbolId(size_t index, DataIndex symbolId)
94 {
95     if (index < Size()) {
96         symbolIds_[index] = symbolId;
97     }
98 }
UpdateSymbolRelatedData(size_t index,uint64_t vaddrInFile,uint64_t offsetToVaddr,uint64_t symbolId,DataIndex nameIndex)99 void PerfCallChain::UpdateSymbolRelatedData(size_t index,
100                                             uint64_t vaddrInFile,
101                                             uint64_t offsetToVaddr,
102                                             uint64_t symbolId,
103                                             DataIndex nameIndex)
104 {
105     if (index < Size()) {
106         vaddrInFiles_[index] = vaddrInFile;
107         offsetToVaddrs_[index] = offsetToVaddr;
108         symbolIds_[index] = symbolId;
109         names_[index] = nameIndex;
110     }
111 }
SetSourceFileNameAndLineNumber(size_t index,DataIndex SourceFileIndex,uint64_t lineNumber)112 void PerfCallChain::SetSourceFileNameAndLineNumber(size_t index, DataIndex SourceFileIndex, uint64_t lineNumber)
113 {
114     if (index < Size()) {
115         sourceFileIds_[index] = SourceFileIndex;
116         lineNumbers_[index] = lineNumber;
117     }
118 }
AppendNewPerfFiles(uint64_t fileIds,uint32_t serial,DataIndex symbols,DataIndex filePath)119 size_t PerfFiles::AppendNewPerfFiles(uint64_t fileIds, uint32_t serial, DataIndex symbols, DataIndex filePath)
120 {
121     ids_.emplace_back(Size());
122     fileIds_.emplace_back(fileIds);
123     serials_.emplace_back(serial);
124     symbols_.emplace_back(symbols);
125     filePaths_.emplace_back(filePath);
126     return Size() - 1;
127 }
FileIds() const128 const std::deque<uint64_t> &PerfFiles::FileIds() const
129 {
130     return fileIds_;
131 }
132 
Serials() const133 const std::deque<uint32_t> &PerfFiles::Serials() const
134 {
135     return serials_;
136 }
Symbols() const137 const std::deque<DataIndex> &PerfFiles::Symbols() const
138 {
139     return symbols_;
140 }
FilePaths() const141 const std::deque<DataIndex> &PerfFiles::FilePaths() const
142 {
143     return filePaths_;
144 }
145 
EraseFileIdSameData(uint64_t fileId)146 bool PerfFiles::EraseFileIdSameData(uint64_t fileId)
147 {
148     uint64_t start = INVALID_UINT64;
149     uint64_t end = INVALID_UINT64;
150     for (auto row = 0; row < Size(); row++) {
151         if (fileIds_[row] == fileId) {
152             if (start == INVALID_UINT64) {
153                 start = row;
154                 end = row;
155             } else {
156                 end = row;
157             }
158         }
159     }
160     end++;
161     if (start <= end && end < Size()) {
162         ids_.erase(ids_.begin() + start, ids_.begin() + end);
163         fileIds_.erase(fileIds_.begin() + start, fileIds_.begin() + end);
164         serials_.erase(serials_.begin() + start, serials_.begin() + end);
165         symbols_.erase(symbols_.begin() + start, symbols_.begin() + end);
166         filePaths_.erase(filePaths_.begin() + start, filePaths_.begin() + end);
167         return true;
168     }
169     return false;
170 }
Clear()171 void PerfFiles::Clear()
172 {
173     CacheBase::Clear();
174     fileIds_.clear();
175     serials_.clear();
176     symbols_.clear();
177     filePaths_.clear();
178 }
179 
AppendNewPerfSample(const PerfSampleRow & perfSampleRow)180 size_t PerfSample::AppendNewPerfSample(const PerfSampleRow &perfSampleRow)
181 {
182     ids_.emplace_back(Size());
183     sampleIds_.emplace_back(perfSampleRow.sampleId);
184     timeStamps_.emplace_back(perfSampleRow.timeStamp);
185     tids_.emplace_back(perfSampleRow.tid);
186     eventCounts_.emplace_back(perfSampleRow.eventCount);
187     eventTypeIds_.emplace_back(perfSampleRow.eventTypeId);
188     timestampTraces_.emplace_back(perfSampleRow.timestampTrace);
189     cpuIds_.emplace_back(perfSampleRow.cpuId);
190     threadStates_.emplace_back(perfSampleRow.threadState);
191     return Size() - 1;
192 }
SampleIds() const193 const std::deque<uint32_t> &PerfSample::SampleIds() const
194 {
195     return sampleIds_;
196 }
Tids() const197 const std::deque<uint32_t> &PerfSample::Tids() const
198 {
199     return tids_;
200 }
EventCounts() const201 const std::deque<uint64_t> &PerfSample::EventCounts() const
202 {
203     return eventCounts_;
204 }
EventTypeIds() const205 const std::deque<uint64_t> &PerfSample::EventTypeIds() const
206 {
207     return eventTypeIds_;
208 }
TimestampTraces() const209 const std::deque<uint64_t> &PerfSample::TimestampTraces() const
210 {
211     return timestampTraces_;
212 }
CpuIds() const213 const std::deque<uint64_t> &PerfSample::CpuIds() const
214 {
215     return cpuIds_;
216 }
ThreadStates() const217 const std::deque<DataIndex> &PerfSample::ThreadStates() const
218 {
219     return threadStates_;
220 }
221 
Clear()222 void PerfSample::Clear()
223 {
224     CacheBase::Clear();
225     sampleIds_.clear();
226     tids_.clear();
227     eventCounts_.clear();
228     eventTypeIds_.clear();
229     timestampTraces_.clear();
230     cpuIds_.clear();
231     threadStates_.clear();
232 }
233 
AppendNewPerfThread(uint32_t pid,uint32_t tid,DataIndex threadName)234 size_t PerfThread::AppendNewPerfThread(uint32_t pid, uint32_t tid, DataIndex threadName)
235 {
236     ids_.emplace_back(Size());
237     pids_.emplace_back(pid);
238     tids_.emplace_back(tid);
239     threadNames_.emplace_back(threadName);
240     return Size() - 1;
241 }
Pids() const242 const std::deque<uint32_t> &PerfThread::Pids() const
243 {
244     return pids_;
245 }
Tids() const246 const std::deque<uint32_t> &PerfThread::Tids() const
247 {
248     return tids_;
249 }
ThreadNames() const250 const std::deque<DataIndex> &PerfThread::ThreadNames() const
251 {
252     return threadNames_;
253 }
Clear()254 void PerfThread::Clear()
255 {
256     CacheBase::Clear();
257     tids_.clear();
258     pids_.clear();
259     threadNames_.clear();
260 }
AppendNewPerfReport(DataIndex type,DataIndex value)261 size_t PerfReport::AppendNewPerfReport(DataIndex type, DataIndex value)
262 {
263     ids_.emplace_back(Size());
264     types_.emplace_back(type);
265     values_.emplace_back(value);
266     return Size() - 1;
267 }
Types() const268 const std::deque<DataIndex> &PerfReport::Types() const
269 {
270     return types_;
271 }
Values() const272 const std::deque<DataIndex> &PerfReport::Values() const
273 {
274     return values_;
275 }
AppendNewPerfNapiAsync(const PerfNapiAsyncRow & perfNapiAsyncRow)276 size_t PerfNapiAsync::AppendNewPerfNapiAsync(const PerfNapiAsyncRow &perfNapiAsyncRow)
277 {
278     ids_.emplace_back(Size());
279     timeStamps_.emplace_back(perfNapiAsyncRow.timeStamp);
280     traceids_.emplace_back(perfNapiAsyncRow.traceid);
281     cpuIds_.emplace_back(perfNapiAsyncRow.cpuId);
282     internalTids_.emplace_back(perfNapiAsyncRow.threadId);
283     processIds_.emplace_back(perfNapiAsyncRow.processId);
284     callerCallchainids_.emplace_back(perfNapiAsyncRow.callerCallchainid);
285     calleeCallchainids_.emplace_back(perfNapiAsyncRow.calleeCallchainid);
286     perfSampleIds_.emplace_back(perfNapiAsyncRow.perfSampleId);
287     eventCounts_.emplace_back(perfNapiAsyncRow.eventCount);
288     eventTypeIds_.emplace_back(perfNapiAsyncRow.eventTypeId);
289     return Size() - 1;
290 }
Traceids() const291 const std::deque<DataIndex> &PerfNapiAsync::Traceids() const
292 {
293     return traceids_;
294 }
CpuIds() const295 const std::deque<uint8_t> &PerfNapiAsync::CpuIds() const
296 {
297     return cpuIds_;
298 }
ProcessIds() const299 const std::deque<uint32_t> &PerfNapiAsync::ProcessIds() const
300 {
301     return processIds_;
302 }
CallerCallchainids() const303 const std::deque<uint32_t> &PerfNapiAsync::CallerCallchainids() const
304 {
305     return callerCallchainids_;
306 }
CalleeCallchainids() const307 const std::deque<uint32_t> &PerfNapiAsync::CalleeCallchainids() const
308 {
309     return calleeCallchainids_;
310 }
PerfSampleIds() const311 const std::deque<uint64_t> &PerfNapiAsync::PerfSampleIds() const
312 {
313     return perfSampleIds_;
314 }
EventCounts() const315 const std::deque<uint64_t> &PerfNapiAsync::EventCounts() const
316 {
317     return eventCounts_;
318 }
EventTypeIds() const319 const std::deque<uint64_t> &PerfNapiAsync::EventTypeIds() const
320 {
321     return eventTypeIds_;
322 }
Clear()323 void PerfNapiAsync::Clear()
324 {
325     CacheBase::Clear();
326     traceids_.clear();
327     processIds_.clear();
328     callerCallchainids_.clear();
329     calleeCallchainids_.clear();
330     perfSampleIds_.clear();
331     eventCounts_.clear();
332     eventTypeIds_.clear();
333 }
334 } // namespace TraceStdtype
335 } // namespace SysTuning
336