• 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_location_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { FILE_ID = 0, OBJECT_INDEX, SCRIPT_ID, LINE, COLUMN };
JsHeapLocationTable(const TraceDataCache * dataCache)21 JsHeapLocationTable::JsHeapLocationTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23     tableColumn_.push_back(TableBase::ColumnInfo("file_id", "INTEGER"));
24     tableColumn_.push_back(TableBase::ColumnInfo("object_index", "INTEGER"));
25     tableColumn_.push_back(TableBase::ColumnInfo("script_id", "INTEGER"));
26     tableColumn_.push_back(TableBase::ColumnInfo("line", "INTEGER"));
27     tableColumn_.push_back(TableBase::ColumnInfo("column", "INTEGER"));
28     tablePriKey_.push_back("file_id");
29 }
30 
~JsHeapLocationTable()31 JsHeapLocationTable::~JsHeapLocationTable() {}
32 
CreateCursor()33 std::unique_ptr<TableBase::Cursor> JsHeapLocationTable::CreateCursor()
34 {
35     return std::make_unique<Cursor>(dataCache_, this);
36 }
37 
Cursor(const TraceDataCache * dataCache,TableBase * table)38 JsHeapLocationTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
39     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsHeapLocationData().Size())),
40       jsHeapLocation_(dataCache->GetConstJsHeapLocationData())
41 {
42 }
43 
~Cursor()44 JsHeapLocationTable::Cursor::~Cursor() {}
45 
Column(int32_t col) const46 int32_t JsHeapLocationTable::Cursor::Column(int32_t col) const
47 {
48     switch (static_cast<Index>(col)) {
49         case Index::FILE_ID:
50             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapLocation_.FileIds()[CurrentRow()]));
51             break;
52         case Index::OBJECT_INDEX:
53             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapLocation_.ObjectIndexs()[CurrentRow()]));
54             break;
55         case Index::SCRIPT_ID:
56             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapLocation_.ScriptIds()[CurrentRow()]));
57             break;
58         case Index::LINE:
59             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapLocation_.Lines()[CurrentRow()]));
60             break;
61         case Index::COLUMN:
62             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapLocation_.Columns()[CurrentRow()]));
63             break;
64         default:
65             TS_LOGF("Unregistered column : %d", col);
66             break;
67     }
68     return SQLITE_OK;
69 }
70 } // namespace TraceStreamer
71 } // namespace SysTuning
72