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_string_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { FILE_ID = 0, FILE_INDEX, STRING };
JsHeapStringTable(const TraceDataCache * dataCache)21 JsHeapStringTable::JsHeapStringTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("file_id", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("file_index", "INTEGER"));
25 tableColumn_.push_back(TableBase::ColumnInfo("string", "TEXT"));
26 tablePriKey_.push_back("file_id");
27 }
28
~JsHeapStringTable()29 JsHeapStringTable::~JsHeapStringTable() {}
30
CreateCursor()31 std::unique_ptr<TableBase::Cursor> JsHeapStringTable::CreateCursor()
32 {
33 return std::make_unique<Cursor>(dataCache_, this);
34 }
35
Cursor(const TraceDataCache * dataCache,TableBase * table)36 JsHeapStringTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
37 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsHeapStringData().Size())),
38 jsHeapString_(dataCache->GetConstJsHeapStringData())
39 {
40 }
41
~Cursor()42 JsHeapStringTable::Cursor::~Cursor() {}
43
Column(int32_t col) const44 int32_t JsHeapStringTable::Cursor::Column(int32_t col) const
45 {
46 switch (static_cast<Index>(col)) {
47 case Index::FILE_ID:
48 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapString_.FileIds()[CurrentRow()]));
49 break;
50 case Index::FILE_INDEX:
51 sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapString_.FileIndexs()[CurrentRow()]));
52 break;
53 case Index::STRING:
54 sqlite3_result_text(context_, jsHeapString_.Strings()[CurrentRow()].c_str(), STR_DEFAULT_LEN, nullptr);
55 break;
56 default:
57 TS_LOGF("Unregistered column : %d", col);
58 break;
59 }
60 return SQLITE_OK;
61 }
62
63 } // namespace TraceStreamer
64 } // namespace SysTuning
65