• 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 "heap_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index {
22     EVENT_ID = 0,
23     IPID,
24     ITID,
25     EVENT_TYPE,
26     START_TS,
27     END_TS,
28     DURATION,
29     ADDR,
30     HEAP_SIZE,
31     ALL_HEAP_SIZE,
32     CURRENT_SIZE_DUR
33 };
34 }
HeapTable(const TraceDataCache * dataCache)35 HeapTable::HeapTable(const TraceDataCache* dataCache) : TableBase(dataCache)
36 {
37     tableColumn_.push_back(TableBase::ColumnInfo("eventId", "UNSIGNED BIG INT"));
38     tableColumn_.push_back(TableBase::ColumnInfo("ipid", "UNSIGNED BIG INT"));
39     tableColumn_.push_back(TableBase::ColumnInfo("itid", "UNSIGNED BIG INT"));
40     tableColumn_.push_back(TableBase::ColumnInfo("event_type", "STRING"));
41     tableColumn_.push_back(TableBase::ColumnInfo("start_ts", "UNSIGNED BIG INT"));
42     tableColumn_.push_back(TableBase::ColumnInfo("end_ts", "UNSIGNED BIG INT"));
43     tableColumn_.push_back(TableBase::ColumnInfo("dur", "UNSIGNED BIG INT"));
44     tableColumn_.push_back(TableBase::ColumnInfo("addr", "UNSIGNED BIG INT"));
45     tableColumn_.push_back(TableBase::ColumnInfo("heap_size", "UNSIGNED INT"));
46     tableColumn_.push_back(TableBase::ColumnInfo("all_heap_size", "UNSIGNED INT"));
47     tableColumn_.push_back(TableBase::ColumnInfo("current_size_dur", "UNSIGNED INT"));
48     tablePriKey_.push_back("eventId");
49 }
50 
~HeapTable()51 HeapTable::~HeapTable() {}
52 
CreateCursor()53 void HeapTable::CreateCursor()
54 {
55     cursor_ = std::make_unique<Cursor>(dataCache_);
56 }
57 
Cursor(const TraceDataCache * dataCache)58 HeapTable::Cursor::Cursor(const TraceDataCache* dataCache)
59     : TableBase::Cursor(dataCache, 0, static_cast<uint32_t>(dataCache->GetConstHeapData().Size())),
60       heapInfoObj_(dataCache->GetConstHeapData())
61 {
62 }
63 
~Cursor()64 HeapTable::Cursor::~Cursor() {}
65 
Column(int column) const66 int HeapTable::Cursor::Column(int column) const
67 {
68     switch (column) {
69         case EVENT_ID:
70             sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.EventIds()[CurrentRow()]));
71             break;
72         case IPID:
73             sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.Ipids()[CurrentRow()]));
74             break;
75         case ITID:
76             sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.Itids()[CurrentRow()]));
77             break;
78         case EVENT_TYPE: {
79             if (heapInfoObj_.EventTypes()[CurrentRow()] != INVALID_UINT64) {
80                 auto eventTypeDataIndex = static_cast<size_t>(heapInfoObj_.EventTypes()[CurrentRow()]);
81                 sqlite3_result_text(context_, dataCache_->GetDataFromDict(eventTypeDataIndex).c_str(), STR_DEFAULT_LEN,
82                                     nullptr);
83             }
84             break;
85         }
86         case START_TS:
87             sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.TimeStamData()[CurrentRow()]));
88             break;
89         case END_TS:
90             if (static_cast<int64_t>(heapInfoObj_.EndTimeStamps()[CurrentRow()]) != 0) {
91                 sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.EndTimeStamps()[CurrentRow()]));
92             }
93             break;
94         case DURATION:
95             if (static_cast<int64_t>(heapInfoObj_.Durations()[CurrentRow()]) != 0) {
96                 sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.Durations()[CurrentRow()]));
97             }
98             break;
99         case ADDR: {
100             sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.Addrs()[CurrentRow()]));
101             break;
102         }
103         case HEAP_SIZE: {
104             sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.HeapSizes()[CurrentRow()]));
105             break;
106         }
107         case ALL_HEAP_SIZE: {
108             sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.AllHeapSizes()[CurrentRow()]));
109             break;
110         }
111         case CURRENT_SIZE_DUR: {
112             sqlite3_result_int64(context_, static_cast<int64_t>(heapInfoObj_.CurrentSizeDurs()[CurrentRow()]));
113             break;
114         }
115         default:
116             TS_LOGF("Unregistered column : %d", column);
117             break;
118     }
119     return SQLITE_OK;
120 }
121 } // namespace TraceStreamer
122 } // namespace SysTuning
123