• 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_heap_edges_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { FILE_ID = 0, EDGE_INDEX, TYPE, NAME_OR_INDEX, TO_NODE, FROM_NODE_ID, TO_NODE_ID };
JsHeapEdgesTable(const TraceDataCache * dataCache)21 JsHeapEdgesTable::JsHeapEdgesTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23     tableColumn_.push_back(TableBase::ColumnInfo("file_id", "INTEGER"));
24     tableColumn_.push_back(TableBase::ColumnInfo("edge_index", "INTEGER"));
25     tableColumn_.push_back(TableBase::ColumnInfo("type", "INTEGER"));
26     tableColumn_.push_back(TableBase::ColumnInfo("name_or_index", "INTEGER"));
27     tableColumn_.push_back(TableBase::ColumnInfo("to_node", "INTEGER"));
28     tableColumn_.push_back(TableBase::ColumnInfo("from_node_id", "INTEGER"));
29     tableColumn_.push_back(TableBase::ColumnInfo("to_node_id", "INTEGER"));
30     tablePriKey_.push_back("file_id");
31 }
32 
~JsHeapEdgesTable()33 JsHeapEdgesTable::~JsHeapEdgesTable() {}
34 
CreateCursor()35 std::unique_ptr<TableBase::Cursor> JsHeapEdgesTable::CreateCursor()
36 {
37     return std::make_unique<Cursor>(dataCache_, this);
38 }
39 
Cursor(const TraceDataCache * dataCache,TableBase * table)40 JsHeapEdgesTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
41     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsHeapEdgesData().Size())),
42       jsHeapEdges_(dataCache->GetConstJsHeapEdgesData())
43 {
44 }
45 
~Cursor()46 JsHeapEdgesTable::Cursor::~Cursor() {}
47 
Column(int32_t col) const48 int32_t JsHeapEdgesTable::Cursor::Column(int32_t col) const
49 {
50     switch (static_cast<Index>(col)) {
51         case Index::FILE_ID:
52             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapEdges_.FileIds()[CurrentRow()]));
53             break;
54         case Index::EDGE_INDEX:
55             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapEdges_.EdgeIndexs()[CurrentRow()]));
56             break;
57         case Index::TYPE:
58             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapEdges_.Types()[CurrentRow()]));
59             break;
60         case Index::NAME_OR_INDEX:
61             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapEdges_.NameOrIndexs()[CurrentRow()]));
62             break;
63         case Index::TO_NODE:
64             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapEdges_.ToNodes()[CurrentRow()]));
65             break;
66         case Index::FROM_NODE_ID:
67             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapEdges_.FromNodeIds()[CurrentRow()]));
68             break;
69         case Index::TO_NODE_ID:
70             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapEdges_.ToNodeIds()[CurrentRow()]));
71             break;
72         default:
73             TS_LOGF("Unregistered column : %d", col);
74             break;
75     }
76     return SQLITE_OK;
77 }
78 } // namespace TraceStreamer
79 } // namespace SysTuning
80