tracing: Add interceptor support

This patch introduces the concept of interceptors to the tracing SDK.
Interceptors make it possible to divert tracing data (i.e., serialized
trace packets) generated by a data source into a custom sink instead
of the central tracing service. Potential use cases include:

  * Logging trace events to the console in real time.

  * Exporting trace events to Android ATrace.

  * Exporting trace events to Windows ETW.

Intercepting works by creating special heap-backed trace writers for
each data source that is being intercepted. The serialized data is
passed in real time to the interceptor at the end of each trace point.

Interceptors are enabled through a new field in the trace config:

data_sources: {
    config {
        name: "track_event"
        interceptor_config: {
            name: "console"
        }
    }
}

Design doc: https://docs.google.com/document/d/1zIBGz7LvaucSb9B7UUWF24gDi6i3XFTGiuTi5Nf1czo

Bug: 170628040
Change-Id: I776f9bb5e99a37155619ea20c56df339131db813
diff --git a/BUILD b/BUILD
index 7f6993c..7f04bc9 100644
--- a/BUILD
+++ b/BUILD
@@ -510,9 +510,11 @@
         "include/perfetto/tracing/data_source.h",
         "include/perfetto/tracing/debug_annotation.h",
         "include/perfetto/tracing/event_context.h",
+        "include/perfetto/tracing/interceptor.h",
         "include/perfetto/tracing/internal/basic_types.h",
         "include/perfetto/tracing/internal/data_source_internal.h",
         "include/perfetto/tracing/internal/in_process_tracing_backend.h",
+        "include/perfetto/tracing/internal/interceptor_trace_writer.h",
         "include/perfetto/tracing/internal/system_tracing_backend.h",
         "include/perfetto/tracing/internal/tracing_muxer.h",
         "include/perfetto/tracing/internal/tracing_tls.h",
@@ -1525,6 +1527,8 @@
         "src/tracing/data_source.cc",
         "src/tracing/debug_annotation.cc",
         "src/tracing/event_context.cc",
+        "src/tracing/interceptor.cc",
+        "src/tracing/internal/interceptor_trace_writer.cc",
         "src/tracing/internal/tracing_muxer_impl.cc",
         "src/tracing/internal/tracing_muxer_impl.h",
         "src/tracing/internal/track_event_internal.cc",
@@ -1647,6 +1651,7 @@
         "protos/perfetto/common/data_source_descriptor.proto",
         "protos/perfetto/common/descriptor.proto",
         "protos/perfetto/common/gpu_counter_descriptor.proto",
+        "protos/perfetto/common/interceptor_descriptor.proto",
         "protos/perfetto/common/observable_events.proto",
         "protos/perfetto/common/sys_stats_counters.proto",
         "protos/perfetto/common/trace_stats.proto",
@@ -1981,6 +1986,7 @@
     srcs = [
         "protos/perfetto/config/chrome/chrome_config.proto",
         "protos/perfetto/config/data_source_config.proto",
+        "protos/perfetto/config/interceptor_config.proto",
         "protos/perfetto/config/stress_test_config.proto",
         "protos/perfetto/config/test_config.proto",
         "protos/perfetto/config/trace_config.proto",