Make preceding_flow and following_flow follow relative slices
Based on altimin@'s cl:
https://android-review.googlesource.com/c/platform/external/perfetto/+/1484245
This changes the preceding_flows() SQL function to follow flows incoming
flows by checking all the ancestors of the slices that are followed. The
following_flows() function will follow all the descendants of the slices
followed. Removes connected_flow function because it can be trivially
implemented in SQL. The connected_flows() function is renamed to
directly_connected_flows() and will follow flows without relatives,
and this is kept as is for the UI to show flows.
Change-Id: I941a7e9bd1bd8328108fa0091906c546e181f9ec
diff --git a/docs/analysis/trace-processor.md b/docs/analysis/trace-processor.md
index 49e2f5e..dad2832 100644
--- a/docs/analysis/trace-processor.md
+++ b/docs/analysis/trace-processor.md
@@ -347,26 +347,41 @@
FROM interesting_slices
```
-### Following/Preceding/Connected flows
-following_flow, preceding_flow, connected_flow are custom operator tables that
-take a [slice table's id column](/docs/analysis/sql-tables.autogen#slice) and
-collect all entries of [flow table](/docs/analysis/sql-tables.autogen#flow),
-that are directly or indirectly connected to the given starting slice.
+### Connected/Following/Preceding flows
-`FOLLOWING_FLOW(start_slice_id)` - contains all entries of
-[flow table](/docs/analysis/sql-tables.autogen#flow)
-that are present in any chain of kind: `flow[0] -> flow[1] -> ... -> flow[n]`,
-where `flow[i].slice_out = flow[i+1].slice_in` and
-`flow[0].slice_out = start_slice_id`.
+DIRECTLY_CONNECTED_FLOW, FOLLOWING_FLOW and PRECEDING_FLOW are custom operator
+tables that take a
+[slice table's id column](/docs/analysis/sql-tables.autogen#slice) and collect
+all entries of [flow table](/docs/analysis/sql-tables.autogen#flow), that are
+directly or indirectly connected to the given starting slice.
-`PRECEDING_FLOW(start_slice_id)` - contains all entries of
-[flow table](/docs/analysis/sql-tables.autogen#flow)
-that are present in any chain of kind: `flow[n] -> flow[n-1] -> ... -> flow[0]`,
-where `flow[i].slice_in = flow[i+1].slice_out` and
-`flow[0].slice_in = start_slice_id`.
+`DIRECTLY_CONNECTED_FLOW(start_slice_id)` - contains all entries of
+[flow table](/docs/analysis/sql-tables.autogen#flow) that are present in any
+chain of kind: `flow[0] -> flow[1] -> ... -> flow[n]`, where
+`flow[i].slice_out = flow[i+1].slice_in` and `flow[0].slice_out = start_slice_id
+OR start_slice_id = flow[n].slice_in`.
-`CONNECTED_FLOW(start_slice_id)` - contains a union of both
-`FOLLOWING_FLOW(start_slice_id)` and `PRECEDING_FLOW(start_slice_id)` tables.
+NOTE: Unlike the following/preceding flow functions, this function will not
+include flows connected to ancestors or descendants while searching for flows
+from a slice. It only includes the slices in the directly connected chain.
+
+`FOLLOWING_FLOW(start_slice_id)` - contains all flows which can be reached from
+a given slice via recursively following from flow's outgoing slice to its
+incoming one and from a reached slice to its child. The return table contains
+all entries of [flow table](/docs/analysis/sql-tables.autogen#flow) that are
+present in any chain of kind: `flow[0] -> flow[1] -> ... -> flow[n]`, where
+`flow[i+1].slice_out IN DESCENDANT_SLICE(flow[i].slice_in) OR
+flow[i+1].slice_out = flow[i].slice_in` and `flow[0].slice_out IN
+DESCENDANT_SLICE(start_slice_id) OR flow[0].slice_out = start_slice_id`.
+
+`PRECEDING_FLOW(start_slice_id)` - contains all flows which can be reached from
+a given slice via recursively following from flow's incoming slice to its
+outgoing one and from a reached slice to its parent. The return table contains
+all entries of [flow table](/docs/analysis/sql-tables.autogen#flow) that are
+present in any chain of kind: `flow[n] -> flow[n-1] -> ... -> flow[0]`, where
+`flow[i].slice_in IN ANCESTOR_SLICE(flow[i+1].slice_out) OR flow[i].slice_in =
+flow[i+1].slice_out` and `flow[0].slice_in IN ANCESTOR_SLICE(start_slice_id) OR
+flow[0].slice_in = start_slice_id`.
```sql
--number of following flows for each slice