• 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 "range_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { START_TS = 0, END_TS };
RangeTable(const TraceDataCache * dataCache)21 RangeTable::RangeTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23     tableColumn_.push_back(TableBase::ColumnInfo("start_ts", "INTEGER"));
24     tableColumn_.push_back(TableBase::ColumnInfo("end_ts", "INTEGER"));
25     tablePriKey_.push_back("start_ts");
26 }
27 
~RangeTable()28 RangeTable::~RangeTable() {}
29 
CreateCursor()30 std::unique_ptr<TableBase::Cursor> RangeTable::CreateCursor()
31 {
32     return std::make_unique<Cursor>(dataCache_, this);
33 }
34 
Cursor(const TraceDataCache * dataCache,TableBase * table)35 RangeTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table) : TableBase::Cursor(dataCache, table, 1)
36 {
37 }
38 
~Cursor()39 RangeTable::Cursor::~Cursor() {}
40 
Column(int32_t column) const41 int32_t RangeTable::Cursor::Column(int32_t column) const
42 {
43     switch (static_cast<Index>(column)) {
44         case Index::START_TS:
45             sqlite3_result_int64(context_, static_cast<int64_t>(dataCache_->TraceStartTime()));
46             break;
47         case Index::END_TS:
48             sqlite3_result_int64(context_, static_cast<int64_t>(dataCache_->TraceEndTime()));
49             break;
50         default:
51             TS_LOGF("Unregistered column : %d", column);
52             break;
53     }
54     return SQLITE_OK;
55 }
56 } // namespace TraceStreamer
57 } // namespace SysTuning
58