• 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_nodes_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21     FILE_ID = 0,
22     NODE_INDEX,
23     TYPE,
24     NAME,
25     NODE_ID,
26     SELF_SIZE,
27     EDGE_COUNT,
28     TRACE_NODE_ID,
29     DETACHEDNESS
30 };
JsHeapNodesTable(const TraceDataCache * dataCache)31 JsHeapNodesTable::JsHeapNodesTable(const TraceDataCache *dataCache) : TableBase(dataCache)
32 {
33     tableColumn_.push_back(TableBase::ColumnInfo("file_id", "INTEGER"));
34     tableColumn_.push_back(TableBase::ColumnInfo("node_index", "INTEGER"));
35     tableColumn_.push_back(TableBase::ColumnInfo("type", "INTEGER"));
36     tableColumn_.push_back(TableBase::ColumnInfo("name", "INTEGER"));
37     tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
38     tableColumn_.push_back(TableBase::ColumnInfo("self_size", "INTEGER"));
39     tableColumn_.push_back(TableBase::ColumnInfo("edge_count", "INTEGER"));
40     tableColumn_.push_back(TableBase::ColumnInfo("trace_node_id", "INTEGER"));
41     tableColumn_.push_back(TableBase::ColumnInfo("detachedness", "INTEGER"));
42     tablePriKey_.push_back("file_id");
43 }
44 
~JsHeapNodesTable()45 JsHeapNodesTable::~JsHeapNodesTable() {}
46 
CreateCursor()47 std::unique_ptr<TableBase::Cursor> JsHeapNodesTable::CreateCursor()
48 {
49     return std::make_unique<Cursor>(dataCache_, this);
50 }
51 
Cursor(const TraceDataCache * dataCache,TableBase * table)52 JsHeapNodesTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
53     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsHeapNodesData().Size())),
54       jsHeapNodes_(dataCache->GetConstJsHeapNodesData())
55 {
56 }
57 
~Cursor()58 JsHeapNodesTable::Cursor::~Cursor() {}
59 
Column(int32_t col) const60 int32_t JsHeapNodesTable::Cursor::Column(int32_t col) const
61 {
62     switch (static_cast<Index>(col)) {
63         case Index::FILE_ID:
64             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapNodes_.FileIds()[CurrentRow()]));
65             break;
66         case Index::NODE_INDEX:
67             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapNodes_.NodeIndexs()[CurrentRow()]));
68             break;
69         case Index::TYPE:
70             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapNodes_.Types()[CurrentRow()]));
71             break;
72         case Index::NAME:
73             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapNodes_.Names()[CurrentRow()]));
74             break;
75         case Index::NODE_ID:
76             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapNodes_.NodeIds()[CurrentRow()]));
77             break;
78         case Index::SELF_SIZE:
79             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapNodes_.SelfSizes()[CurrentRow()]));
80             break;
81         case Index::EDGE_COUNT:
82             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapNodes_.EdgeCounts()[CurrentRow()]));
83             break;
84         case Index::TRACE_NODE_ID:
85             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapNodes_.TraceNodeIds()[CurrentRow()]));
86             break;
87         case Index::DETACHEDNESS:
88             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapNodes_.DetachedNess()[CurrentRow()]));
89             break;
90         default:
91             TS_LOGF("Unregistered column : %d", col);
92             break;
93     }
94     return SQLITE_OK;
95 }
96 } // namespace TraceStreamer
97 } // namespace SysTuning
98