• 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 "stat_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum Index { 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     const StatAndInfo stat = dataCache_->GetConstStatAndInfo();
49     SupportedTraceEventType eventType = static_cast<SupportedTraceEventType>(CurrentRow() / STAT_EVENT_MAX);
50     StatType statType = static_cast<StatType>(CurrentRow() % STAT_EVENT_MAX);
51     switch (column) {
52         case EVENT_NAME:
53             sqlite3_result_text(context_, dataCache_->GetConstStatAndInfo().GetEvent(eventType).c_str(),
54                                 STR_DEFAULT_LEN, nullptr);
55             break;
56         case STAT_EVENT_TYPE:
57             sqlite3_result_text(context_, dataCache_->GetConstStatAndInfo().GetStat(statType).c_str(), STR_DEFAULT_LEN,
58                                 nullptr);
59             break;
60         case COUNT:
61             sqlite3_result_int64(context_,
62                                  static_cast<int64_t>(dataCache_->GetConstStatAndInfo().GetValue(eventType, statType)));
63             break;
64         case SEVERITY:
65             sqlite3_result_text(context_,
66                                 dataCache_->GetConstStatAndInfo().GetSeverityDesc(eventType, statType).c_str(),
67                                 STR_DEFAULT_LEN, nullptr);
68             break;
69         case SOURCE:
70             sqlite3_result_text(context_, "trace", STR_DEFAULT_LEN, nullptr);
71             break;
72         default:
73             TS_LOGF("Unregistered column : %d", column);
74             break;
75     }
76     return SQLITE_OK;
77 }
78 } // namespace TraceStreamer
79 } // namespace SysTuning
80