• 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 
16 #include "trace_data_cache_writer.h"
17 namespace SysTuning {
18 namespace TraceStreamer {
19 using namespace TraceStdtype;
~TraceDataCacheWriter()20 TraceDataCacheWriter::~TraceDataCacheWriter() {}
GetProcessInternalPid(uint32_t pid)21 InternalPid TraceDataCacheWriter::GetProcessInternalPid(uint32_t pid)
22 {
23     internalProcessesData_.emplace_back(pid);
24     return static_cast<InternalPid>(internalProcessesData_.size() - 1);
25 }
GetProcessData(InternalPid internalPid)26 Process *TraceDataCacheWriter::GetProcessData(InternalPid internalPid)
27 {
28     TS_ASSERT(internalPid < internalProcessesData_.size());
29     return &internalProcessesData_[internalPid];
30 }
31 
AppendNewProcessData(uint32_t pid,const std::string & name,uint64_t startTs)32 uint32_t TraceDataCacheWriter::AppendNewProcessData(uint32_t pid, const std::string &name, uint64_t startTs)
33 {
34     internalProcessesData_.emplace_back(pid);
35     auto &process = internalProcessesData_.back();
36     process.cmdLine_ = name;
37     process.startT_ = startTs;
38     return internalProcessesData_.size() - 1;
39 }
40 
NewInternalThread(uint32_t tid)41 InternalTid TraceDataCacheWriter::NewInternalThread(uint32_t tid)
42 {
43     internalThreadsData_.emplace_back(tid);
44     return static_cast<InternalTid>(internalThreadsData_.size() - 1);
45 }
GetThreadData(InternalTid internalTid)46 Thread *TraceDataCacheWriter::GetThreadData(InternalTid internalTid)
47 {
48     if (internalTid >= internalThreadsData_.size()) {
49         return nullptr;
50     }
51     return &internalThreadsData_[internalTid];
52 }
53 
UpdateTraceTime(uint64_t timeStamp)54 void TraceDataCacheWriter::UpdateTraceTime(uint64_t timeStamp)
55 {
56     if (isSplitFile_) {
57         return;
58     }
59     if (timeStamp) {
60         traceStartTime_ = std::min(traceStartTime_, timeStamp);
61         traceEndTime_ = std::max(traceEndTime_, timeStamp);
62     }
63 }
64 
UpdateTraceMinTime(uint64_t timestampMin)65 void TraceDataCacheWriter::UpdateTraceMinTime(uint64_t timestampMin)
66 {
67     if (isSplitFile_) {
68         return;
69     }
70     if (timestampMin) {
71         traceStartTime_ = timestampMin;
72     }
73 }
74 
MixTraceTime(uint64_t timestampMin,uint64_t timestampMax)75 void TraceDataCacheWriter::MixTraceTime(uint64_t timestampMin, uint64_t timestampMax)
76 {
77     if (isSplitFile_) {
78         return;
79     }
80     if (timestampMin == timestampMax) {
81         ++timestampMax;
82         --timestampMin;
83     }
84     if (timestampMin == std::numeric_limits<uint64_t>::max() || timestampMax == 0) {
85         return;
86     }
87     if (traceStartTime_ != std::numeric_limits<uint64_t>::max()) {
88         traceStartTime_ = std::min(traceStartTime_, timestampMin);
89     } else {
90         traceStartTime_ = timestampMin;
91     }
92     if (traceEndTime_) {
93         traceEndTime_ = std::max(traceEndTime_, timestampMax);
94     } else {
95         traceEndTime_ = timestampMax;
96     }
97 }
GetInternalSlicesData()98 CallStack *TraceDataCacheWriter::GetInternalSlicesData()
99 {
100     return &callstackData_;
101 }
GetIrqData()102 CallStack *TraceDataCacheWriter::GetIrqData()
103 {
104     return &irqData_;
105 }
106 
GetFilterData()107 Filter *TraceDataCacheWriter::GetFilterData()
108 {
109     return &filterData_;
110 }
111 
GetRawData()112 Raw *TraceDataCacheWriter::GetRawData()
113 {
114     return &rawData_;
115 }
116 
GetMeasureData()117 Measure *TraceDataCacheWriter::GetMeasureData()
118 {
119     return &measureData_;
120 }
121 
GetSysMemMeasureData()122 Measure *TraceDataCacheWriter::GetSysMemMeasureData()
123 {
124     return &sysMemMeasureData_;
125 }
GetProcessMeasureData()126 Measure *TraceDataCacheWriter::GetProcessMeasureData()
127 {
128     return &processMeasureData_;
129 }
130 
GetThreadStateData()131 ThreadStateData *TraceDataCacheWriter::GetThreadStateData()
132 {
133     return &threadStateData_;
134 }
135 
GetSchedSliceData()136 SchedSlice *TraceDataCacheWriter::GetSchedSliceData()
137 {
138     return &schedSliceData_;
139 }
140 
GetCpuMeasuresData()141 CpuMeasureFilter *TraceDataCacheWriter::GetCpuMeasuresData()
142 {
143     return &cpuMeasureData_;
144 }
145 
GetInstantsData()146 Instants *TraceDataCacheWriter::GetInstantsData()
147 {
148     return &instantsData_;
149 }
150 
GetProcessMeasureFilterData()151 ProcessMeasureFilter *TraceDataCacheWriter::GetProcessMeasureFilterData()
152 {
153     return &processMeasureFilterData_;
154 }
155 
GetClockEventFilterData()156 ClockEventData *TraceDataCacheWriter::GetClockEventFilterData()
157 {
158     return &clockEventFilterData_;
159 }
160 
GetClkEventFilterData()161 ClkEventData *TraceDataCacheWriter::GetClkEventFilterData()
162 {
163     return &clkEventFilterData_;
164 }
GetStatAndInfo()165 StatAndInfo *TraceDataCacheWriter::GetStatAndInfo()
166 {
167     return &stat_;
168 }
169 
GetMetaData()170 MetaData *TraceDataCacheWriter::GetMetaData()
171 {
172     return &metaData_;
173 }
174 
GetSymbolsData()175 SymbolsData *TraceDataCacheWriter::GetSymbolsData()
176 {
177     return &symbolsData_;
178 }
GetSysCallData()179 SysCall *TraceDataCacheWriter::GetSysCallData()
180 {
181     return &sysCallData_;
182 }
GetHilogData()183 LogInfo *TraceDataCacheWriter::GetHilogData()
184 {
185     return &hilogData_;
186 }
187 
GetNativeHookData()188 NativeHook *TraceDataCacheWriter::GetNativeHookData()
189 {
190     return &nativeHookData_;
191 }
192 
GetNativeHookFrameData()193 NativeHookFrame *TraceDataCacheWriter::GetNativeHookFrameData()
194 {
195     return &nativeHookFrameData_;
196 }
197 
GetNativeHookStatisticsData()198 NativeHookStatistic *TraceDataCacheWriter::GetNativeHookStatisticsData()
199 {
200     return &nativeHookStatisticData_;
201 }
GetHidumpData()202 Hidump *TraceDataCacheWriter::GetHidumpData()
203 {
204     return &hidumpData_;
205 }
GetPerfCallChainData()206 PerfCallChain *TraceDataCacheWriter::GetPerfCallChainData()
207 {
208     return &perfCallChain_;
209 }
GetPerfFilesData()210 PerfFiles *TraceDataCacheWriter::GetPerfFilesData()
211 {
212     return &perfFiles_;
213 }
GetPerfSampleData()214 PerfSample *TraceDataCacheWriter::GetPerfSampleData()
215 {
216     return &perfSample_;
217 }
GetPerfThreadData()218 PerfThread *TraceDataCacheWriter::GetPerfThreadData()
219 {
220     return &perfThread_;
221 }
GetPerfReportData()222 PerfReport *TraceDataCacheWriter::GetPerfReportData()
223 {
224     return &perfReport_;
225 }
GetArgSetData()226 ArgSet *TraceDataCacheWriter::GetArgSetData()
227 {
228     return &argSet_;
229 }
230 
GetDataTypeData()231 DataType *TraceDataCacheWriter::GetDataTypeData()
232 {
233     return &dataType_;
234 }
235 
GetSysMeasureFilterData()236 SysMeasureFilter *TraceDataCacheWriter::GetSysMeasureFilterData()
237 {
238     return &sysEvent_;
239 }
GetNetworkData()240 NetDetailData *TraceDataCacheWriter::GetNetworkData()
241 {
242     return &networkData_;
243 }
GetDiskIOData()244 DiskIOData *TraceDataCacheWriter::GetDiskIOData()
245 {
246     return &diskIOData_;
247 }
248 
GetCpuUsageInfoData()249 CpuUsageDetailData *TraceDataCacheWriter::GetCpuUsageInfoData()
250 {
251     return &cpuUsageData_;
252 }
GetLiveProcessData()253 LiveProcessDetailData *TraceDataCacheWriter::GetLiveProcessData()
254 {
255     return &liveProcessDetailData_;
256 }
GetFileSystemSample()257 FileSystemSample *TraceDataCacheWriter::GetFileSystemSample()
258 {
259     return &fileSamplingTableData_;
260 }
GetEbpfCallStack()261 EbpfCallStackData *TraceDataCacheWriter::GetEbpfCallStack()
262 {
263     return &ebpfCallStackData_;
264 }
GetPagedMemorySampleData()265 PagedMemorySampleData *TraceDataCacheWriter::GetPagedMemorySampleData()
266 {
267     return &pagedMemorySampleData_;
268 }
GetHiSysEventSubkeysData()269 HiSysEventSubkeys *TraceDataCacheWriter::GetHiSysEventSubkeysData()
270 {
271     return &sysEventNameIds_;
272 }
GetHiSysEventMeasureData()273 HiSysEventMeasureData *TraceDataCacheWriter::GetHiSysEventMeasureData()
274 {
275     return &sysEventMeasureData_;
276 }
GetHiSysEventDeviceStateData()277 HiSysEventDeviceStateData *TraceDataCacheWriter::GetHiSysEventDeviceStateData()
278 {
279     return &deviceStateData_;
280 }
GetTraceConfigData()281 TraceConfig *TraceDataCacheWriter::GetTraceConfigData()
282 {
283     return &traceConfigData_;
284 }
GetHiSysEventAllEventData()285 HiSysEventAllEventData *TraceDataCacheWriter::GetHiSysEventAllEventData()
286 {
287     return &hiSysEventAllEventData_;
288 }
GetSmapsData()289 SmapsData *TraceDataCacheWriter::GetSmapsData()
290 {
291     return &smapsData_;
292 }
GetBioLatencySampleData()293 BioLatencySampleData *TraceDataCacheWriter::GetBioLatencySampleData()
294 {
295     return &bioLatencySampleData_;
296 }
297 
GetClockSnapshotData()298 ClockSnapshotData *TraceDataCacheWriter::GetClockSnapshotData()
299 {
300     return &clockSnapshotData_;
301 }
GetDataSourceClockIdData()302 DataSourceClockIdData *TraceDataCacheWriter::GetDataSourceClockIdData()
303 {
304     return &dataSourceClockIdData_;
305 }
GetFrameSliceData()306 FrameSlice *TraceDataCacheWriter::GetFrameSliceData()
307 {
308     return &frameSliceData_;
309 }
GetFrameMapsData()310 FrameMaps *TraceDataCacheWriter::GetFrameMapsData()
311 {
312     return &frameMapsData_;
313 }
314 
GetGPUSliceData()315 GPUSlice *TraceDataCacheWriter::GetGPUSliceData()
316 {
317     return &gpuSliceData_;
318 }
GetTaskPoolData()319 TaskPoolInfo *TraceDataCacheWriter::GetTaskPoolData()
320 {
321     return &taskPoolInfo_;
322 }
GetJsHeapFilesData()323 JsHeapFiles *TraceDataCacheWriter::GetJsHeapFilesData()
324 {
325     return &jsHeapFilesData_;
326 }
GetJsHeapEdgesData()327 JsHeapEdges *TraceDataCacheWriter::GetJsHeapEdgesData()
328 {
329     return &jsHeapEdgesData_;
330 }
GetJsHeapInfoData()331 JsHeapInfo *TraceDataCacheWriter::GetJsHeapInfoData()
332 {
333     return &jsHeapInfoData_;
334 }
GetJsHeapLocationData()335 JsHeapLocation *TraceDataCacheWriter::GetJsHeapLocationData()
336 {
337     return &jsHeapLocationData_;
338 }
GetJsHeapNodesData()339 JsHeapNodes *TraceDataCacheWriter::GetJsHeapNodesData()
340 {
341     return &jsHeapNodesData_;
342 }
GetJsHeapSampleData()343 JsHeapSample *TraceDataCacheWriter::GetJsHeapSampleData()
344 {
345     return &jsHeapSampleData_;
346 }
GetJsHeapStringData()347 JsHeapString *TraceDataCacheWriter::GetJsHeapStringData()
348 {
349     return &jsHeapStringData_;
350 }
GetJsHeapTraceFuncInfoData()351 JsHeapTraceFuncInfo *TraceDataCacheWriter::GetJsHeapTraceFuncInfoData()
352 {
353     return &jsHeapTraceFuncInfoData_;
354 }
GetJsHeapTraceNodeData()355 JsHeapTraceNode *TraceDataCacheWriter::GetJsHeapTraceNodeData()
356 {
357     return &jsHeapTraceNodeData_;
358 }
GetJsCpuProfilerNodeData()359 JsCpuProfilerNode *TraceDataCacheWriter::GetJsCpuProfilerNodeData()
360 {
361     return &jsCpuProfilerNodeData_;
362 }
GetJsCpuProfilerSampleData()363 JsCpuProfilerSample *TraceDataCacheWriter::GetJsCpuProfilerSampleData()
364 {
365     return &jsCpuProfilerSampleData_;
366 }
GetJsConfigData()367 JsConfig *TraceDataCacheWriter::GetJsConfigData()
368 {
369     return &jsConfigData_;
370 }
GetAppStartupData()371 AppStartup *TraceDataCacheWriter::GetAppStartupData()
372 {
373     return &appStartupData_;
374 }
GetSoStaticInitalizationData()375 SoStaticInitalization *TraceDataCacheWriter::GetSoStaticInitalizationData()
376 {
377     return &soStaticInitalizationData_;
378 }
GetAnimation()379 Animation *TraceDataCacheWriter::GetAnimation()
380 {
381     return &animation_;
382 }
GetDeviceInfo()383 DeviceInfo *TraceDataCacheWriter::GetDeviceInfo()
384 {
385     return &deviceInfo_;
386 }
GetDynamicFrame()387 DynamicFrame *TraceDataCacheWriter::GetDynamicFrame()
388 {
389     return &dynamicFrame_;
390 }
GetAshMemData()391 AshMemData *TraceDataCacheWriter::GetAshMemData()
392 {
393     return &ashMemData_;
394 }
GetDmaMemData()395 DmaMemData *TraceDataCacheWriter::GetDmaMemData()
396 {
397     return &dmaMemData_;
398 }
GetGpuProcessMemData()399 GpuProcessMemData *TraceDataCacheWriter::GetGpuProcessMemData()
400 {
401     return &gpuProcessMemData_;
402 }
GetGpuWindowMemData()403 GpuWindowMemData *TraceDataCacheWriter::GetGpuWindowMemData()
404 {
405     return &gpuWindowMemData_;
406 }
GetCpuDumpInfo()407 CpuDumpInfo *TraceDataCacheWriter::GetCpuDumpInfo()
408 {
409     return &cpuDumpInfo_;
410 }
GetProfileMemInfo()411 ProfileMemInfo *TraceDataCacheWriter::GetProfileMemInfo()
412 {
413     return &profileMemInfo_;
414 }
GetRSImageDumpInfo()415 RSImageDumpInfo *TraceDataCacheWriter::GetRSImageDumpInfo()
416 {
417     return &rsImageDumpInfo_;
418 }
ClearMeasure()419 void TraceDataCacheWriter::ClearMeasure()
420 {
421     filterData_.Clear();
422     measureData_.Clear();
423     cpuMeasureData_.Clear();
424     clockEventFilterData_.Clear();
425     clkEventFilterData_.Clear();
426     processMeasureFilterData_.Clear();
427 }
ClearHiperf()428 void TraceDataCacheWriter::ClearHiperf()
429 {
430     perfSample_.Clear();
431     perfCallChain_.Clear();
432     perfThread_.Clear();
433     perfFiles_.Clear();
434     perfReport_.Clear();
435 }
ClearArkTs()436 void TraceDataCacheWriter::ClearArkTs()
437 {
438     jsHeapFilesData_.Clear();
439     jsHeapEdgesData_.Clear();
440     jsHeapInfoData_.Clear();
441     jsHeapLocationData_.Clear();
442     jsHeapNodesData_.Clear();
443     jsHeapSampleData_.Clear();
444     jsHeapStringData_.Clear();
445     jsHeapTraceFuncInfoData_.Clear();
446     jsHeapTraceNodeData_.Clear();
447     jsCpuProfilerNodeData_.Clear();
448     jsCpuProfilerSampleData_.Clear();
449     jsConfigData_.Clear();
450 }
ClearNativeMemory()451 void TraceDataCacheWriter::ClearNativeMemory()
452 {
453     nativeHookData_.Clear();
454     nativeHookFrameData_.Clear();
455 }
ClearBase()456 void TraceDataCacheWriter::ClearBase()
457 {
458     internalProcessesData_.clear();
459     internalThreadsData_.clear();
460     metaData_.Clear();
461     symbolsData_.Clear();
462     argSet_.Clear();
463     dataType_.Clear();
464     dataDict_.Clear();
465 }
ClearEbpf()466 void TraceDataCacheWriter::ClearEbpf()
467 {
468     fileSamplingTableData_.Clear();
469     ebpfCallStackData_.Clear();
470     pagedMemorySampleData_.Clear();
471     bioLatencySampleData_.Clear();
472 }
ClearTemplate()473 void TraceDataCacheWriter::ClearTemplate()
474 {
475     // task pool business
476     taskPoolInfo_.Clear();
477     // app start up business
478     appStartupData_.Clear();
479     soStaticInitalizationData_.Clear();
480     // animation business
481     animation_.Clear();
482     deviceInfo_.Clear();
483     dynamicFrame_.Clear();
484 }
Clear()485 void TraceDataCacheWriter::Clear()
486 {
487     ClearBase();
488     ClearMeasure();
489     ClearHiperf();
490     ClearArkTs();
491     ClearNativeMemory();
492     ClearEbpf();
493     ClearTemplate();
494     rawData_.Clear();
495     threadStateData_.Clear();
496     instantsData_.Clear();
497     schedSliceData_.Clear();
498     callstackData_.Clear();
499     irqData_.Clear();
500     hilogData_.Clear();
501     hidumpData_.Clear();
502     sysCallData_.Clear();
503     sysEvent_.Clear();
504     networkData_.Clear();
505     networkDetailData_.Clear();
506     cpuUsageData_.Clear();
507     diskIOData_.Clear();
508     liveProcessDetailData_.Clear();
509     sysEventNameIds_.Clear();
510     sysEventMeasureData_.Clear();
511     deviceStateData_.Clear();
512     smapsData_.Clear();
513     ashMemData_.Clear();
514     dmaMemData_.Clear();
515     gpuProcessMemData_.Clear();
516     gpuWindowMemData_.Clear();
517     gpuSliceData_.Clear();
518     frameMapsData_.Clear();
519     frameSliceData_.Clear();
520 }
521 } // namespace TraceStreamer
522 } // namespace SysTuning
523