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 "slice_object_table.h"
17 #include <cmath>
18
19 namespace SysTuning {
20 namespace TraceStreamer {
21 enum class Index : int32_t { SLICE_ID = 0, SLICE_NAME = 1 };
SliceObjectTable(const TraceDataCache * dataCache)22 SliceObjectTable::SliceObjectTable(const TraceDataCache* dataCache) : DemoTableBase(dataCache)
23 {
24 demoTableColumn_.push_back(DemoTableBase::ColumnInfo("slice_id", "INTEGER"));
25 demoTableColumn_.push_back(DemoTableBase::ColumnInfo("slice_name", "REAL"));
26 demoTablePriKey_.push_back("slice_id");
27 }
28
~SliceObjectTable()29 SliceObjectTable::~SliceObjectTable() {}
30
CreateCursor()31 std::unique_ptr<DemoTableBase::Cursor> SliceObjectTable::CreateCursor()
32 {
33 return std::make_unique<Cursor>(demoTraceDataCache_, this);
34 }
35
Cursor(const TraceDataCache * dataCache,DemoTableBase * table)36 SliceObjectTable::Cursor::Cursor(const TraceDataCache* dataCache, DemoTableBase* table)
37 : DemoTableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstSliceObjectData().Size())),
38 sliceObjectDataObj_(dataCache->GetConstSliceObjectData())
39 {
40 }
41
~Cursor()42 SliceObjectTable::Cursor::~Cursor() {}
43
Column(int32_t SliceObjColumn) const44 int32_t SliceObjectTable::Cursor::Column(int32_t SliceObjColumn) const
45 {
46 switch (static_cast<Index>(SliceObjColumn)) {
47 case Index::SLICE_ID: {
48 sqlite3_result_int64(demoContext_, static_cast<int64_t>(sliceObjectDataObj_.SliceId()[CurrentRow()]));
49 break;
50 }
51 case Index::SLICE_NAME: {
52 sqlite3_result_text(demoContext_, sliceObjectDataObj_.SliceName()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
53 nullptr);
54 break;
55 }
56 default:
57 TS_LOGF("Unregistered SliceObjColumn : %d", SliceObjColumn);
58 break;
59 }
60 return SQLITE_OK;
61 }
62 } // namespace TraceStreamer
63 } // namespace SysTuning
64