1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 "js_config_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21 PID = 0,
22 TYPE,
23 INTERVAL,
24 CAPTURE_NUMERIC_VALUE,
25 TRACK_ALLOCATION,
26 CPU_PROFILER,
27 CPU_PROFILER_INTERVAL
28 };
JsConfigTable(const TraceDataCache * dataCache)29 JsConfigTable::JsConfigTable(const TraceDataCache *dataCache) : TableBase(dataCache)
30 {
31 tableColumn_.push_back(TableBase::ColumnInfo("pid", "INTEGER"));
32 tableColumn_.push_back(TableBase::ColumnInfo("type", "INTEGER"));
33 tableColumn_.push_back(TableBase::ColumnInfo("interval", "INTEGER"));
34 tableColumn_.push_back(TableBase::ColumnInfo("capture_numeric_value", "INTEGER"));
35 tableColumn_.push_back(TableBase::ColumnInfo("trace_allocation", "INTEGER"));
36 tableColumn_.push_back(TableBase::ColumnInfo("enable_cpu_profiler ", "INTEGER"));
37 tableColumn_.push_back(TableBase::ColumnInfo("cpu_profiler_interval ", "INTEGER"));
38 tablePriKey_.push_back("pid");
39 }
40
~JsConfigTable()41 JsConfigTable::~JsConfigTable() {}
42
CreateCursor()43 std::unique_ptr<TableBase::Cursor> JsConfigTable::CreateCursor()
44 {
45 return std::make_unique<Cursor>(dataCache_, this);
46 }
47
Cursor(const TraceDataCache * dataCache,TableBase * table)48 JsConfigTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
49 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstJsConfigData().Size())),
50 jsConfig_(dataCache->GetConstJsConfigData())
51 {
52 }
53
~Cursor()54 JsConfigTable::Cursor::~Cursor() {}
55
Column(int32_t col) const56 int32_t JsConfigTable::Cursor::Column(int32_t col) const
57 {
58 switch (static_cast<Index>(col)) {
59 case Index::PID:
60 sqlite3_result_int64(context_, static_cast<int64_t>(jsConfig_.Pids()[CurrentRow()]));
61 break;
62 case Index::TYPE:
63 sqlite3_result_int64(context_, static_cast<int64_t>(jsConfig_.Types()[CurrentRow()]));
64 break;
65 case Index::INTERVAL:
66 sqlite3_result_int64(context_, static_cast<int64_t>(jsConfig_.Intervals()[CurrentRow()]));
67 break;
68 case Index::CAPTURE_NUMERIC_VALUE:
69 sqlite3_result_int64(context_, static_cast<int64_t>(jsConfig_.CaptureNumericValue()[CurrentRow()]));
70 break;
71 case Index::TRACK_ALLOCATION:
72 sqlite3_result_int64(context_, static_cast<int64_t>(jsConfig_.TrackAllocations()[CurrentRow()]));
73 break;
74 case Index::CPU_PROFILER:
75 sqlite3_result_int64(context_, static_cast<int64_t>(jsConfig_.CpuProfiler()[CurrentRow()]));
76 break;
77 case Index::CPU_PROFILER_INTERVAL:
78 sqlite3_result_int64(context_, static_cast<int64_t>(jsConfig_.CpuProfilerInterval()[CurrentRow()]));
79 break;
80 default:
81 TS_LOGF("Unregistered column : %d", col);
82 break;
83 }
84 return SQLITE_OK;
85 }
86 } // namespace TraceStreamer
87 } // namespace SysTuning
88