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