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_filter_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { ID = 0, TYPE, NAME, INTERNAL_TID };
22 }
MeasureFilterTable(const TraceDataCache * dataCache)23 MeasureFilterTable::MeasureFilterTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("type", "TEXT"));
27 tableColumn_.push_back(TableBase::ColumnInfo("name", "TEXT"));
28 tableColumn_.push_back(TableBase::ColumnInfo("itid", "INTEGER"));
29 tablePriKey_.push_back("id");
30 }
31
~MeasureFilterTable()32 MeasureFilterTable::~MeasureFilterTable() {}
33
CreateCursor()34 std::unique_ptr<TableBase::Cursor> MeasureFilterTable::CreateCursor()
35 {
36 return std::make_unique<Cursor>(dataCache_, this);
37 }
38
Cursor(const TraceDataCache * dataCache,TableBase * table)39 MeasureFilterTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
40 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstThreadMeasureFilterData().Size()))
41 {
42 }
43
~Cursor()44 MeasureFilterTable::Cursor::~Cursor() {}
45
Column(int column) const46 int MeasureFilterTable::Cursor::Column(int column) const
47 {
48 switch (column) {
49 case ID:
50 sqlite3_result_int64(
51 context_,
52 static_cast<sqlite3_int64>(dataCache_->GetConstThreadMeasureFilterData().FilterIdData()[CurrentRow()]));
53 break;
54 case TYPE:
55 sqlite3_result_text(context_, "thread_measure_filter", STR_DEFAULT_LEN, nullptr);
56 break;
57 case NAME: {
58 const std::string& str = dataCache_->GetDataFromDict(
59 dataCache_->GetConstThreadMeasureFilterData().NameIndexData()[CurrentRow()]);
60 sqlite3_result_text(context_, str.c_str(), STR_DEFAULT_LEN, nullptr);
61 break;
62 }
63 case INTERNAL_TID:
64 sqlite3_result_int64(
65 context_,
66 static_cast<int32_t>(dataCache_->GetConstThreadMeasureFilterData().InternalTidData()[CurrentRow()]));
67 break;
68 default:
69 TS_LOGF("Unregistered column : %d", column);
70 break;
71 }
72 return SQLITE_OK;
73 }
74 } // namespace TraceStreamer
75 } // namespace SysTuning
76