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 #ifndef SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_ANCESTOR_H_ 18 #define SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_ANCESTOR_H_ 19 20 #include <cstdint> 21 #include <memory> 22 #include <optional> 23 #include <string> 24 #include <vector> 25 26 #include "perfetto/ext/base/status_or.h" 27 #include "perfetto/trace_processor/basic_types.h" 28 #include "src/trace_processor/db/table.h" 29 #include "src/trace_processor/perfetto_sql/intrinsics/table_functions/static_table_function.h" 30 #include "src/trace_processor/storage/trace_storage.h" 31 #include "src/trace_processor/tables/slice_tables_py.h" 32 33 namespace perfetto::trace_processor { 34 35 class TraceProcessorContext; 36 37 // Implements the following dynamic tables: 38 // * ancestor_slice 39 // * experimental_ancestor_stack_profile_callsite 40 // * ancestor_slice_by_stack 41 // 42 // See docs/analysis/trace-processor for usage. 43 class Ancestor : public StaticTableFunction { 44 public: 45 enum class Type { kSlice = 1, kStackProfileCallsite = 2, kSliceByStack = 3 }; 46 47 Ancestor(Type type, const TraceStorage* storage); 48 49 Table::Schema CreateSchema() override; 50 std::string TableName() override; 51 uint32_t EstimateRowCount() override; 52 base::StatusOr<std::unique_ptr<Table>> ComputeTable( 53 const std::vector<SqlValue>& arguments) override; 54 55 // Returns a vector of rows numbers which are ancestors of |slice_id|. 56 // Returns std::nullopt if an invalid |slice_id| is given. This is used by 57 // ConnectedFlow to traverse flow indirectly connected flow events. 58 static std::optional<std::vector<tables::SliceTable::RowNumber>> 59 GetAncestorSlices(const tables::SliceTable& slices, SliceId slice_id); 60 61 private: 62 Type type_; 63 const TraceStorage* storage_ = nullptr; 64 }; 65 66 } // namespace perfetto::trace_processor 67 68 #endif // SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_ANCESTOR_H_ 69