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_frame_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { EVENT_ID = 0, DEPTH, IP, SP, SYMBOL_NAME, FILE_PATH, OFFSET, SYMBOL_OFFSET };
22 }
HeapFrameTable(const TraceDataCache * dataCache)23 HeapFrameTable::HeapFrameTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25 tableColumn_.push_back(TableBase::ColumnInfo("eventId", "UNSIGNED BIG INT"));
26 tableColumn_.push_back(TableBase::ColumnInfo("depth", "UNSIGNED BIG INT"));
27 tableColumn_.push_back(TableBase::ColumnInfo("ip", "UNSIGNED BIG INT"));
28 tableColumn_.push_back(TableBase::ColumnInfo("sp", "UNSIGNED BIG INT"));
29 tableColumn_.push_back(TableBase::ColumnInfo("symbol_name", "STRING"));
30 tableColumn_.push_back(TableBase::ColumnInfo("file_path", "STRING"));
31 tableColumn_.push_back(TableBase::ColumnInfo("offset", "UNSIGNED BIG INT"));
32 tableColumn_.push_back(TableBase::ColumnInfo("symbol_offset", "UNSIGNED BIG INT"));
33 tablePriKey_.push_back("eventId");
34 }
35
~HeapFrameTable()36 HeapFrameTable::~HeapFrameTable() {}
37
CreateCursor()38 void HeapFrameTable::CreateCursor()
39 {
40 cursor_ = std::make_unique<Cursor>(dataCache_);
41 }
42
Cursor(const TraceDataCache * dataCache)43 HeapFrameTable::Cursor::Cursor(const TraceDataCache* dataCache)
44 : TableBase::Cursor(dataCache, 0, static_cast<uint32_t>(dataCache->GetConstHeapFrameData().Size())),
45 heapFrameInfoObj_(dataCache->GetConstHeapFrameData())
46 {
47 }
48
~Cursor()49 HeapFrameTable::Cursor::~Cursor() {}
50
Column(int column) const51 int HeapFrameTable::Cursor::Column(int column) const
52 {
53 switch (column) {
54 case EVENT_ID:
55 sqlite3_result_int64(context_, static_cast<int64_t>(heapFrameInfoObj_.EventIds()[CurrentRow()]));
56 break;
57 case DEPTH:
58 sqlite3_result_int64(context_, static_cast<int64_t>(heapFrameInfoObj_.Depths()[CurrentRow()]));
59 break;
60 case IP:
61 sqlite3_result_int64(context_, static_cast<int64_t>(heapFrameInfoObj_.Ips()[CurrentRow()]));
62 break;
63 case SP: {
64 sqlite3_result_int64(context_, static_cast<int64_t>(heapFrameInfoObj_.Sps()[CurrentRow()]));
65 break;
66 }
67 case SYMBOL_NAME:
68 if (heapFrameInfoObj_.SymbolNames()[CurrentRow()] != INVALID_UINT64) {
69 auto symbolNameDataIndex = static_cast<int64_t>(heapFrameInfoObj_.SymbolNames()[CurrentRow()]);
70 sqlite3_result_text(context_, dataCache_->GetDataFromDict(symbolNameDataIndex).c_str(), STR_DEFAULT_LEN,
71 nullptr);
72 }
73 break;
74 case FILE_PATH: {
75 if (heapFrameInfoObj_.FilePaths()[CurrentRow()] != INVALID_UINT64) {
76 auto filePathDataIndex = static_cast<size_t>(heapFrameInfoObj_.FilePaths()[CurrentRow()]);
77 sqlite3_result_text(context_, dataCache_->GetDataFromDict(filePathDataIndex).c_str(), STR_DEFAULT_LEN,
78 nullptr);
79 }
80 break;
81 }
82 case OFFSET: {
83 sqlite3_result_int64(context_, static_cast<int64_t>(heapFrameInfoObj_.Offsets()[CurrentRow()]));
84 break;
85 }
86 case SYMBOL_OFFSET: {
87 sqlite3_result_int64(context_, static_cast<int64_t>(heapFrameInfoObj_.SymbolOffsets()[CurrentRow()]));
88 break;
89 }
90 default:
91 TS_LOGF("Unregistered column : %d", column);
92 break;
93 }
94 return SQLITE_OK;
95 }
96 } // namespace TraceStreamer
97 } // namespace SysTuning
98