• 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 "raw_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { ID = 0, TYPE, TS, NAME, CPU, INTERNAL_TID };
22 }
RawTable(const TraceDataCache * dataCache)23 RawTable::RawTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25     tableColumn_.push_back(TableBase::ColumnInfo("id", "UNSIGNED INT"));
26     tableColumn_.push_back(TableBase::ColumnInfo("type", "STRING"));
27     tableColumn_.push_back(TableBase::ColumnInfo("ts", "UNSIGNED BIG INT"));
28     tableColumn_.push_back(TableBase::ColumnInfo("name", "STRING"));
29     tableColumn_.push_back(TableBase::ColumnInfo("cpu", "UNSIGNED INT"));
30     tableColumn_.push_back(TableBase::ColumnInfo("itid", "UNSIGNED INT"));
31     tablePriKey_.push_back("id");
32 }
33 
~RawTable()34 RawTable::~RawTable() {}
35 
CreateCursor()36 void RawTable::CreateCursor()
37 {
38     cursor_ = std::make_unique<Cursor>(dataCache_);
39 }
40 
Cursor(const TraceDataCache * dataCache)41 RawTable::Cursor::Cursor(const TraceDataCache* dataCache)
42     : TableBase::Cursor(dataCache, 0, static_cast<uint32_t>(dataCache->GetConstRawTableData().Size())),
43       rawObj_(dataCache->GetConstRawTableData())
44 {
45 }
46 
~Cursor()47 RawTable::Cursor::~Cursor() {}
48 
Column(int column) const49 int RawTable::Cursor::Column(int column) const
50 {
51     switch (column) {
52         case ID:
53             sqlite3_result_int64(context_, static_cast<int32_t>(CurrentRow()));
54             break;
55         case TYPE:
56             sqlite3_result_text(context_, "raw", STR_DEFAULT_LEN, nullptr);
57             break;
58         case TS:
59             sqlite3_result_int64(context_, static_cast<int64_t>(rawObj_.TimeStamData()[CurrentRow()]));
60             break;
61         case NAME: {
62             if (rawObj_.NameData()[CurrentRow()] == CPU_IDLE) {
63                 sqlite3_result_text(context_, "cpu_idle", STR_DEFAULT_LEN, nullptr);
64             } else if (rawObj_.NameData()[CurrentRow()] == SCHED_WAKEUP) {
65                 sqlite3_result_text(context_, "sched_wakeup", STR_DEFAULT_LEN, nullptr);
66             } else {
67                 sqlite3_result_text(context_, "sched_waking", STR_DEFAULT_LEN, nullptr);
68             }
69             break;
70         }
71         case CPU:
72             sqlite3_result_int64(context_, static_cast<int32_t>(rawObj_.CpuData()[CurrentRow()]));
73             break;
74         case INTERNAL_TID:
75             sqlite3_result_int64(context_, static_cast<int32_t>(rawObj_.InternalTidData()[CurrentRow()]));
76             break;
77         default:
78             TS_LOGF("Unregistered column : %d", column);
79             break;
80     }
81     return SQLITE_OK;
82 }
83 } // namespace TraceStreamer
84 } // namespace SysTuning
85