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