• 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 "sched_slice_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { ID = 0, TYPE, TS, DUR, CPU, INTERNAL_TID, END_STATE, PRIORITY };
22 }
SchedSliceTable(const TraceDataCache * dataCache)23 SchedSliceTable::SchedSliceTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25     tableColumn_.push_back(TableBase::ColumnInfo("id", "INT"));
26     tableColumn_.push_back(TableBase::ColumnInfo("type", "STRING"));
27     tableColumn_.push_back(TableBase::ColumnInfo("ts", "INT"));
28     tableColumn_.push_back(TableBase::ColumnInfo("dur", "UNSIGNED BIG INT"));
29     tableColumn_.push_back(TableBase::ColumnInfo("cpu", "UNSIGNED BIG INT"));
30     tableColumn_.push_back(TableBase::ColumnInfo("itid", "UNSIGNED BIG INT"));
31     tableColumn_.push_back(TableBase::ColumnInfo("end_state", "STRING"));
32     tableColumn_.push_back(TableBase::ColumnInfo("priority", "INT"));
33     tablePriKey_.push_back("id");
34 }
35 
~SchedSliceTable()36 SchedSliceTable::~SchedSliceTable() {}
37 
CreateCursor()38 void SchedSliceTable::CreateCursor()
39 {
40     cursor_ = std::make_unique<Cursor>(dataCache_);
41 }
42 
Cursor(const TraceDataCache * dataCache)43 SchedSliceTable::Cursor::Cursor(const TraceDataCache* dataCache)
44     : TableBase::Cursor(dataCache, 0, static_cast<uint32_t>(dataCache->GetConstSchedSliceData().Size())),
45       schedSliceObj_(dataCache->GetConstSchedSliceData())
46 {
47 }
48 
~Cursor()49 SchedSliceTable::Cursor::~Cursor() {}
50 
Column(int col) const51 int SchedSliceTable::Cursor::Column(int col) const
52 {
53     switch (col) {
54         case ID:
55             sqlite3_result_int64(context_, static_cast<sqlite3_int64>(CurrentRow()));
56             break;
57         case TYPE:
58             sqlite3_result_text(context_, "sched_slice", STR_DEFAULT_LEN, nullptr);
59             break;
60         case TS:
61             sqlite3_result_int64(context_, static_cast<sqlite3_int64>(schedSliceObj_.TimeStamData()[CurrentRow()]));
62             break;
63         case DUR:
64             sqlite3_result_int64(context_, static_cast<sqlite3_int64>(schedSliceObj_.DursData()[CurrentRow()]));
65             break;
66         case CPU:
67             sqlite3_result_int64(context_, static_cast<sqlite3_int64>(schedSliceObj_.CpusData()[CurrentRow()]));
68             break;
69         case INTERNAL_TID:
70             sqlite3_result_int64(context_, static_cast<sqlite3_int64>(schedSliceObj_.InternalTidsData()[CurrentRow()]));
71             break;
72         case END_STATE: {
73             const std::string& str = dataCache_->GetConstSchedStateData(schedSliceObj_.EndStatesData()[CurrentRow()]);
74             sqlite3_result_text(context_, str.c_str(), STR_DEFAULT_LEN, nullptr);
75             break;
76         }
77         case PRIORITY:
78             sqlite3_result_int64(context_, static_cast<sqlite3_int64>(schedSliceObj_.PriorityData()[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