• 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 #ifndef TRACE_DATA_CACHE_BASE_H
17 #define TRACE_DATA_CACHE_BASE_H
18 
19 #include <array>
20 #include <atomic>
21 #include <deque>
22 #include <map>
23 #include <stdexcept>
24 #include <string>
25 #include <vector>
26 #include "activity_monitor_stdtype.h"
27 #include "animation_stdtype.h"
28 #include "app_startup_stdtype.h"
29 #include "arkts_stdtype.h"
30 #include "base_stdtype.h"
31 #include "callstack_stdtype.h"
32 #include "common_stdtype.h"
33 #include "ebpf_stdtype.h"
34 #include "hilog_stdtype.h"
35 #include "hiperf_stdtype.h"
36 #include "hisysevent_stdtype.h"
37 #include "measure_stdtype.h"
38 #include "native_memory_stdtype.h"
39 #include "render_service_stdtype.h"
40 #include "sched_stdtype.h"
41 #include "syscall_stdtype.h"
42 #include "task_pool_stdtype.h"
43 namespace SysTuning {
44 namespace TraceStreamer {
45 using namespace TraceStdtype;
46 class TraceDataCacheBase {
47 public:
48     TraceDataCacheBase();
49     TraceDataCacheBase(const TraceDataCacheBase &) = delete;
50     TraceDataCacheBase &operator=(const TraceDataCacheBase &) = delete;
51     virtual ~TraceDataCacheBase() = default;
52 
53 public:
ThreadSize()54     size_t ThreadSize() const
55     {
56         return internalThreadsData_.size();
57     }
ProcessSize()58     size_t ProcessSize() const
59     {
60         return internalProcessesData_.size();
61     }
62 
63     void UpdataZeroThreadInfo();
DataDictSize()64     size_t DataDictSize() const
65     {
66         return dataDict_.Size();
67     }
UpdateTraceRange()68     void UpdateTraceRange()
69     {
70         metaData_.SetTraceDuration((traceEndTime_ - traceStartTime_) / SEC_TO_NS);
71     }
GetThreadStateValue(const std::string & status)72     uint64_t GetThreadStateValue(const std::string &status) const
73     {
74         if (threadStatus2Value_.count(status)) {
75             return threadStatus2Value_.at(status);
76         }
77         return INVALID_UINT64;
78     }
79     DataIndex GetDataIndex(std::string_view str);
80     DataIndex GetConstDataIndex(std::string_view str) const;
81     std::map<uint64_t, std::string> statusString_ = {{TASK_RUNNABLE, "R"},
82                                                      {TASK_INTERRUPTIBLE, "S"},
83                                                      {TASK_UNINTERRUPTIBLE, "D"},
84                                                      {TASK_UNINTERRUPTIBLE_IO, "D-IO"},
85                                                      {TASK_UNINTERRUPTIBLE_NIO, "D-NIO"},
86                                                      {TASK_RUNNING, "Running"},
87                                                      {TASK_STOPPED, "T"},
88                                                      {TASK_TRACED, "t"},
89                                                      {TASK_EXIT_DEAD, "X"},
90                                                      {TASK_ZOMBIE, "Z"},
91                                                      {TASK_PARKED, "P"},
92                                                      {TASK_DEAD, "I"},
93                                                      {TASK_DK, "DK"},
94                                                      {TASK_DK_IO, "DK-IO"},
95                                                      {TASK_DK_NIO, "DK-NIO"},
96                                                      {TASK_TRACED_KILL, "TK"},
97                                                      {TASK_WAKEKILL, "R+"},
98                                                      {TASK_NEW, "R+"},
99                                                      {TASK_RUNNABLE_BINDER, "R-B"},
100                                                      {TASK_MAX, "S"},
101                                                      {TASK_INVALID, "U"}};
102     std::map<std::string, uint64_t> threadStatus2Value_ = {};
103     uint64_t traceStartTime_ = std::numeric_limits<uint64_t>::max();
104     uint64_t traceEndTime_ = 0;
105 #ifdef IS_WASM
106     bool supportThread_ = false;
107 #else
108     bool supportThread_ = true;
109 #endif
110     uint8_t parserThreadNum_ = 4;
111     std::atomic<bool> isSplitFile_{false};
112 
113     Raw rawData_;
114     ThreadStateData threadStateData_;
115     Instants instantsData_;
116 
117     Filter filterData_;
118     ProcessMeasureFilter processMeasureFilterData_;
119     ClockEventData clockEventFilterData_;
120     ClkEventData clkEventFilterData_;
121     DataDict dataDict_;
122 
123     SchedSlice schedSliceData_;
124     CallStack callstackData_;
125     CallStack irqData_;
126     LogInfo hilogData_;
127     NativeHook nativeHookData_;
128     NativeHookFrame nativeHookFrameData_;
129     NativeHookStatistic nativeHookStatisticData_;
130     Hidump hidumpData_;
131     PerfSample perfSample_;
132     PerfCallChain perfCallChain_;
133     PerfThread perfThread_;
134     PerfFiles perfFiles_;
135     PerfReport perfReport_;
136 
137     std::deque<Process> internalProcessesData_ = {};
138     std::deque<Thread> internalThreadsData_ = {};
139 
140     Measure measureData_;
141     Measure sysMemMeasureData_;
142     Measure processMeasureData_;
143     CpuMeasureFilter cpuMeasureData_;
144 
145     StatAndInfo stat_;
146     MetaData metaData_;
147     SymbolsData symbolsData_;
148     SysCall sysCallData_;
149     ArgSet argSet_;
150     DataType dataType_;
151     SysMeasureFilter sysEvent_;
152     NetDetailData networkData_;
153     NetDetailData networkDetailData_;
154     CpuUsageDetailData cpuUsageData_;
155     DiskIOData diskIOData_;
156     LiveProcessDetailData liveProcessDetailData_;
157     FileSystemSample fileSamplingTableData_;
158     EbpfCallStackData ebpfCallStackData_;
159     PagedMemorySampleData pagedMemorySampleData_;
160     HiSysEventSubkeys sysEventNameIds_;
161     HiSysEventMeasureData sysEventMeasureData_;
162     HiSysEventDeviceStateData deviceStateData_;
163     TraceConfig traceConfigData_;
164     HiSysEventAllEventData hiSysEventAllEventData_;
165     SmapsData smapsData_;
166     BioLatencySampleData bioLatencySampleData_;
167     ClockSnapshotData clockSnapshotData_;
168     DataSourceClockIdData dataSourceClockIdData_;
169     FrameSlice frameSliceData_;
170     FrameMaps frameMapsData_;
171     GPUSlice gpuSliceData_;
172     TaskPoolInfo taskPoolInfo_;
173     JsHeapFiles jsHeapFilesData_;
174     JsHeapEdges jsHeapEdgesData_;
175     JsHeapInfo jsHeapInfoData_;
176     JsHeapLocation jsHeapLocationData_;
177     JsHeapNodes jsHeapNodesData_;
178     JsHeapSample jsHeapSampleData_;
179     JsHeapString jsHeapStringData_;
180     JsHeapTraceFuncInfo jsHeapTraceFuncInfoData_;
181     JsHeapTraceNode jsHeapTraceNodeData_;
182     JsCpuProfilerNode jsCpuProfilerNodeData_;
183     JsCpuProfilerSample jsCpuProfilerSampleData_;
184     JsConfig jsConfigData_;
185     AppStartup appStartupData_;
186     SoStaticInitalization soStaticInitalizationData_;
187     Animation animation_;
188     DeviceInfo deviceInfo_;
189     DynamicFrame dynamicFrame_;
190     AshMemData ashMemData_;
191     DmaMemData dmaMemData_;
192     GpuProcessMemData gpuProcessMemData_;
193     GpuWindowMemData gpuWindowMemData_;
194     CpuDumpInfo cpuDumpInfo_;
195     ProfileMemInfo profileMemInfo_;
196     RSImageDumpInfo rsImageDumpInfo_;
197 };
198 } // namespace TraceStreamer
199 } // namespace SysTuning
200 
201 #endif // TRACE_DATA_CACHE_BASE_H
202