• 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_files_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { ID = 0, FILE_NAME, START_TIME, END_TIME, SELF_SIZE_COUNT };
JsHeapFilesTable(const TraceDataCache * dataCache)21 JsHeapFilesTable::JsHeapFilesTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23     tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
24     tableColumn_.push_back(TableBase::ColumnInfo("file_name", "TEXT"));
25     tableColumn_.push_back(TableBase::ColumnInfo("start_time", "INTEGER"));
26     tableColumn_.push_back(TableBase::ColumnInfo("end_time", "INTEGER"));
27     tableColumn_.push_back(TableBase::ColumnInfo("self_size", "INTEGER"));
28     tablePriKey_.push_back("id");
29 }
30 
~JsHeapFilesTable()31 JsHeapFilesTable::~JsHeapFilesTable() {}
32 
CreateCursor()33 std::unique_ptr<TableBase::Cursor> JsHeapFilesTable::CreateCursor()
34 {
35     return std::make_unique<Cursor>(dataCache_, this);
36 }
37 
Cursor(const TraceDataCache * dataCache,TableBase * table)38 JsHeapFilesTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
39     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsHeapFilesData().Size())),
40       jsHeapFiles_(dataCache->GetConstJsHeapFilesData())
41 {
42 }
43 
~Cursor()44 JsHeapFilesTable::Cursor::~Cursor() {}
45 
Column(int32_t col) const46 int32_t JsHeapFilesTable::Cursor::Column(int32_t col) const
47 {
48     switch (static_cast<Index>(col)) {
49         case Index::ID:
50             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapFiles_.IDs()[CurrentRow()]));
51             break;
52         case Index::FILE_NAME:
53             sqlite3_result_text(context_, jsHeapFiles_.FilePaths()[CurrentRow()].c_str(), STR_DEFAULT_LEN, nullptr);
54             break;
55         case Index::START_TIME:
56             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapFiles_.StartTimes()[CurrentRow()]));
57             break;
58         case Index::END_TIME:
59             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapFiles_.EndTimes()[CurrentRow()]));
60             break;
61         case Index::SELF_SIZE_COUNT:
62             sqlite3_result_int64(context_, static_cast<int64_t>(jsHeapFiles_.SelfSizeCount()[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