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_info_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { FILE_ID = 0, KEY, TYPE, INT_VALUE, STR_VALUE };
JsHeapInfoTable(const TraceDataCache * dataCache)21 JsHeapInfoTable::JsHeapInfoTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("file_id", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("key", "TEXT"));
25 tableColumn_.push_back(TableBase::ColumnInfo("type", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("int_value", "INTEGER"));
27 tableColumn_.push_back(TableBase::ColumnInfo("str_value", "TEXT"));
28 tablePriKey_.push_back("file_id");
29 }
30
~JsHeapInfoTable()31 JsHeapInfoTable::~JsHeapInfoTable() {}
32
CreateCursor()33 std::unique_ptr<TableBase::Cursor> JsHeapInfoTable::CreateCursor()
34 {
35 return std::make_unique<Cursor>(dataCache_, this);
36 }
37
Cursor(const TraceDataCache * dataCache,TableBase * table)38 JsHeapInfoTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
39 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsHeapInfoData().Size())),
40 jsHeapInfo_(dataCache->GetConstJsHeapInfoData())
41 {
42 }
43
~Cursor()44 JsHeapInfoTable::Cursor::~Cursor() {}
45
Column(int32_t col) const46 int32_t JsHeapInfoTable::Cursor::Column(int32_t col) const
47 {
48 switch (static_cast<Index>(col)) {
49 case Index::FILE_ID:
50 sqlite3_result_int64(
51 context_,
52 static_cast<int64_t>(jsHeapInfo_.FileIds()[CurrentRow()])); // IdsData() will be optimized
53 break;
54 case Index::KEY:
55 sqlite3_result_text(context_, jsHeapInfo_.Keys()[CurrentRow()].c_str(), STR_DEFAULT_LEN, nullptr);
56 break;
57 case Index::TYPE:
58 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapInfo_.Types()[CurrentRow()]));
59 break;
60 case Index::INT_VALUE:
61 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapInfo_.IntValues()[CurrentRow()]));
62 break;
63 case Index::STR_VALUE:
64 sqlite3_result_text(context_, jsHeapInfo_.StrValues()[CurrentRow()].c_str(), STR_DEFAULT_LEN, nullptr);
65 break;
66 default:
67 TS_LOGF("Unregistered column : %d", col);
68 break;
69 }
70 return SQLITE_OK;
71 }
72
73 } // namespace TraceStreamer
74 } // namespace SysTuning
75