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", "STRING"));
26 tableColumn_.push_back(TableBase::ColumnInfo("end_ts", "INT"));
27 tablePriKey_.push_back("start_ts");
28 }
29
~RangeTable()30 RangeTable::~RangeTable() {}
31
CreateCursor()32 void RangeTable::CreateCursor()
33 {
34 cursor_ = std::make_unique<Cursor>(dataCache_);
35 }
36
Cursor(const TraceDataCache * dataCache)37 RangeTable::Cursor::Cursor(const TraceDataCache* dataCache) : TableBase::Cursor(dataCache, 0, 1) {}
38
~Cursor()39 RangeTable::Cursor::~Cursor() {}
40
Column(int column) const41 int RangeTable::Cursor::Column(int column) const
42 {
43 switch (column) {
44 case START_TS:
45 sqlite3_result_int64(context_, static_cast<int64_t>(dataCache_->TraceStartTime()));
46 break;
47 case 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