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