• 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 #include "trace_data_cache_writer.h"
17 #include "log.h"
18 namespace SysTuning {
19 namespace TraceStreamer {
20 using namespace TraceStdtype;
~TraceDataCacheWriter()21 TraceDataCacheWriter::~TraceDataCacheWriter() {}
GetProcessInternalPid(uint32_t pid)22 InternalPid TraceDataCacheWriter::GetProcessInternalPid(uint32_t pid)
23 {
24     internalProcessesData_.emplace_back(pid);
25     return static_cast<InternalPid>(internalProcessesData_.size() - 1);
26 }
GetProcessData(InternalPid internalPid)27 Process* TraceDataCacheWriter::GetProcessData(InternalPid internalPid)
28 {
29     TS_ASSERT(internalPid < internalProcessesData_.size());
30     return &internalProcessesData_[internalPid];
31 }
32 
AppendNewProcessData(uint32_t pid,const std::string & name,uint64_t startTs)33 uint32_t TraceDataCacheWriter::AppendNewProcessData(uint32_t pid, const std::string& name, uint64_t startTs)
34 {
35     internalProcessesData_.emplace_back(pid);
36     auto& process = internalProcessesData_.back();
37     process.cmdLine_ = name;
38     process.startT_ = startTs;
39     return internalProcessesData_.size() - 1;
40 }
41 
NewInternalThread(uint32_t tid)42 InternalTid TraceDataCacheWriter::NewInternalThread(uint32_t tid)
43 {
44     internalThreadsData_.emplace_back(tid);
45     return static_cast<InternalTid>(internalThreadsData_.size() - 1);
46 }
GetThreadData(InternalTid internalTid)47 Thread* TraceDataCacheWriter::GetThreadData(InternalTid internalTid)
48 {
49     if (internalTid >= internalThreadsData_.size()) {
50         return nullptr;
51     }
52     return &internalThreadsData_[internalTid];
53 }
54 
UpdateTraceTime(uint64_t timestamp)55 void TraceDataCacheWriter::UpdateTraceTime(uint64_t timestamp)
56 {
57     if (timestamp) {
58         traceStartTime_ = std::min(traceStartTime_, timestamp);
59         traceEndTime_ = std::max(traceEndTime_, timestamp);
60     }
61 }
62 
MixTraceTime(uint64_t timestampMin,uint64_t timestampMax)63 void TraceDataCacheWriter::MixTraceTime(uint64_t timestampMin, uint64_t timestampMax)
64 {
65     if (timestampMin == std::numeric_limits<uint64_t>::max() || timestampMax == 0) {
66         return;
67     }
68     if (traceStartTime_ != std::numeric_limits<uint64_t>::max()) {
69         traceStartTime_ = std::max(traceStartTime_, timestampMin);
70     } else {
71         traceStartTime_ = timestampMin;
72     }
73     if (traceEndTime_) {
74         traceEndTime_ = std::min(traceEndTime_, timestampMax);
75     } else {
76         traceEndTime_ = timestampMax;
77     }
78 }
GetInternalSlicesData()79 CallStack* TraceDataCacheWriter::GetInternalSlicesData()
80 {
81     return &callstackData_;
82 }
GetIrqData()83 CallStack* TraceDataCacheWriter::GetIrqData()
84 {
85     return &irqData_;
86 }
87 
GetFilterData()88 Filter* TraceDataCacheWriter::GetFilterData()
89 {
90     return &filterData_;
91 }
92 
GetRawData()93 Raw* TraceDataCacheWriter::GetRawData()
94 {
95     return &rawData_;
96 }
97 
GetMeasureData()98 Measure* TraceDataCacheWriter::GetMeasureData()
99 {
100     return &measureData_;
101 }
102 
GetSysMemMeasureData()103 Measure* TraceDataCacheWriter::GetSysMemMeasureData()
104 {
105     return &sysMemMeasureData_;
106 }
GetProcessMeasureData()107 Measure* TraceDataCacheWriter::GetProcessMeasureData()
108 {
109     return &processMeasureData_;
110 }
111 
GetThreadStateData()112 ThreadState* TraceDataCacheWriter::GetThreadStateData()
113 {
114     return &threadStateData_;
115 }
116 
GetSchedSliceData()117 SchedSlice* TraceDataCacheWriter::GetSchedSliceData()
118 {
119     return &schedSliceData_;
120 }
121 
GetCpuMeasuresData()122 CpuMeasureFilter* TraceDataCacheWriter::GetCpuMeasuresData()
123 {
124     return &cpuMeasureData_;
125 }
126 
GetThreadMeasureFilterData()127 ThreadMeasureFilter* TraceDataCacheWriter::GetThreadMeasureFilterData()
128 {
129     return &threadMeasureFilterData_;
130 }
131 
GetThreadFilterData()132 ThreadMeasureFilter* TraceDataCacheWriter::GetThreadFilterData()
133 {
134     return &threadFilterData_;
135 }
136 
GetInstantsData()137 Instants* TraceDataCacheWriter::GetInstantsData()
138 {
139     return &instantsData_;
140 }
141 
GetProcessFilterData()142 ProcessMeasureFilter* TraceDataCacheWriter::GetProcessFilterData()
143 {
144     return &processFilterData_;
145 }
146 
GetProcessMeasureFilterData()147 ProcessMeasureFilter* TraceDataCacheWriter::GetProcessMeasureFilterData()
148 {
149     return &processMeasureFilterData_;
150 }
151 
GetClockEventFilterData()152 ClockEventData* TraceDataCacheWriter::GetClockEventFilterData()
153 {
154     return &clockEventFilterData_;
155 }
156 
GetClkEventFilterData()157 ClkEventData* TraceDataCacheWriter::GetClkEventFilterData()
158 {
159     return &clkEventFilterData_;
160 }
GetStatAndInfo()161 StatAndInfo* TraceDataCacheWriter::GetStatAndInfo()
162 {
163     return &stat_;
164 }
165 
GetMetaData()166 MetaData* TraceDataCacheWriter::GetMetaData()
167 {
168     return &metaData_;
169 }
170 
GetSymbolsData()171 SymbolsData* TraceDataCacheWriter::GetSymbolsData()
172 {
173     return &symbolsData_;
174 }
GetSysCallData()175 SysCall* TraceDataCacheWriter::GetSysCallData()
176 {
177     return &sysCallData_;
178 }
GetHilogData()179 LogInfo* TraceDataCacheWriter::GetHilogData()
180 {
181     return &hilogData_;
182 }
183 
GetNativeHookData()184 NativeHook* TraceDataCacheWriter::GetNativeHookData()
185 {
186     return &nativeHookData_;
187 }
188 
GetNativeHookFrameData()189 NativeHookFrame* TraceDataCacheWriter::GetNativeHookFrameData()
190 {
191     return &nativeHookFrameData_;
192 }
193 
GetHidumpData()194 Hidump* TraceDataCacheWriter::GetHidumpData()
195 {
196     return &hidumpData_;
197 }
GetPerfCallChainData()198 PerfCallChain* TraceDataCacheWriter::GetPerfCallChainData()
199 {
200     return &perfCallChain_;
201 }
GetPerfFilesData()202 PerfFiles* TraceDataCacheWriter::GetPerfFilesData()
203 {
204     return &perfFiles_;
205 }
GetPerfSampleData()206 PerfSample* TraceDataCacheWriter::GetPerfSampleData()
207 {
208     return &perfSample_;
209 }
GetPerfThreadData()210 PerfThread* TraceDataCacheWriter::GetPerfThreadData()
211 {
212     return &perfThread_;
213 }
GetPerfReportData()214 PerfReport* TraceDataCacheWriter::GetPerfReportData()
215 {
216     return &perfReport_;
217 }
GetArgSetData()218 ArgSet* TraceDataCacheWriter::GetArgSetData()
219 {
220     return &argSet_;
221 }
222 
GetDataTypeData()223 DataType* TraceDataCacheWriter::GetDataTypeData()
224 {
225     return &dataType_;
226 }
227 
GetSysMeasureFilterData()228 SysMeasureFilter* TraceDataCacheWriter::GetSysMeasureFilterData()
229 {
230     return &sysEvent_;
231 }
GetNetworkData()232 NetDetailData* TraceDataCacheWriter::GetNetworkData()
233 {
234     return &networkData_;
235 }
GetNetworkDetailData()236 NetDetailData* TraceDataCacheWriter::GetNetworkDetailData()
237 {
238     return &networkDetailData_;
239 }
GetDiskIOData()240 DiskIOData* TraceDataCacheWriter::GetDiskIOData()
241 {
242     return &diskIOData_;
243 }
244 
GetCpuUsageInfoData()245 CpuUsageDetailData* TraceDataCacheWriter::GetCpuUsageInfoData()
246 {
247     return &cpuUsageData_;
248 }
GetLiveProcessData()249 LiveProcessDetailData* TraceDataCacheWriter::GetLiveProcessData()
250 {
251     return &liveProcessDetailData_;
252 }
GetFileSystemSample()253 FileSystemSample* TraceDataCacheWriter::GetFileSystemSample()
254 {
255     return &fileSamplingTableData_;
256 }
GetEbpfCallStack()257 EbpfCallStackData* TraceDataCacheWriter::GetEbpfCallStack()
258 {
259     return &ebpfCallStackData_;
260 }
GetPagedMemorySampleData()261 PagedMemorySampleData* TraceDataCacheWriter::GetPagedMemorySampleData()
262 {
263     return &PagedMemorySampleData_;
264 }
265 #if WITH_EBPF_HELP
GetEbpfProcessMaps()266 EbpfProcessMaps* TraceDataCacheWriter::GetEbpfProcessMaps()
267 {
268     return &ebpfProcessMaps_;
269 }
GetEbpfElf()270 EbpfElf* TraceDataCacheWriter::GetEbpfElf()
271 {
272     return &ebpfElf_;
273 }
GetEbpfElfSymbol()274 EbpfElfSymbol* TraceDataCacheWriter::GetEbpfElfSymbol()
275 {
276     return &ebpfElfSymbol_;
277 }
278 #endif
GetAppNamesData()279 AppNames* TraceDataCacheWriter::GetAppNamesData()
280 {
281     return &appNames_;
282 }
GetSyseventMeasureData()283 SysEventMeasureData* TraceDataCacheWriter::GetSyseventMeasureData()
284 {
285     return &sysEventMeasureData_;
286 }
GetDeviceStateData()287 DeviceStateData* TraceDataCacheWriter::GetDeviceStateData()
288 {
289     return &deviceStateData_;
290 }
GetSmapsData()291 SmapsData* TraceDataCacheWriter::GetSmapsData()
292 {
293     return &smapsData_;
294 }
GetBioLatencySampleData()295 BioLatencySampleData* TraceDataCacheWriter::GetBioLatencySampleData()
296 {
297     return &bioLatencySampleData_;
298 }
299 
GetClockSnapshotData()300 ClockSnapshotData* TraceDataCacheWriter::GetClockSnapshotData()
301 {
302     return &clockSnapshotData_;
303 }
GetDataSourceClockIdData()304 DataSourceClockIdData* TraceDataCacheWriter::GetDataSourceClockIdData()
305 {
306     return &dataSourceClockIdData_;
307 }
Clear()308 void TraceDataCacheWriter::Clear()
309 {
310     rawData_.Clear();
311     threadStateData_.Clear();
312     instantsData_.Clear();
313 
314     filterData_.Clear();
315     processMeasureFilterData_.Clear();
316     clockEventFilterData_.Clear();
317     clkEventFilterData_.Clear();
318     processFilterData_.Clear();
319     threadMeasureFilterData_.Clear();
320     threadFilterData_.Clear();
321     dataDict_.Clear();
322 
323     schedSliceData_.Clear();
324     callstackData_.Clear();
325     irqData_.Clear();
326     hilogData_.Clear();
327     nativeHookData_.Clear();
328     nativeHookFrameData_.Clear();
329     hidumpData_.Clear();
330 
331     internalProcessesData_.clear();
332     internalThreadsData_.clear();
333 
334     measureData_.Clear();
335     cpuMeasureData_.Clear();
336 
337     metaData_.Clear();
338     symbolsData_.Clear();
339     sysCallData_.Clear();
340     argSet_.Clear();
341     dataType_.Clear();
342     sysEvent_.Clear();
343     networkData_.Clear();
344     networkDetailData_.Clear();
345     perfSample_.Clear();
346     perfCallChain_.Clear();
347     perfThread_.Clear();
348     perfFiles_.Clear();
349     perfReport_.Clear();
350     cpuUsageData_.Clear();
351     diskIOData_.Clear();
352     liveProcessDetailData_.Clear();
353     fileSamplingTableData_.Clear();
354     ebpfCallStackData_.Clear();
355     PagedMemorySampleData_.Clear();
356 #if WITH_EBPF_HELP
357     ebpfProcessMaps_.Clear();
358     ebpfElf_.Clear();
359     ebpfElfSymbol_.Clear();
360 #endif
361     appNames_.Clear();
362     sysEventMeasureData_.Clear();
363     deviceStateData_.Clear();
364     smapsData_.Clear();
365     bioLatencySampleData_.Clear();
366 }
367 } // namespace TraceStreamer
368 } // namespace SysTuning
369