• 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 "symbols_table.h"
17 #include "trace_data_cache.h"
18 
19 namespace SysTuning {
20 namespace TraceStreamer {
21 namespace {
22 enum Index { ID = 0, STR, ADDR };
23 }
SymbolsTable(const TraceDataCache * dataCache)24 SymbolsTable::SymbolsTable(const TraceDataCache* dataCache) : TableBase(dataCache)
25 {
26     tableColumn_.push_back(TableBase::ColumnInfo("id", "UNSIGNED BIG INT"));
27     tableColumn_.push_back(TableBase::ColumnInfo("funcname", "STRING"));
28     tableColumn_.push_back(TableBase::ColumnInfo("addr", "UNSIGNED BIG INT"));
29     tablePriKey_.push_back("id");
30 }
31 
~SymbolsTable()32 SymbolsTable::~SymbolsTable() {}
33 
CreateCursor()34 void SymbolsTable::CreateCursor()
35 {
36     cursor_ = std::make_unique<Cursor>(dataCache_);
37 }
38 
Cursor(const TraceDataCache * dataCache)39 SymbolsTable::Cursor::Cursor(const TraceDataCache* dataCache)
40     : TableBase::Cursor(dataCache, 0, static_cast<uint32_t>(dataCache->GetConstSymbolsData().Size()))
41 {
42 }
43 
~Cursor()44 SymbolsTable::Cursor::~Cursor() {}
45 
Column(int col) const46 int SymbolsTable::Cursor::Column(int col) const
47 {
48     DataIndex index = static_cast<DataIndex>(CurrentRow());
49     switch (col) {
50         case ID:
51             sqlite3_result_int64(context_, static_cast<sqlite3_int64>(CurrentRow()));
52             break;
53         case STR:
54             sqlite3_result_text(context_,
55                 dataCache_->GetDataFromDict(dataCache_->GetConstSymbolsData().GetConstFuncNames()[index]).c_str(),
56                 STR_DEFAULT_LEN, nullptr);
57             break;
58         case ADDR:
59             sqlite3_result_int64(context_,
60                 static_cast<sqlite3_int64>(dataCache_->GetConstSymbolsData().GetConstAddrs()[index]));
61             break;
62         default:
63             TS_LOGF("Unknown column %d", col);
64             break;
65     }
66     return SQLITE_OK;
67 }
68 } // namespace TraceStreamer
69 } // namespace SysTuning
70