• 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 "instants_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { TS = 0, NAME, REF, REF_TYPE };
22 }
InstantsTable(const TraceDataCache * dataCache)23 InstantsTable::InstantsTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25     tableColumn_.push_back(TableBase::ColumnInfo("ts", "UNSIGNED BIG INT"));
26     tableColumn_.push_back(TableBase::ColumnInfo("name", "STRING"));
27     tableColumn_.push_back(TableBase::ColumnInfo("ref", "UNSIGNED INT"));
28     tableColumn_.push_back(TableBase::ColumnInfo("ref_type", "STRING"));
29     tablePriKey_.push_back("ts");
30     tablePriKey_.push_back("ref");
31 }
32 
~InstantsTable()33 InstantsTable::~InstantsTable() {}
34 
CreateCursor()35 void InstantsTable::CreateCursor()
36 {
37     cursor_ = std::make_unique<Cursor>(dataCache_);
38 }
39 
Cursor(const TraceDataCache * dataCache)40 InstantsTable::Cursor::Cursor(const TraceDataCache* dataCache)
41     : TableBase::Cursor(dataCache, 0, static_cast<uint32_t>(dataCache->GetConstInstantsData().Size())),
42       InstantsObj_(dataCache->GetConstInstantsData())
43 {
44 }
45 
~Cursor()46 InstantsTable::Cursor::~Cursor() {}
47 
Column(int column) const48 int InstantsTable::Cursor::Column(int column) const
49 {
50     size_t stringIdentity = static_cast<size_t>(InstantsObj_.NameIndexsData()[CurrentRow()]);
51     switch (column) {
52         case TS:
53             sqlite3_result_int64(context_, static_cast<int64_t>(InstantsObj_.TimeStamData()[CurrentRow()]));
54             break;
55         case NAME: {
56             sqlite3_result_text(context_, dataCache_->GetDataFromDict(stringIdentity).c_str(),
57                 STR_DEFAULT_LEN, nullptr);
58             break;
59         }
60         case REF:
61             sqlite3_result_int64(context_, static_cast<int32_t>(InstantsObj_.InternalTidsData()[CurrentRow()]));
62             break;
63         case REF_TYPE: {
64             sqlite3_result_text(context_, "itid", STR_DEFAULT_LEN, nullptr);
65             break;
66         }
67         default:
68             TS_LOGF("Unregistered column : %d", column);
69             break;
70     }
71     return SQLITE_OK;
72 }
73 } // namespace TraceStreamer
74 } // namespace SysTuning
75