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 "js_heap_trace_node_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { FILE_ID = 0, TRACE_NODE_ID, FUNCTION_INFO_INDEX, COUNT, SIZE, PARENT_ID };
JsHeapTraceNodeTable(const TraceDataCache * dataCache)21 JsHeapTraceNodeTable::JsHeapTraceNodeTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("file_id", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
25 tableColumn_.push_back(TableBase::ColumnInfo("function_info_index", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("count", "INTEGER"));
27 tableColumn_.push_back(TableBase::ColumnInfo("size", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("parent_id", "INTEGER"));
29 tablePriKey_.push_back("file_id");
30 }
31
~JsHeapTraceNodeTable()32 JsHeapTraceNodeTable::~JsHeapTraceNodeTable() {}
33
CreateCursor()34 std::unique_ptr<TableBase::Cursor> JsHeapTraceNodeTable::CreateCursor()
35 {
36 return std::make_unique<Cursor>(dataCache_, this);
37 }
38
Cursor(const TraceDataCache * dataCache,TableBase * table)39 JsHeapTraceNodeTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
40 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsHeapTraceNodeData().Size())),
41 jsHeapTraceNode_(dataCache->GetConstJsHeapTraceNodeData())
42 {
43 }
44
~Cursor()45 JsHeapTraceNodeTable::Cursor::~Cursor() {}
46
Column(int32_t col) const47 int32_t JsHeapTraceNodeTable::Cursor::Column(int32_t col) const
48 {
49 switch (static_cast<Index>(col)) {
50 case Index::FILE_ID:
51 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceNode_.FileIds()[CurrentRow()]));
52 break;
53 case Index::TRACE_NODE_ID:
54 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceNode_.TraceNodeIDs()[CurrentRow()]));
55 break;
56 case Index::FUNCTION_INFO_INDEX:
57 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceNode_.FunctionInfoIndexs()[CurrentRow()]));
58 break;
59 case Index::COUNT:
60 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceNode_.Counts()[CurrentRow()]));
61 break;
62 case Index::SIZE:
63 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceNode_.NodeSizes()[CurrentRow()]));
64 break;
65 case Index::PARENT_ID:
66 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceNode_.ParentIds()[CurrentRow()]));
67 break;
68 default:
69 TS_LOGF("Unregistered column : %d", col);
70 break;
71 }
72 return SQLITE_OK;
73 }
74 } // namespace TraceStreamer
75 } // namespace SysTuning
76