1 /* 2 * Copyright (C) 2024 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_FUNCTIONS_DFS_H_ 18 #define SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_FUNCTIONS_DFS_H_ 19 20 #include "src/trace_processor/containers/string_pool.h" 21 #include "src/trace_processor/sqlite/bindings/sqlite_aggregate_function.h" 22 23 namespace perfetto::trace_processor { 24 25 // An SQL aggregate-function which performs a DFS from a given start node in a 26 // graph and returns all the nodes which are reachable from the start node. 27 // 28 // Arguments: 29 // 1) |source_node_id|: a non-null uint32 corresponding to the source of edge. 30 // 2) |dest_node_id|: a non-null uint32 corresponding to the destination of 31 // the edge. 32 // 3) |start_node_id|: a non-null uint32 corresponding to of the start node in 33 // the graph from which reachability should be computed. 34 // 35 // Returns: 36 // A value table with the nodes reachable from the start node and their 37 // "parent" in the tree generated by the DFS. The schema of the table is 38 // (node_id int64_t, parent_node_id optional<int64_t>). 39 // 40 // Note: this function is not intended to be used directly from SQL: instead 41 // macros exist in the standard library, wrapping it and making it 42 // user-friendly. 43 struct Dfs : public SqliteAggregateFunction<Dfs> { 44 static constexpr char kName[] = "__intrinsic_dfs"; 45 static constexpr int kArgCount = 3; 46 using UserDataContext = StringPool; 47 48 static void Step(sqlite3_context*, int argc, sqlite3_value** argv); 49 static void Final(sqlite3_context* ctx); 50 }; 51 52 } // namespace perfetto::trace_processor 53 54 #endif // SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_FUNCTIONS_DFS_H_ 55