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/dynamic/experimental_sched_upid_generator.h"
18
19 namespace perfetto {
20 namespace trace_processor {
21
ExperimentalSchedUpidGenerator(const tables::SchedSliceTable & sched,const tables::ThreadTable & thread)22 ExperimentalSchedUpidGenerator::ExperimentalSchedUpidGenerator(
23 const tables::SchedSliceTable& sched,
24 const tables::ThreadTable& thread)
25 : sched_slice_table_(&sched), thread_table_(&thread) {}
26 ExperimentalSchedUpidGenerator::~ExperimentalSchedUpidGenerator() = default;
27
CreateSchema()28 Table::Schema ExperimentalSchedUpidGenerator::CreateSchema() {
29 Table::Schema schema = tables::SchedSliceTable::Schema();
30 schema.columns.emplace_back(
31 Table::Schema::Column{"upid", SqlValue::Type::kLong, false /* is_id */,
32 false /* is_sorted */, false /* is_hidden */});
33 return schema;
34 }
35
TableName()36 std::string ExperimentalSchedUpidGenerator::TableName() {
37 return "experimental_sched_upid";
38 }
39
EstimateRowCount()40 uint32_t ExperimentalSchedUpidGenerator::EstimateRowCount() {
41 return sched_slice_table_->row_count();
42 }
43
ValidateConstraints(const QueryConstraints &)44 util::Status ExperimentalSchedUpidGenerator::ValidateConstraints(
45 const QueryConstraints&) {
46 return util::OkStatus();
47 }
48
ComputeTable(const std::vector<Constraint> &,const std::vector<Order> &)49 std::unique_ptr<Table> ExperimentalSchedUpidGenerator::ComputeTable(
50 const std::vector<Constraint>&,
51 const std::vector<Order>&) {
52 if (!upid_column_) {
53 upid_column_.reset(new NullableVector<uint32_t>(ComputeUpidColumn()));
54 }
55 return std::unique_ptr<Table>(new Table(sched_slice_table_->ExtendWithColumn(
56 "upid", upid_column_.get(),
57 TypedColumn<base::Optional<uint32_t>>::default_flags())));
58 }
59
ComputeUpidColumn()60 NullableVector<uint32_t> ExperimentalSchedUpidGenerator::ComputeUpidColumn() {
61 NullableVector<uint32_t> upid;
62 for (uint32_t i = 0; i < sched_slice_table_->row_count(); ++i) {
63 upid.Append(thread_table_->upid()[sched_slice_table_->utid()[i]]);
64 }
65 return upid;
66 }
67
68 } // namespace trace_processor
69 } // namespace perfetto
70