• 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 "slice_table.h"
17 #include <cmath>
18 
19 namespace SysTuning {
20 namespace TraceStreamer {
21 enum class Index : int32_t { TS = 0, ENDTS = 1, VALUE = 2, SLICE_ID = 3 };
SliceTable(const TraceDataCache * dataCache)22 SliceTable::SliceTable(const TraceDataCache* dataCache) : DemoTableBase(dataCache)
23 {
24     demoTableColumn_.push_back(DemoTableBase::ColumnInfo("start_ts", "INTEGER"));
25     demoTableColumn_.push_back(DemoTableBase::ColumnInfo("end_ts", "INTEGER"));
26     demoTableColumn_.push_back(DemoTableBase::ColumnInfo("value", "INTEGER"));
27     demoTableColumn_.push_back(DemoTableBase::ColumnInfo("slice_id", "INTEGER"));
28     demoTablePriKey_.push_back("start_ts");
29     demoTablePriKey_.push_back("slice_id");
30 }
31 
~SliceTable()32 SliceTable::~SliceTable() {}
33 
CreateCursor()34 std::unique_ptr<DemoTableBase::Cursor> SliceTable::CreateCursor()
35 {
36     return std::make_unique<Cursor>(demoTraceDataCache_, this);
37 }
38 
Cursor(const TraceDataCache * dataCache,DemoTableBase * table)39 SliceTable::Cursor::Cursor(const TraceDataCache* dataCache, DemoTableBase* table)
40     : DemoTableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstSliceData().Size())),
41       sliceDataObj_(dataCache->GetConstSliceData())
42 {
43 }
44 
~Cursor()45 SliceTable::Cursor::~Cursor() {}
46 
Column(int32_t SliceTabColumn) const47 int32_t SliceTable::Cursor::Column(int32_t SliceTabColumn) const
48 {
49     switch (static_cast<Index>(SliceTabColumn)) {
50         case Index::TS: {
51             sqlite3_result_int64(demoContext_, static_cast<int64_t>(sliceDataObj_.TimeStamp()[CurrentRow()]));
52             break;
53         }
54         case Index::ENDTS: {
55             sqlite3_result_int64(demoContext_, static_cast<int64_t>(sliceDataObj_.EndTs()[CurrentRow()]));
56             break;
57         }
58         case Index::VALUE: {
59             sqlite3_result_int64(demoContext_, static_cast<int64_t>(sliceDataObj_.Value()[CurrentRow()]));
60             break;
61         }
62         case Index::SLICE_ID: {
63             sqlite3_result_int64(demoContext_, static_cast<int64_t>(sliceDataObj_.SliceId()[CurrentRow()]));
64             break;
65         }
66         default:
67             TS_LOGF("Unregistered SliceTabColumn : %d", SliceTabColumn);
68             break;
69     }
70     return SQLITE_OK;
71 }
72 } // namespace TraceStreamer
73 } // namespace SysTuning
74