• 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 #include "js_cpu_profiler_node_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
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() {}
Column(int32_t col) const59 int32_t JsCpuProfilerNodeTable::Cursor::Column(int32_t col) const
60 {
61     switch (static_cast<Index>(col)) {
62         case Index::FUNCTION_ID:
63             sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.FunctionIds()[CurrentRow()]));
64             break;
65         case Index::FUNCTION_NAME:
66             sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.FunctionNames()[CurrentRow()]));
67             break;
68         case Index::SCRIPT_ID:
69             sqlite3_result_text(context_, jsCpuProfilerNodes_.ScriptIds()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
70                                 nullptr);
71             break;
72         case Index::URL:
73             sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.Urls()[CurrentRow()]));
74             break;
75         case Index::LINE_NUMBER:
76             sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.LineNumbers()[CurrentRow()]));
77             break;
78         case Index::COLUMN_NUMBER:
79             sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.ColumnNumbers()[CurrentRow()]));
80             break;
81         case Index::HIT_COUNT:
82             sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.HitCounts()[CurrentRow()]));
83             break;
84         case Index::CHILDREN:
85             sqlite3_result_text(context_, jsCpuProfilerNodes_.Children()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
86                                 nullptr);
87             break;
88         case Index::PARENT_ID:
89             sqlite3_result_int64(context_, static_cast<int64_t>(jsCpuProfilerNodes_.Parents()[CurrentRow()]));
90             break;
91         default:
92             TS_LOGF("Unregistered column : %d", col);
93             break;
94     }
95     return SQLITE_OK;
96 }
97 } // namespace TraceStreamer
98 } // namespace SysTuning
99