• 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 "log_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { SEQ = 0, TS, PID, TID, LEVEL, TAG, CONTEXT, ORIGINTS };
LogTable(const TraceDataCache * dataCache)21 LogTable::LogTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23     tableColumn_.push_back(TableBase::ColumnInfo("seq", "INTEGER"));
24     tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
25     tableColumn_.push_back(TableBase::ColumnInfo("pid", "INTEGER"));
26     tableColumn_.push_back(TableBase::ColumnInfo("tid", "INTEGER"));
27     tableColumn_.push_back(TableBase::ColumnInfo("level", "TEXT"));
28     tableColumn_.push_back(TableBase::ColumnInfo("tag", "TEXT"));
29     tableColumn_.push_back(TableBase::ColumnInfo("context", "TEXT"));
30     tableColumn_.push_back(TableBase::ColumnInfo("origints", "INTEGER"));
31     tablePriKey_.push_back("ts");
32 }
33 
~LogTable()34 LogTable::~LogTable() {}
35 
CreateCursor()36 std::unique_ptr<TableBase::Cursor> LogTable::CreateCursor()
37 {
38     return std::make_unique<Cursor>(dataCache_, this);
39 }
40 
Cursor(const TraceDataCache * dataCache,TableBase * table)41 LogTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
42     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstHilogData().Size())),
43       logInfoObj_(dataCache->GetConstHilogData())
44 {
45 }
46 
~Cursor()47 LogTable::Cursor::~Cursor() {}
48 
Column(int32_t logColumn) const49 int32_t LogTable::Cursor::Column(int32_t logColumn) const
50 {
51     switch (static_cast<Index>(logColumn)) {
52         case Index::SEQ:
53             sqlite3_result_int64(context_, static_cast<int64_t>(logInfoObj_.HilogLineSeqs()[CurrentRow()]));
54             break;
55         case Index::TS:
56             sqlite3_result_int64(context_, static_cast<int64_t>(logInfoObj_.TimeStampData()[CurrentRow()]));
57             break;
58         case Index::PID: {
59             sqlite3_result_int64(context_, static_cast<int64_t>(logInfoObj_.Pids()[CurrentRow()]));
60             break;
61         }
62         case Index::TID:
63             sqlite3_result_int64(context_, static_cast<int64_t>(logInfoObj_.Tids()[CurrentRow()]));
64             break;
65         case Index::LEVEL: {
66             if (logInfoObj_.Levels()[CurrentRow()] != INVALID_UINT64) {
67                 auto levelDataIndex = static_cast<size_t>(logInfoObj_.Levels()[CurrentRow()]);
68                 sqlite3_result_text(context_, dataCache_->GetDataFromDict(levelDataIndex).c_str(), STR_DEFAULT_LEN,
69                                     nullptr);
70             }
71             break;
72         }
73         case Index::TAG: {
74             if (logInfoObj_.Tags()[CurrentRow()] != INVALID_UINT64) {
75                 auto tagDataIndex = static_cast<size_t>(logInfoObj_.Tags()[CurrentRow()]);
76                 sqlite3_result_text(context_, dataCache_->GetDataFromDict(tagDataIndex).c_str(), STR_DEFAULT_LEN,
77                                     nullptr);
78             }
79             break;
80         }
81         case Index::CONTEXT: {
82             if (logInfoObj_.Contexts()[CurrentRow()] != INVALID_UINT64) {
83                 auto contextDataIndex = static_cast<size_t>(logInfoObj_.Contexts()[CurrentRow()]);
84                 sqlite3_result_text(context_, dataCache_->GetDataFromDict(contextDataIndex).c_str(), STR_DEFAULT_LEN,
85                                     nullptr);
86             }
87             break;
88         }
89         case Index::ORIGINTS: {
90             sqlite3_result_int64(context_, static_cast<int64_t>(logInfoObj_.OriginTimeStamData()[CurrentRow()]));
91             break;
92         }
93         default:
94             TS_LOGF("Unregistered logColumn : %d", logColumn);
95             break;
96     }
97     return SQLITE_OK;
98 }
99 } // namespace TraceStreamer
100 } // namespace SysTuning
101