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_CONNECTED_FLOW_H_
18 #define SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_CONNECTED_FLOW_H_
19 
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "perfetto/ext/base/status_or.h"
26 #include "perfetto/trace_processor/basic_types.h"
27 #include "src/trace_processor/db/table.h"
28 #include "src/trace_processor/perfetto_sql/intrinsics/table_functions/static_table_function.h"
29 #include "src/trace_processor/storage/trace_storage.h"
30 
31 namespace perfetto::trace_processor {
32 
33 class TraceProcessorContext;
34 
35 // Implementation of tables:
36 // - DIRECTLY_CONNECTED_FLOW
37 // - PRECEDING_FLOW
38 // - FOLLOWING_FLOW
39 class ConnectedFlow : public StaticTableFunction {
40  public:
41   enum class Mode {
42     // Directly connected slices through the same flow ID given by the trace
43     // writer.
44     kDirectlyConnectedFlow,
45     // Flow events which can be reached from the given slice by going over
46     // incoming flow events or to parent slices.
47     kPrecedingFlow,
48     // Flow events which can be reached from the given slice by going over
49     // outgoing flow events or to child slices.
50     kFollowingFlow,
51   };
52 
53   ConnectedFlow(Mode mode, const TraceStorage*);
54   ~ConnectedFlow() override;
55 
56   Table::Schema CreateSchema() override;
57   std::string TableName() override;
58   uint32_t EstimateRowCount() override;
59   base::StatusOr<std::unique_ptr<Table>> ComputeTable(
60       const std::vector<SqlValue>& arguments) override;
61 
62  private:
63   Mode mode_;
64   const TraceStorage* storage_ = nullptr;
65 };
66 
67 }  // namespace perfetto::trace_processor
68 
69 #endif  // SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_CONNECTED_FLOW_H_
70