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.h"
17 #include "animation_table.h"
18 #include "app_startup_table.h"
19 #include "appname_table.h"
20 #include "args_table.h"
21 #include "bio_latency_sample_table.h"
22 #include "callstack_table.h"
23 #include "clk_event_filter_table.h"
24 #include "clock_event_filter_table.h"
25 #include "clock_snapshot_table.h"
26 #include "cpu_measure_filter_table.h"
27 #include "cpu_usage_info_table.h"
28 #include "data_dict_table.h"
29 #include "data_type_table.h"
30 #include "datasource_clockid_table.h"
31 #include "device_info_table.h"
32 #include "device_state_table.h"
33 #include "disk_io_table.h"
34 #include "dynamic_frame_table.h"
35 #include "ebpf_callstack_table.h"
36 #if WITH_EBPF_HELP
37 #include "ebpf_elf_symbol_table.h"
38 #include "ebpf_elf_table.h"
39 #include "ebpf_process_maps_table.h"
40 #endif
41 #include "file_system_sample_table.h"
42 #include "filter_table.h"
43 #include "frame_maps_table.h"
44 #include "frame_slice_table.h"
45 #include "gpu_slice_table.h"
46 #include "js_config_table.h"
47 #include "js_cpu_profiler_node_table.h"
48 #include "js_cpu_profiler_sample_table.h"
49 #include "js_heap_edges_table.h"
50 #include "js_heap_files_table.h"
51 #include "js_heap_info_table.h"
52 #include "js_heap_location_table.h"
53 #include "js_heap_nodes_table.h"
54 #include "js_heap_sample_table.h"
55 #include "js_heap_string_table.h"
56 #include "js_heap_trace_function_info_table.h"
57 #include "js_heap_trace_node_table.h"
58 #include "hidump_table.h"
59 #include "instants_table.h"
60 #include "irq_table.h"
61 #include "live_process_table.h"
62 #include "log_table.h"
63 #include "measure_filter_table.h"
64 #include "measure_table.h"
65 #include "meta_table.h"
66 #include "native_hook_frame_table.h"
67 #include "native_hook_statistic_table.h"
68 #include "native_hook_table.h"
69 #include "native_hook_statistic_table.h"
70 #include "network_table.h"
71 #include "paged_memory_sample_table.h"
72 #include "perf_call_chain_table.h"
73 #include "perf_files_table.h"
74 #include "perf_report_table.h"
75 #include "perf_sample_table.h"
76 #include "perf_thread_table.h"
77 #include "process_filter_table.h"
78 #include "process_measure_filter_table.h"
79 #include "process_table.h"
80 #include "range_table.h"
81 #include "raw_table.h"
82 #include "sched_slice_table.h"
83 #include "smaps_table.h"
84 #include "span_join.h"
85 #include "sqlite3.h"
86 #include "stat_table.h"
87 #include "so_static_initalization_table.h"
88 #include "symbols_table.h"
89 #include "sysevent_measure_table.h"
90 #include "system_call_table.h"
91 #include "system_event_filter_table.h"
92 #include "table_base.h"
93 #include "task_pool_table.h"
94 #include "thread_filter_table.h"
95 #include "thread_state_table.h"
96 #include "thread_table.h"
97 #include "trace_config_table.h"
98 #include "memory_ashmem_table.h"
99 #include "memory_dma_table.h"
100 #include "memory_process_gpu_table.h"
101 #include "memory_window_gpu_table.h"
102
103 namespace SysTuning {
104 namespace TraceStreamer {
TraceDataCache()105 TraceDataCache::TraceDataCache()
106 {
107 InitDB();
108 }
109
~TraceDataCache()110 TraceDataCache::~TraceDataCache() {}
111
InitDB()112 void TraceDataCache::InitDB()
113 {
114 if (dbInited_) {
115 return;
116 }
117 #ifdef USE_VTABLE
118 TableBase::TableDeclare<AnimationTable>(*db_, this, "animation");
119 TableBase::TableDeclare<DynamicFrameTable>(*db_, this, "dynamic_frame");
120 TableBase::TableDeclare<ProcessTable>(*db_, this, "process");
121 TableBase::TableDeclare<SchedSliceTable>(*db_, this, "sched_slice");
122 TableBase::TableDeclare<CallStackTable>(*db_, this, "callstack");
123 TableBase::TableDeclare<ThreadTable>(*db_, this, "thread");
124 TableBase::TableDeclare<ThreadStateTable>(*db_, this, "thread_state");
125 TableBase::TableDeclare<ThreadFilterTable>(*db_, this, "thread_filter");
126 TableBase::TableDeclare<ProcessFilterTable>(*db_, this, "process_filter");
127 TableBase::TableDeclare<MeasureFilterTable>(*db_, this, "measure_filter");
128 TableBase::TableDeclare<IrqTable>(*db_, this, "irq");
129 TableBase::TableDeclare<DataDictTable>(*db_, this, "data_dict");
130 TableBase::TableDeclare<RawTable>(*db_, this, "raw");
131 TableBase::TableDeclare<SymbolsTable>(*db_, this, "symbols");
132 TableBase::TableDeclare<DataTypeTable>(*db_, this, "data_type");
133 TableBase::TableDeclare<HidumpTable>(*db_, this, "hidump");
134 TableBase::TableDeclare<NativeHookTable>(*db_, this, "native_hook");
135 TableBase::TableDeclare<NativeHookFrameTable>(*db_, this, "native_hook_frame");
136 TableBase::TableDeclare<NativeHookStatisticTable>(*db_, this, "native_hook_statistic");
137 TableBase::TableDeclare<SpanJoin>(*db_, this, "span_join");
138
139 // no id
140 TableBase::TableDeclare<DeviceInfoTable>(*db_, this, "device_info");
141 TableBase::TableDeclare<InstantsTable>(*db_, this, "instant");
142 TableBase::TableDeclare<MeasureTable>(*db_, this, "measure");
143 TableBase::TableDeclare<MeasureTable>(*db_, this, "sys_mem_measure");
144 TableBase::TableDeclare<MeasureTable>(*db_, this, "process_measure");
145 TableBase::TableDeclare<RangeTable>(*db_, this, "trace_range");
146 TableBase::TableDeclare<StatTable>(*db_, this, "stat");
147 TableBase::TableDeclare<SystemCallTable>(*db_, this, "syscall");
148 TableBase::TableDeclare<MetaTable>(*db_, this, "meta");
149 TableBase::TableDeclare<LogTable>(*db_, this, "log");
150 TableBase::TableDeclare<NetworkTable>(*db_, this, "network");
151
152 // id is not real id
153 TableBase::TableDeclare<CpuMeasureFilterTable>(*db_, this, "cpu_measure_filter");
154 TableBase::TableDeclare<FilterTable>(*db_, this, "measure_filter");
155 TableBase::TableDeclare<ProcessMeasureFilterTable>(*db_, this, "process_measure_filter");
156 TableBase::TableDeclare<ClockEventFilterTable>(*db_, this, "clock_event_filter");
157 TableBase::TableDeclare<ClkEventFilterTable>(*db_, this, "clk_event_filter");
158 TableBase::TableDeclare<TaskPoolTable>(*db_, this, "task_pool");
159 TableBase::TableDeclare<JsHeapFilesTable>(*db_, this, "js_heap_files");
160 TableBase::TableDeclare<JsHeapEdgesTable>(*db_, this, "js_heap_edges");
161 TableBase::TableDeclare<JsHeapInfoTable>(*db_, this, "js_heap_info");
162 TableBase::TableDeclare<JsHeapLocationTable>(*db_, this, "js_heap_location");
163 TableBase::TableDeclare<JsHeapNodesTable>(*db_, this, "js_heap_nodes");
164 TableBase::TableDeclare<JsHeapSampleTable>(*db_, this, "js_heap_sample");
165 TableBase::TableDeclare<JsHeapStringTable>(*db_, this, "js_heap_string");
166 TableBase::TableDeclare<JsHeapTraceFunctionInfoTable>(*db_, this, "js_heap_trace_function_info");
167 TableBase::TableDeclare<JsHeapTraceNodeTable>(*db_, this, "js_heap_trace_node");
168 TableBase::TableDeclare<JsCpuProfilerNodeTable>(*db_, this, "js_cpu_profiler_node");
169 TableBase::TableDeclare<JsCpuProfilerSampleTable>(*db_, this, "js_cpu_profiler_sample");
170 TableBase::TableDeclare<JsConfigTable>(*db_, this, "js_config");
171 TableBase::TableDeclare<ArgsTable>(*db_, this, "args");
172
173 TableBase::TableDeclare<SystemEventFilterTable>(*db_, this, "sys_event_filter");
174 TableBase::TableDeclare<DiskIOTable>(*db_, this, "diskio");
175 TableBase::TableDeclare<CpuUsageInfoTable>(*db_, this, "cpu_usage");
176 TableBase::TableDeclare<LiveProcessTable>(*db_, this, "live_process");
177 TableBase::TableDeclare<FileSystemSampleTable>(*db_, this, "file_system_sample");
178 TableBase::TableDeclare<EbpfCallStackTable>(*db_, this, "ebpf_callstack");
179 TableBase::TableDeclare<PagedMemorySampleTable>(*db_, this, "paged_memory_sample");
180 #if WITH_EBPF_HELP
181 TableBase::TableDeclare<EbpfProcessMapsTable>(*db_, this, "ebpf_process_maps");
182 TableBase::TableDeclare<EbpfElfTable>(*db_, this, "ebpf_elf");
183 TableBase::TableDeclare<EbpfElfSymbolTable>(*db_, this, "ebpf_elf_symbol");
184 #endif
185 TableBase::TableDeclare<AppnameTable>(*db_, this, "app_name");
186 TableBase::TableDeclare<SysEventMeasureTable>(*db_, this, "hisys_event_measure");
187 TableBase::TableDeclare<TraceConfigTable>(*db_, this, "trace_config");
188 TableBase::TableDeclare<DeviceStateTable>(*db_, this, "device_state");
189 TableBase::TableDeclare<SmapsTable>(*db_, this, "smaps");
190 TableBase::TableDeclare<BioLatencySampleTable>(*db_, this, "bio_latency_sample");
191 TableBase::TableDeclare<DataSourceClockIdTableTable>(*db_, this, "datasource_clockid");
192 TableBase::TableDeclare<ClockSnapShotTable>(*db_, this, "clock_snapshot");
193 TableBase::TableDeclare<FrameSliceTable>(*db_, this, "frame_slice");
194 TableBase::TableDeclare<FrameMapsTable>(*db_, this, "frame_maps");
195 TableBase::TableDeclare<GPUSliceTable>(*db_, this, "gpu_slice");
196 TableBase::TableDeclare<AppStartupTable>(*db_, this, "app_startup");
197 TableBase::TableDeclare<SoStaticInitalizationTable>(*db_, this, "static_initalize");
198 TableBase::TableDeclare<MemoryAshMemTable>(*db_, this, "memory_ashmem");
199 TableBase::TableDeclare<MemoryDmaTable>(*db_, this, "memory_dma");
200 TableBase::TableDeclare<MemoryProcessGpuTable>(*db_, this, "memory_process_gpu");
201 TableBase::TableDeclare<MemoryWindowGpuTable>(*db_, this, "memory_window_gpu");
202
203 TableBase::TableDeclare<PerfReportTable>(*db_, this, "perf_report");
204 TableBase::TableDeclare<PerfSampleTable>(*db_, this, "perf_sample");
205 TableBase::TableDeclare<PerfCallChainTable>(*db_, this, "perf_callchain");
206 TableBase::TableDeclare<PerfThreadTable>(*db_, this, "perf_thread");
207 TableBase::TableDeclare<PerfFilesTable>(*db_, this, "perf_files");
208 #else
209 TableBase::TableDeclare<AnimationTable>(*db_, this, "_animation");
210 TableBase::TableDeclare<DynamicFrameTable>(*db_, this, "_dynamic_frame");
211 TableBase::TableDeclare<ProcessTable>(*db_, this, "_process");
212 TableBase::TableDeclare<SchedSliceTable>(*db_, this, "_sched_slice");
213 TableBase::TableDeclare<CallStackTable>(*db_, this, "_callstack");
214 TableBase::TableDeclare<ThreadTable>(*db_, this, "_thread");
215 TableBase::TableDeclare<ThreadStateTable>(*db_, this, "_thread_state");
216 TableBase::TableDeclare<ThreadFilterTable>(*db_, this, "_thread_filter");
217 TableBase::TableDeclare<ProcessFilterTable>(*db_, this, "_process_filter");
218 TableBase::TableDeclare<MeasureFilterTable>(*db_, this, "_measure_filter");
219 TableBase::TableDeclare<IrqTable>(*db_, this, "_irq");
220 TableBase::TableDeclare<DataDictTable>(*db_, this, "_data_dict");
221 TableBase::TableDeclare<RawTable>(*db_, this, "_raw");
222 TableBase::TableDeclare<SymbolsTable>(*db_, this, "_symbols");
223 TableBase::TableDeclare<DataTypeTable>(*db_, this, "_data_type");
224 TableBase::TableDeclare<HidumpTable>(*db_, this, "_hidump");
225 TableBase::TableDeclare<NativeHookTable>(*db_, this, "_native_hook");
226 TableBase::TableDeclare<NativeHookFrameTable>(*db_, this, "_native_hook_frame");
227 TableBase::TableDeclare<NativeHookStatisticTable>(*db_, this, "_native_hook_statistic");
228 TableBase::TableDeclare<SpanJoin>(*db_, this, "_span_join");
229
230 // no id
231 TableBase::TableDeclare<DeviceInfoTable>(*db_, this, "_device_info");
232 TableBase::TableDeclare<InstantsTable>(*db_, this, "_instant");
233 TableBase::TableDeclare<MeasureTable>(*db_, this, "_measure");
234 TableBase::TableDeclare<MeasureTable>(*db_, this, "_sys_mem_measure");
235 TableBase::TableDeclare<MeasureTable>(*db_, this, "_process_measure");
236 TableBase::TableDeclare<RangeTable>(*db_, this, "_trace_range");
237 TableBase::TableDeclare<StatTable>(*db_, this, "_stat");
238 TableBase::TableDeclare<SystemCallTable>(*db_, this, "_syscall");
239 TableBase::TableDeclare<MetaTable>(*db_, this, "_meta");
240 TableBase::TableDeclare<LogTable>(*db_, this, "_log");
241 TableBase::TableDeclare<NetworkTable>(*db_, this, "_network");
242
243 // id is not real id
244 TableBase::TableDeclare<CpuMeasureFilterTable>(*db_, this, "_cpu_measure_filter");
245 TableBase::TableDeclare<FilterTable>(*db_, this, "_measure_filter");
246 TableBase::TableDeclare<ProcessMeasureFilterTable>(*db_, this, "_process_measure_filter");
247 TableBase::TableDeclare<ClockEventFilterTable>(*db_, this, "_clock_event_filter");
248 TableBase::TableDeclare<ClkEventFilterTable>(*db_, this, "_clk_event_filter");
249 TableBase::TableDeclare<TaskPoolTable>(*db_, this, "_task_pool");
250 TableBase::TableDeclare<JsHeapFilesTable>(*db_, this, "_js_heap_files");
251 TableBase::TableDeclare<JsHeapEdgesTable>(*db_, this, "_js_heap_edges");
252 TableBase::TableDeclare<JsHeapInfoTable>(*db_, this, "_js_heap_info");
253 TableBase::TableDeclare<JsHeapLocationTable>(*db_, this, "_js_heap_location");
254 TableBase::TableDeclare<JsHeapNodesTable>(*db_, this, "_js_heap_nodes");
255 TableBase::TableDeclare<JsHeapSampleTable>(*db_, this, "_js_heap_sample");
256 TableBase::TableDeclare<JsHeapStringTable>(*db_, this, "_js_heap_string");
257 TableBase::TableDeclare<JsHeapTraceFunctionInfoTable>(*db_, this, "_js_heap_trace_function_info");
258 TableBase::TableDeclare<JsHeapTraceNodeTable>(*db_, this, "_js_heap_trace_node");
259 TableBase::TableDeclare<JsCpuProfilerNodeTable>(*db_, this, "_js_cpu_Perfiler_Node");
260 TableBase::TableDeclare<JsCpuProfilerSampleTable>(*db_, this, "_js_cpu_Perfiler_Sample");
261 TableBase::TableDeclare<JsConfigTable>(*db_, this, "_js_config");
262 TableBase::TableDeclare<ArgsTable>(*db_, this, "_args");
263 TableBase::TableDeclare<SystemEventFilterTable>(*db_, this, "_sys_event_filter");
264 TableBase::TableDeclare<DiskIOTable>(*db_, this, "_diskio");
265 TableBase::TableDeclare<CpuUsageInfoTable>(*db_, this, "_cpu_usage");
266 TableBase::TableDeclare<LiveProcessTable>(*db_, this, "_live_process");
267 TableBase::TableDeclare<FileSystemSampleTable>(*db_, this, "_file_system_sample");
268 TableBase::TableDeclare<EbpfCallStackTable>(*db_, this, "_ebpf_callstack");
269 TableBase::TableDeclare<PagedMemorySampleTable>(*db_, this, "_paged_memory_sample");
270 TableBase::TableDeclare<SmapsTable>(*db_, this, "_smaps");
271 TableBase::TableDeclare<BioLatencySampleTable>(*db_, this, "_bio_latency_sample");
272 TableBase::TableDeclare<DataSourceClockIdTableTable>(*db_, this, "_datasource_clockid");
273 TableBase::TableDeclare<ClockSnapShotTable>(*db_, this, "_clock_snapshot");
274 TableBase::TableDeclare<FrameSliceTable>(*db_, this, "_frame_slice");
275 TableBase::TableDeclare<FrameMapsTable>(*db_, this, "_frame_maps");
276 TableBase::TableDeclare<GPUSliceTable>(*db_, this, "_gpu_slice");
277 TableBase::TableDeclare<AppStartupTable>(*db_, this, "_app_startup");
278 TableBase::TableDeclare<SoStaticInitalizationTable>(*db_, this, "_static_initalize");
279 TableBase::TableDeclare<MemoryAshMemTable>(*db_, this, "_memory_ashmem");
280 TableBase::TableDeclare<MemoryDmaTable>(*db_, this, "_memory_dma");
281 TableBase::TableDeclare<MemoryProcessGpuTable>(*db_, this, "_memory_process_gpu");
282 TableBase::TableDeclare<MemoryWindowGpuTable>(*db_, this, "_memory_window_gpu");
283 #if WITH_EBPF_HELP
284 TableBase::TableDeclare<EbpfProcessMapsTable>(*db_, this, "_ebpf_process_maps");
285 TableBase::TableDeclare<EbpfElfTable>(*db_, this, "_ebpf_elf");
286 TableBase::TableDeclare<EbpfElfSymbolTable>(*db_, this, "_ebpf_elf_symbol");
287 #endif
288 TableBase::TableDeclare<AppnameTable>(*db_, this, "_app_name");
289 TableBase::TableDeclare<SysEventMeasureTable>(*db_, this, "_hisys_event_measure");
290 TableBase::TableDeclare<DeviceStateTable>(*db_, this, "_device_state");
291 TableBase::TableDeclare<TraceConfigTable>(*db_, this, "_trace_config");
292 TableBase::TableDeclare<PerfReportTable>(*db_, this, "_perf_report");
293 TableBase::TableDeclare<PerfSampleTable>(*db_, this, "_perf_sample");
294 TableBase::TableDeclare<PerfCallChainTable>(*db_, this, "_perf_callchain");
295 TableBase::TableDeclare<PerfThreadTable>(*db_, this, "_perf_thread");
296 TableBase::TableDeclare<PerfFilesTable>(*db_, this, "_perf_files");
297 #endif
298 dbInited_ = true;
299 }
AnimationTraceEnabled()300 bool TraceDataCache::AnimationTraceEnabled()
301 {
302 return animationTraceEnabled_;
303 }
UpdateAnimationTraceStatus(bool status)304 void TraceDataCache::UpdateAnimationTraceStatus(bool status)
305 {
306 animationTraceEnabled_ = status;
307 }
TaskPoolTraceEnabled()308 bool TraceDataCache::TaskPoolTraceEnabled()
309 {
310 return taskPoolTraceEnabled_;
311 }
UpdateTaskPoolTraceStatus(bool status)312 void TraceDataCache::UpdateTaskPoolTraceStatus(bool status)
313 {
314 taskPoolTraceEnabled_ = status;
315 }
AppStartTraceEnabled()316 bool TraceDataCache::AppStartTraceEnabled()
317 {
318 return appStartTraceEnabled_;
319 }
UpdateAppStartTraceStatus(bool status)320 void TraceDataCache::UpdateAppStartTraceStatus(bool status)
321 {
322 appStartTraceEnabled_ = status;
323 }
324 } // namespace TraceStreamer
325 } // namespace SysTuning
326