1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "src/trace_processor/prelude/table_functions/experimental_sched_upid.h"
18
19 #include "src/trace_processor/prelude/table_functions/tables_py.h"
20
21 namespace perfetto {
22 namespace trace_processor {
23 namespace tables {
24
25 ExperimentalSchedUpidTable::~ExperimentalSchedUpidTable() = default;
26
27 } // namespace tables
28
ExperimentalSchedUpid(const tables::SchedSliceTable & sched,const tables::ThreadTable & thread)29 ExperimentalSchedUpid::ExperimentalSchedUpid(
30 const tables::SchedSliceTable& sched,
31 const tables::ThreadTable& thread)
32 : sched_slice_table_(&sched), thread_table_(&thread) {}
33 ExperimentalSchedUpid::~ExperimentalSchedUpid() = default;
34
CreateSchema()35 Table::Schema ExperimentalSchedUpid::CreateSchema() {
36 return tables::ExperimentalSchedUpidTable::ComputeStaticSchema();
37 }
38
TableName()39 std::string ExperimentalSchedUpid::TableName() {
40 return tables::ExperimentalSchedUpidTable::Name();
41 }
42
EstimateRowCount()43 uint32_t ExperimentalSchedUpid::EstimateRowCount() {
44 return sched_slice_table_->row_count();
45 }
46
ValidateConstraints(const QueryConstraints &)47 base::Status ExperimentalSchedUpid::ValidateConstraints(
48 const QueryConstraints&) {
49 return base::OkStatus();
50 }
51
ComputeTable(const std::vector<Constraint> &,const std::vector<Order> &,const BitVector &,std::unique_ptr<Table> & table_return)52 base::Status ExperimentalSchedUpid::ComputeTable(
53 const std::vector<Constraint>&,
54 const std::vector<Order>&,
55 const BitVector&,
56 std::unique_ptr<Table>& table_return) {
57 if (!sched_upid_table_) {
58 sched_upid_table_ = tables::ExperimentalSchedUpidTable::ExtendParent(
59 *sched_slice_table_, ComputeUpidColumn());
60 }
61 table_return.reset(new Table(sched_upid_table_->Copy()));
62 return base::OkStatus();
63 }
64
65 ColumnStorage<std::optional<UniquePid>>
ComputeUpidColumn()66 ExperimentalSchedUpid::ComputeUpidColumn() {
67 ColumnStorage<std::optional<UniquePid>> upid;
68 for (uint32_t i = 0; i < sched_slice_table_->row_count(); ++i) {
69 upid.Append(thread_table_->upid()[sched_slice_table_->utid()[i]]);
70 }
71 return upid;
72 }
73
74 } // namespace trace_processor
75 } // namespace perfetto
76