• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "clock_snapshot_table.h"
17 #include <cmath>
18 
19 namespace SysTuning {
20 namespace TraceStreamer {
21 namespace {
22 enum Index { ID = 0, CLOCK_ID, TS, CLOCK_NAME };
23 }
ClockSnapShotTable(const TraceDataCache * dataCache)24 ClockSnapShotTable::ClockSnapShotTable(const TraceDataCache* dataCache) : TableBase(dataCache)
25 {
26     tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
27     tableColumn_.push_back(TableBase::ColumnInfo("clock_id", "INTEGER"));
28     tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
29     tableColumn_.push_back(TableBase::ColumnInfo("clock_name", "TEXT"));
30     tablePriKey_.push_back("ts");
31     tablePriKey_.push_back("id");
32 }
33 
~ClockSnapShotTable()34 ClockSnapShotTable::~ClockSnapShotTable() {}
35 
CreateCursor()36 std::unique_ptr<TableBase::Cursor> ClockSnapShotTable::CreateCursor()
37 {
38     return std::make_unique<Cursor>(dataCache_, this);
39 }
40 
Cursor(const TraceDataCache * dataCache,TableBase * table)41 ClockSnapShotTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
42     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstClockSnapshotData().Size())),
43       snapShotData_(dataCache->GetConstClockSnapshotData())
44 {
45 }
46 
~Cursor()47 ClockSnapShotTable::Cursor::~Cursor() {}
48 
Column(int column) const49 int ClockSnapShotTable::Cursor::Column(int column) const
50 {
51     switch (column) {
52         case ID:
53             sqlite3_result_int64(context_, CurrentRow());
54             break;
55         case CLOCK_ID:
56             sqlite3_result_int64(context_, static_cast<int64_t>(snapShotData_.ClockIds()[CurrentRow()]));
57             break;
58         case TS:
59             sqlite3_result_int64(context_, static_cast<int64_t>(snapShotData_.Ts()[CurrentRow()]));
60             break;
61         case CLOCK_NAME:
62             sqlite3_result_text(context_, snapShotData_.Names()[CurrentRow()].c_str(), STR_DEFAULT_LEN, nullptr);
63             break;
64         default:
65             TS_LOGF("Unregistered column : %d", column);
66             break;
67     }
68     return SQLITE_OK;
69 }
70 } // namespace TraceStreamer
71 } // namespace SysTuning
72