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_function_info_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { FILE_ID = 0, FUNCTION_INDEX, FUNCTION_ID, NAME, SCRIPT_NAME, SCRIPT_ID, LINE, COLUMN };
JsHeapTraceFunctionInfoTable(const TraceDataCache * dataCache)21 JsHeapTraceFunctionInfoTable::JsHeapTraceFunctionInfoTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("file_id", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("function_index", "INTEGER"));
25 tableColumn_.push_back(TableBase::ColumnInfo("function_id", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("name", "INTEGER"));
27 tableColumn_.push_back(TableBase::ColumnInfo("script_name", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("script_id", "INTEGER"));
29 tableColumn_.push_back(TableBase::ColumnInfo("line", "INTEGER"));
30 tableColumn_.push_back(TableBase::ColumnInfo("column", "INTEGER"));
31 tablePriKey_.push_back("file_id");
32 }
33
~JsHeapTraceFunctionInfoTable()34 JsHeapTraceFunctionInfoTable::~JsHeapTraceFunctionInfoTable() {}
35
CreateCursor()36 std::unique_ptr<TableBase::Cursor> JsHeapTraceFunctionInfoTable::CreateCursor()
37 {
38 return std::make_unique<Cursor>(dataCache_, this);
39 }
40
Cursor(const TraceDataCache * dataCache,TableBase * table)41 JsHeapTraceFunctionInfoTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
42 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsHeapTraceFuncInfoData().Size())),
43 jsHeapTraceFuncInfo_(dataCache->GetConstJsHeapTraceFuncInfoData())
44 {
45 }
46
~Cursor()47 JsHeapTraceFunctionInfoTable::Cursor::~Cursor() {}
48
Column(int32_t col) const49 int32_t JsHeapTraceFunctionInfoTable::Cursor::Column(int32_t col) const
50 {
51 switch (static_cast<Index>(col)) {
52 case Index::FILE_ID:
53 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceFuncInfo_.FileIds()[CurrentRow()]));
54 break;
55 case Index::FUNCTION_INDEX:
56 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceFuncInfo_.FunctionIndexs()[CurrentRow()]));
57 break;
58 case Index::FUNCTION_ID:
59 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceFuncInfo_.FunctionIds()[CurrentRow()]));
60 break;
61 case Index::NAME:
62 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceFuncInfo_.Names()[CurrentRow()]));
63 break;
64 case Index::SCRIPT_NAME:
65 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceFuncInfo_.ScriptNames()[CurrentRow()]));
66 break;
67 case Index::SCRIPT_ID:
68 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceFuncInfo_.ScriptIds()[CurrentRow()]));
69 break;
70 case Index::LINE:
71 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceFuncInfo_.Lines()[CurrentRow()]));
72 break;
73 case Index::COLUMN:
74 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapTraceFuncInfo_.Columns()[CurrentRow()]));
75 break;
76 default:
77 TS_LOGF("Unregistered column : %d", col);
78 break;
79 }
80 return SQLITE_OK;
81 }
82 } // namespace TraceStreamer
83 } // namespace SysTuning
84