• 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 "measure_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { TYPE = 0, TS, VALUE, FILTER_ID };
22 }
MeasureTable(const TraceDataCache * dataCache)23 MeasureTable::MeasureTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25     tableColumn_.push_back(TableBase::ColumnInfo("type", "STRING"));
26     tableColumn_.push_back(TableBase::ColumnInfo("ts", "UNSIGNED BIG INT"));
27     tableColumn_.push_back(TableBase::ColumnInfo("value", "UNSIGNED BIG INT"));
28     tableColumn_.push_back(TableBase::ColumnInfo("filter_id", "UNSIGNED INT"));
29     tablePriKey_.push_back("ts");
30     tablePriKey_.push_back("filter_id");
31 }
32 
~MeasureTable()33 MeasureTable::~MeasureTable() {}
34 
CreateCursor()35 void MeasureTable::CreateCursor()
36 {
37     cursor_ = std::make_unique<Cursor>(dataCache_);
38 }
39 
Cursor(const TraceDataCache * dataCache)40 MeasureTable::Cursor::Cursor(const TraceDataCache* dataCache)
41     : TableBase::Cursor(dataCache, 0, static_cast<uint32_t>(dataCache->GetConstMeasureData().Size())),
42       measureObj(dataCache->GetConstMeasureData())
43 {
44 }
45 
~Cursor()46 MeasureTable::Cursor::~Cursor() {}
47 
Column(int column) const48 int MeasureTable::Cursor::Column(int column) const
49 {
50     switch (column) {
51         case TYPE:
52             sqlite3_result_text(context_, "measure", STR_DEFAULT_LEN, nullptr);
53             break;
54         case TS:
55             sqlite3_result_int64(context_, static_cast<int64_t>(measureObj.TimeStamData()[CurrentRow()]));
56             break;
57         case VALUE:
58             sqlite3_result_int64(context_, static_cast<int64_t>(measureObj.ValuesData()[CurrentRow()]));
59             break;
60         case FILTER_ID:
61             sqlite3_result_int64(context_, static_cast<int32_t>(measureObj.FilterIdData()[CurrentRow()]));
62             break;
63         default:
64             TS_LOGF("Unregistered column : %d", column);
65             break;
66     }
67     return SQLITE_OK;
68 }
69 } // namespace TraceStreamer
70 } // namespace SysTuning
71