• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PRELUDE_TABLE_FUNCTIONS_ANCESTOR_H_
18 #define SRC_TRACE_PROCESSOR_PRELUDE_TABLE_FUNCTIONS_ANCESTOR_H_
19 
20 #include <optional>
21 
22 #include "src/trace_processor/prelude/table_functions/table_function.h"
23 #include "src/trace_processor/storage/trace_storage.h"
24 
25 namespace perfetto {
26 namespace trace_processor {
27 
28 class TraceProcessorContext;
29 
30 // Implements the following dynamic tables:
31 // * ancestor_slice
32 // * experimental_ancestor_stack_profile_callsite
33 // * ancestor_slice_by_stack
34 //
35 // See docs/analysis/trace-processor for usage.
36 class Ancestor : public TableFunction {
37  public:
38   enum class Type { kSlice = 1, kStackProfileCallsite = 2, kSliceByStack = 3 };
39 
40   Ancestor(Type type, const TraceStorage* storage);
41 
42   Table::Schema CreateSchema() override;
43   std::string TableName() override;
44   uint32_t EstimateRowCount() override;
45   base::Status ValidateConstraints(const QueryConstraints&) override;
46   base::Status ComputeTable(const std::vector<Constraint>& cs,
47                             const std::vector<Order>& ob,
48                             const BitVector& cols_used,
49                             std::unique_ptr<Table>& table_return) override;
50 
51   // Returns a vector of rows numbers which are ancestors of |slice_id|.
52   // Returns std::nullopt if an invalid |slice_id| is given. This is used by
53   // ConnectedFlow to traverse flow indirectly connected flow events.
54   static std::optional<std::vector<tables::SliceTable::RowNumber>>
55   GetAncestorSlices(const tables::SliceTable& slices, SliceId slice_id);
56 
57  private:
58   Type type_;
59   const TraceStorage* storage_ = nullptr;
60 };
61 
62 }  // namespace trace_processor
63 }  // namespace perfetto
64 
65 #endif  // SRC_TRACE_PROCESSOR_PRELUDE_TABLE_FUNCTIONS_ANCESTOR_H_
66