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 "js_cpu_profiler_node_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum Index {
21 FUNCTION_ID = 0,
22 FUNCTION_NAME,
23 SCRIPT_ID,
24 URL,
25 LINE_NUMBER,
26 COLUMN_NUMBER,
27 HIT_COUNT,
28 CHILDREN,
29 PARENT_ID
30 };
JsCpuProfilerNodeTable(const TraceDataCache * dataCache)31 JsCpuProfilerNodeTable::JsCpuProfilerNodeTable(const TraceDataCache* dataCache) : TableBase(dataCache)
32 {
33 tableColumn_.push_back(TableBase::ColumnInfo("function_id", "INTEGER"));
34 tableColumn_.push_back(TableBase::ColumnInfo("function_index", "INTEGER"));
35 tableColumn_.push_back(TableBase::ColumnInfo("script_id", "TEXT"));
36 tableColumn_.push_back(TableBase::ColumnInfo("url_index", "INTEGER"));
37 tableColumn_.push_back(TableBase::ColumnInfo("line_number", "INTEGER"));
38 tableColumn_.push_back(TableBase::ColumnInfo("column_number", "INTEGER"));
39 tableColumn_.push_back(TableBase::ColumnInfo("hit_count", "INTEGER"));
40 tableColumn_.push_back(TableBase::ColumnInfo("children", "INTEGER"));
41 tableColumn_.push_back(TableBase::ColumnInfo("parent_id", "INTEGER"));
42 tablePriKey_.push_back("function_id");
43 }
44
~JsCpuProfilerNodeTable()45 JsCpuProfilerNodeTable::~JsCpuProfilerNodeTable() {}
46
CreateCursor()47 std::unique_ptr<TableBase::Cursor> JsCpuProfilerNodeTable::CreateCursor()
48 {
49 return std::make_unique<Cursor>(dataCache_, this);
50 }
51
Cursor(const TraceDataCache * dataCache,TableBase * table)52 JsCpuProfilerNodeTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
53 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsCpuProfilerNodeData().Size())),
54 jsCpuProfilerNodes_(dataCache->GetConstJsCpuProfilerNodeData())
55 {
56 }
57
~Cursor()58 JsCpuProfilerNodeTable::Cursor::~Cursor() {}
59
Column(int32_t col) const60 int32_t JsCpuProfilerNodeTable::Cursor::Column(int32_t col) const
61 {
62 switch (col) {
63 case FUNCTION_ID:
64 sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.FunctionIds()[CurrentRow()]));
65 break;
66 case FUNCTION_NAME:
67 sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.FunctionNames()[CurrentRow()]));
68 break;
69 case SCRIPT_ID:
70 sqlite3_result_text(context_, jsCpuProfilerNodes_.ScriptIds()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
71 nullptr);
72 break;
73 case URL:
74 sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.Urls()[CurrentRow()]));
75 break;
76 case LINE_NUMBER:
77 sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.LineNumbers()[CurrentRow()]));
78 break;
79 case COLUMN_NUMBER:
80 sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.ColumnNumbers()[CurrentRow()]));
81 break;
82 case HIT_COUNT:
83 sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.HitCounts()[CurrentRow()]));
84 break;
85 case CHILDREN:
86 sqlite3_result_text(context_, jsCpuProfilerNodes_.Children()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
87 nullptr);
88 break;
89 case PARENT_ID:
90 sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.Parents()[CurrentRow()]));
91 break;
92 default:
93 TS_LOGF("Unregistered column : %d", col);
94 break;
95 }
96 return SQLITE_OK;
97 }
98 } // namespace TraceStreamer
99 } // namespace SysTuning
100