• 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 "irq_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index {
22     ID = 0,
23     TS,
24     DUR,
25     CALL_ID,
26     CAT,
27     NAME,
28     DEPTH,
29     COOKIE_ID,
30     PARENT_ID,
31     ARGSET,
32     CHAIN_ID,
33     SPAN_ID,
34     PARENT_SPAN_ID,
35     FLAG,
36     ARGS
37 };
38 }
IrqTable(const TraceDataCache * dataCache)39 IrqTable::IrqTable(const TraceDataCache* dataCache) : TableBase(dataCache)
40 {
41     tableColumn_.push_back(TableBase::ColumnInfo("id", "UNSIGNED BIG INT"));
42     tableColumn_.push_back(TableBase::ColumnInfo("ts", "UNSIGNED BIG INT"));
43     tableColumn_.push_back(TableBase::ColumnInfo("dur", "UNSIGNED BIG INT"));
44     tableColumn_.push_back(TableBase::ColumnInfo("callid", "UNSIGNED INT"));
45     tableColumn_.push_back(TableBase::ColumnInfo("cat", "STRING"));
46     tableColumn_.push_back(TableBase::ColumnInfo("name", "STRING"));
47     tableColumn_.push_back(TableBase::ColumnInfo("depth", "UNSIGNED INT"));
48     tableColumn_.push_back(TableBase::ColumnInfo("cookie", "UNSIGNED BIG INT"));
49     tableColumn_.push_back(TableBase::ColumnInfo("parent_id", "UNSIGNED INT"));
50     tableColumn_.push_back(TableBase::ColumnInfo("argsetid", "UNSIGNED INT"));
51     tableColumn_.push_back(TableBase::ColumnInfo("chainId", "STRING"));
52     tableColumn_.push_back(TableBase::ColumnInfo("spanId", "STRING"));
53     tableColumn_.push_back(TableBase::ColumnInfo("parentSpanId", "STRING"));
54     tableColumn_.push_back(TableBase::ColumnInfo("flag", "STRING"));
55     tableColumn_.push_back(TableBase::ColumnInfo("args", "STRING"));
56     tablePriKey_.push_back("callid");
57     tablePriKey_.push_back("ts");
58     tablePriKey_.push_back("depth");
59 }
60 
~IrqTable()61 IrqTable::~IrqTable() {}
62 
CreateCursor()63 void IrqTable::CreateCursor()
64 {
65     cursor_ = std::make_unique<Cursor>(dataCache_);
66 }
67 
Cursor(const TraceDataCache * dataCache)68 IrqTable::Cursor::Cursor(const TraceDataCache* dataCache)
69     : TableBase::Cursor(dataCache, 0, static_cast<uint32_t>(dataCache->GetConstIrqData().Size())),
70       slicesObj_(dataCache->GetConstIrqData())
71 {
72 }
73 
~Cursor()74 IrqTable::Cursor::~Cursor() {}
75 
Column(int column) const76 int IrqTable::Cursor::Column(int column) const
77 {
78     switch (column) {
79         case ID:
80             sqlite3_result_int64(context_, CurrentRow());
81             break;
82         case TS:
83             sqlite3_result_int64(context_, static_cast<int64_t>(slicesObj_.TimeStamData()[CurrentRow()]));
84             break;
85         case DUR:
86             sqlite3_result_int64(context_, static_cast<int64_t>(slicesObj_.DursData()[CurrentRow()]));
87             break;
88         case CALL_ID:
89             sqlite3_result_int64(context_, static_cast<int64_t>(slicesObj_.CallIds()[CurrentRow()]));
90             break;
91         case CAT: {
92             if (slicesObj_.CatsData()[CurrentRow()] != INVALID_UINT64) {
93                 auto catsDataIndex = static_cast<size_t>(slicesObj_.CatsData()[CurrentRow()]);
94                 sqlite3_result_text(context_, dataCache_->GetDataFromDict(catsDataIndex).c_str(), STR_DEFAULT_LEN,
95                                     nullptr);
96             }
97             break;
98         }
99         case NAME: {
100             if (slicesObj_.NamesData()[CurrentRow()] != INVALID_UINT64) {
101                 auto nameDataIndex = static_cast<size_t>(slicesObj_.NamesData()[CurrentRow()]);
102                 sqlite3_result_text(context_, dataCache_->GetDataFromDict(nameDataIndex).c_str(), STR_DEFAULT_LEN,
103                                     nullptr);
104             }
105             break;
106         }
107         case DEPTH:
108             sqlite3_result_int64(context_, static_cast<int64_t>(slicesObj_.Depths()[CurrentRow()]));
109             break;
110         case COOKIE_ID:
111             if (slicesObj_.Cookies()[CurrentRow()] != INVALID_UINT64) {
112                 sqlite3_result_int64(context_, static_cast<int64_t>(slicesObj_.Cookies()[CurrentRow()]));
113             }
114             break;
115         case PARENT_ID: {
116             if (slicesObj_.ParentIdData()[CurrentRow()].has_value()) {
117                 sqlite3_result_int64(context_, static_cast<int64_t>(slicesObj_.ParentIdData()[CurrentRow()].value()));
118             }
119             break;
120         }
121         case ARGSET:
122             if (slicesObj_.ArgSetIdsData()[CurrentRow()] != INVALID_UINT32) {
123                 sqlite3_result_int64(context_, static_cast<int64_t>(slicesObj_.ArgSetIdsData()[CurrentRow()]));
124             }
125             break;
126         case CHAIN_ID:
127             sqlite3_result_text(context_, slicesObj_.ChainIds()[CurrentRow()].c_str(),
128                                 STR_DEFAULT_LEN, nullptr);
129             break;
130         case SPAN_ID:
131             sqlite3_result_text(context_, slicesObj_.SpanIds()[CurrentRow()].c_str(),
132                                 STR_DEFAULT_LEN, nullptr);
133             break;
134         case PARENT_SPAN_ID:
135             sqlite3_result_text(context_,
136                                 slicesObj_.ParentSpanIds()[CurrentRow()].c_str(),
137                                 STR_DEFAULT_LEN, nullptr);
138             break;
139         case FLAG:
140             sqlite3_result_text(context_, slicesObj_.Flags()[CurrentRow()].c_str(),
141                                 STR_DEFAULT_LEN, nullptr);
142             break;
143         case ARGS:
144             sqlite3_result_text(context_, slicesObj_.ArgsData()[CurrentRow()].c_str(),
145                                 STR_DEFAULT_LEN, nullptr);
146             break;
147         default:
148             TS_LOGF("Unregistered column : %d", column);
149             break;
150     }
151     return SQLITE_OK;
152 }
153 } // namespace TraceStreamer
154 } // namespace SysTuning
155