docs: Add minimal example for SDK flows.
Reported-at: https://github.com/google/perfetto/issues/483
Change-Id: I660efeb3e5844f642209b494acd29be1c77e59cb
diff --git a/docs/images/flows.png b/docs/images/flows.png
new file mode 100644
index 0000000..7948713
--- /dev/null
+++ b/docs/images/flows.png
Binary files differ
diff --git a/docs/instrumentation/track-events.md b/docs/instrumentation/track-events.md
index 37f7796..9758bc7 100644
--- a/docs/instrumentation/track-events.md
+++ b/docs/instrumentation/track-events.md
@@ -554,6 +554,33 @@
perfetto::TrackEvent::EraseTrackDescriptor(track);
```
+### Flows
+
+Flows can be used to link two (or more) events (slices or instants), to mark
+them as related.
+
+The link is displayed as an arrow in the UI, when one of the events is selected:
+
+![A flow between two slices in the Perfetto UI](
+ /docs/images/flows.png "A flow between two slices in the Perfetto UI")
+
+```C++
+// The same identifier is used in both the related slices.
+uint64_t request_id = GetRequestId();
+
+{
+ TRACE_EVENT("rendering", "HandleRequestPhase1",
+ perfetto::Flow::ProcessScoped(request_id));
+ //...
+}
+
+std::thread t1([&] {
+ TRACE_EVENT("rendering", "HandleRequestPhase2",
+ perfetto::TerminatingFlow::ProcessScoped(request_id));
+ //...
+});
+```
+
### Counters
Time-varying numeric data can be recorded with the `TRACE_COUNTER` macro: