• 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 "stat_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { EVENT_NAME = 0, STAT_EVENT_TYPE = 1, COUNT = 2, SEVERITY = 3, SOURCE = 4 };
StatTable(const TraceDataCache * dataCache)21 StatTable::StatTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23     tableColumn_.push_back(TableBase::ColumnInfo("event_name", "TEXT"));
24     tableColumn_.push_back(TableBase::ColumnInfo("stat_type", "TEXT"));
25     tableColumn_.push_back(TableBase::ColumnInfo("count", "INTEGER"));
26     tableColumn_.push_back(TableBase::ColumnInfo("serverity", "TEXT"));
27     tableColumn_.push_back(TableBase::ColumnInfo("source", "TEXT"));
28     tablePriKey_.push_back("event_name");
29     tablePriKey_.push_back("stat_type");
30 }
31 
~StatTable()32 StatTable::~StatTable() {}
33 
CreateCursor()34 std::unique_ptr<TableBase::Cursor> StatTable::CreateCursor()
35 {
36     return std::make_unique<Cursor>(dataCache_, this);
37 }
38 
Cursor(const TraceDataCache * dataCache,TableBase * table)39 StatTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
40     : TableBase::Cursor(dataCache, table, STAT_EVENT_MAX * TRACE_EVENT_MAX)
41 {
42 }
43 
~Cursor()44 StatTable::Cursor::~Cursor() {}
45 
Column(int32_t column) const46 int32_t StatTable::Cursor::Column(int32_t column) const
47 {
48     SupportedTraceEventType eventType = static_cast<SupportedTraceEventType>(CurrentRow() / STAT_EVENT_MAX);
49     StatType statType = static_cast<StatType>(CurrentRow() % STAT_EVENT_MAX);
50     switch (static_cast<Index>(column)) {
51         case Index::EVENT_NAME:
52             sqlite3_result_text(context_, dataCache_->GetConstStatAndInfo().GetEvent(eventType).c_str(),
53                                 STR_DEFAULT_LEN, nullptr);
54             break;
55         case Index::STAT_EVENT_TYPE:
56             sqlite3_result_text(context_, dataCache_->GetConstStatAndInfo().GetStat(statType).c_str(), STR_DEFAULT_LEN,
57                                 nullptr);
58             break;
59         case Index::COUNT:
60             sqlite3_result_int64(context_,
61                                  static_cast<int64_t>(dataCache_->GetConstStatAndInfo().GetValue(eventType, statType)));
62             break;
63         case Index::SEVERITY:
64             sqlite3_result_text(context_,
65                                 dataCache_->GetConstStatAndInfo().GetSeverityDesc(eventType, statType).c_str(),
66                                 STR_DEFAULT_LEN, nullptr);
67             break;
68         case Index::SOURCE:
69             sqlite3_result_text(context_, "trace", STR_DEFAULT_LEN, nullptr);
70             break;
71         default:
72             TS_LOGF("Unregistered column : %d", column);
73             break;
74     }
75     return SQLITE_OK;
76 }
77 } // namespace TraceStreamer
78 } // namespace SysTuning
79