• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 "perf_report_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21     ID = 0,
22     REPORT_TYPE,
23     REPORT_VALUE,
24 };
PerfReportTable(const TraceDataCache * dataCache)25 PerfReportTable::PerfReportTable(const TraceDataCache *dataCache) : TableBase(dataCache)
26 {
27     tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
28     tableColumn_.push_back(TableBase::ColumnInfo("report_type", "TEXT"));
29     tableColumn_.push_back(TableBase::ColumnInfo("report_value", "TEXT"));
30     tablePriKey_.push_back("id");
31 }
32 
~PerfReportTable()33 PerfReportTable::~PerfReportTable() {}
34 
CreateCursor()35 std::unique_ptr<TableBase::Cursor> PerfReportTable::CreateCursor()
36 {
37     return std::make_unique<Cursor>(dataCache_, this);
38 }
39 
Cursor(const TraceDataCache * dataCache,TableBase * table)40 PerfReportTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
41     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstPerfReportData().Size())),
42       perfReportObj_(dataCache->GetConstPerfReportData())
43 {
44 }
45 
~Cursor()46 PerfReportTable::Cursor::~Cursor() {}
47 
Column(int32_t column) const48 int32_t PerfReportTable::Cursor::Column(int32_t column) const
49 {
50     switch (static_cast<Index>(column)) {
51         case Index::ID:
52             sqlite3_result_int64(context_, static_cast<int64_t>(perfReportObj_.IdsData()[CurrentRow()]));
53             break;
54         case Index::REPORT_TYPE:
55             if (perfReportObj_.Types()[CurrentRow()] != INVALID_UINT64) {
56                 auto typeIndex = static_cast<size_t>(perfReportObj_.Types()[CurrentRow()]);
57                 sqlite3_result_text(context_, dataCache_->GetDataFromDict(typeIndex).c_str(), STR_DEFAULT_LEN, nullptr);
58             }
59             break;
60         case Index::REPORT_VALUE:
61             if (perfReportObj_.Values()[CurrentRow()] != INVALID_UINT64) {
62                 auto typeValueIndex = static_cast<size_t>(perfReportObj_.Values()[CurrentRow()]);
63                 sqlite3_result_text(context_, dataCache_->GetDataFromDict(typeValueIndex).c_str(), STR_DEFAULT_LEN,
64                                     nullptr);
65             }
66             break;
67         default:
68             TS_LOGF("Unregistered column : %d", column);
69             break;
70     }
71     return SQLITE_OK;
72 }
73 } // namespace TraceStreamer
74 } // namespace SysTuning
75