Merge "tp: add metatracing of individual queries"
diff --git a/Android.bp b/Android.bp
index 7307710..9d91a4e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -24,6 +24,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_tracing_core_core",
         ":perfetto_include_perfetto_tracing_core_forward_decls",
         ":perfetto_include_perfetto_tracing_tracing",
@@ -188,6 +190,8 @@
     srcs: [
         ":perfetto_include_perfetto_base_base",
         ":perfetto_include_perfetto_ext_base_base",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_src_base_base",
         ":perfetto_src_profiling_memory_malloc_interceptor_bionic_hooks",
         ":perfetto_src_profiling_memory_wrap_allocators",
@@ -221,6 +225,8 @@
     srcs: [
         ":perfetto_include_perfetto_base_base",
         ":perfetto_include_perfetto_ext_base_base",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_src_base_base",
         ":perfetto_src_base_unix_socket",
         ":perfetto_src_profiling_memory_client",
@@ -274,6 +280,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_tracing_core_core",
         ":perfetto_include_perfetto_tracing_core_forward_decls",
         ":perfetto_include_perfetto_tracing_tracing",
@@ -431,6 +439,8 @@
     srcs: [
         ":perfetto_include_perfetto_base_base",
         ":perfetto_include_perfetto_ext_base_base",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_src_base_base",
         "src/ipc/protoc_plugin/ipc_plugin.cc",
     ],
@@ -461,6 +471,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_tracing_core_core",
         ":perfetto_include_perfetto_tracing_core_forward_decls",
         ":perfetto_include_perfetto_tracing_tracing",
@@ -662,6 +674,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_tracing_core_core",
         ":perfetto_include_perfetto_tracing_core_forward_decls",
         ":perfetto_include_perfetto_tracing_tracing",
@@ -860,6 +874,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_tracing_core_core",
         ":perfetto_include_perfetto_tracing_core_forward_decls",
         ":perfetto_include_perfetto_tracing_tracing",
@@ -1000,6 +1016,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_tracing_core_core",
         ":perfetto_include_perfetto_tracing_core_forward_decls",
         ":perfetto_include_perfetto_tracing_tracing",
@@ -1260,6 +1278,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_tracing_core_core",
         ":perfetto_include_perfetto_tracing_core_forward_decls",
         ":perfetto_include_perfetto_tracing_tracing",
@@ -1604,6 +1624,16 @@
     name: "perfetto_include_perfetto_protozero_protozero",
 }
 
+// GN: //include/perfetto/public/abi:base
+filegroup {
+    name: "perfetto_include_perfetto_public_abi_base",
+}
+
+// GN: //include/perfetto/public:base
+filegroup {
+    name: "perfetto_include_perfetto_public_base",
+}
+
 // GN: //include/perfetto/test:test_support
 filegroup {
     name: "perfetto_include_perfetto_test_test_support",
@@ -1653,6 +1683,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_test_test_support",
         ":perfetto_include_perfetto_trace_processor_basic_types",
         ":perfetto_include_perfetto_trace_processor_storage",
@@ -7967,6 +7999,8 @@
     srcs: [
         ":perfetto_include_perfetto_base_base",
         ":perfetto_include_perfetto_ext_base_base",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_src_base_base",
         "src/protozero/protoc_plugin/cppgen_plugin.cc",
     ],
@@ -8252,6 +8286,8 @@
         ":perfetto_include_perfetto_base_base",
         ":perfetto_include_perfetto_ext_base_base",
         ":perfetto_include_perfetto_ext_trace_processor_demangle",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         "src/trace_processor/demangle.cc",
     ],
     host_supported: true,
@@ -9909,6 +9945,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_test_test_support",
         ":perfetto_include_perfetto_trace_processor_basic_types",
         ":perfetto_include_perfetto_trace_processor_storage",
@@ -10314,6 +10352,8 @@
     srcs: [
         ":perfetto_include_perfetto_base_base",
         ":perfetto_include_perfetto_ext_base_base",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_src_base_base",
         "src/protozero/protoc_plugin/protozero_plugin.cc",
     ],
@@ -10343,6 +10383,8 @@
         ":perfetto_include_perfetto_ext_trace_processor_importers_memory_tracker_memory_tracker",
         ":perfetto_include_perfetto_ext_traced_sys_stats_counters",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_trace_processor_basic_types",
         ":perfetto_include_perfetto_trace_processor_storage",
         ":perfetto_include_perfetto_trace_processor_trace_processor",
@@ -10508,6 +10550,8 @@
         ":perfetto_include_perfetto_ext_traced_sys_stats_counters",
         ":perfetto_include_perfetto_profiling_pprof_builder",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_trace_processor_basic_types",
         ":perfetto_include_perfetto_trace_processor_storage",
         ":perfetto_include_perfetto_trace_processor_trace_processor",
@@ -10663,6 +10707,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_tracing_core_core",
         ":perfetto_include_perfetto_tracing_core_forward_decls",
         ":perfetto_include_perfetto_tracing_tracing",
@@ -10844,6 +10890,8 @@
         ":perfetto_include_perfetto_ext_tracing_core_core",
         ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
         ":perfetto_include_perfetto_protozero_protozero",
+        ":perfetto_include_perfetto_public_abi_base",
+        ":perfetto_include_perfetto_public_base",
         ":perfetto_include_perfetto_tracing_core_core",
         ":perfetto_include_perfetto_tracing_core_forward_decls",
         ":perfetto_include_perfetto_tracing_tracing",
diff --git a/BUILD b/BUILD
index a87b2dd..0c50584 100644
--- a/BUILD
+++ b/BUILD
@@ -70,6 +70,8 @@
         ":include_perfetto_ext_base_base",
         ":include_perfetto_ext_ipc_ipc",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
     ],
     deps = [
         ":protos_perfetto_ipc_wire_protocol_cpp",
@@ -120,6 +122,8 @@
     hdrs = [
         ":include_perfetto_base_base",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
     ],
     deps = [
         ":src_base_base",
@@ -169,6 +173,8 @@
     srcs = [
         ":include_perfetto_base_base",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
         ":include_perfetto_tracing_core_forward_decls",
         ":include_perfetto_tracing_tracing",
         "test/client_api_example.cc",
@@ -256,6 +262,8 @@
         ":include_perfetto_ext_tracing_core_core",
         ":include_perfetto_ext_tracing_ipc_ipc",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
         ":include_perfetto_tracing_core_core",
         ":include_perfetto_tracing_core_forward_decls",
         ":include_perfetto_tracing_tracing",
@@ -515,6 +523,22 @@
     ],
 )
 
+# GN target: //include/perfetto/public/abi:base
+perfetto_filegroup(
+    name = "include_perfetto_public_abi_base",
+    srcs = [
+        "include/perfetto/public/abi/export.h",
+    ],
+)
+
+# GN target: //include/perfetto/public:base
+perfetto_filegroup(
+    name = "include_perfetto_public_base",
+    srcs = [
+        "include/perfetto/public/compiler.h",
+    ],
+)
+
 # GN target: //include/perfetto/trace_processor:basic_types
 perfetto_filegroup(
     name = "include_perfetto_trace_processor_basic_types",
@@ -662,6 +686,8 @@
         ":include_perfetto_base_base",
         ":include_perfetto_ext_base_base",
         ":include_perfetto_ext_base_http_http",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
     ],
     deps = [
         ":src_base_base",
@@ -709,6 +735,8 @@
     hdrs = [
         ":include_perfetto_base_base",
         ":include_perfetto_ext_base_base",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
     ],
     deps = [
     ] + PERFETTO_CONFIG.deps.version_header,
@@ -724,6 +752,8 @@
     hdrs = [
         ":include_perfetto_base_base",
         ":include_perfetto_ext_base_base",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
     ],
     linkstatic = True,
 )
@@ -935,6 +965,8 @@
     hdrs = [
         ":include_perfetto_base_base",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
         "src/trace_processor/containers/bit_vector.h",
         "src/trace_processor/containers/bit_vector_iterators.h",
         "src/trace_processor/containers/null_term_string_view.h",
@@ -1430,6 +1462,8 @@
         ":include_perfetto_base_base",
         ":include_perfetto_ext_base_base",
         ":include_perfetto_ext_trace_processor_demangle",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
     ],
     deps = [
     ] + PERFETTO_CONFIG.deps.llvm_demangle,
@@ -3637,6 +3671,8 @@
         ":include_perfetto_ext_tracing_core_core",
         ":include_perfetto_ext_tracing_ipc_ipc",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
         ":include_perfetto_tracing_core_core",
         ":include_perfetto_tracing_core_forward_decls",
         ":include_perfetto_tracing_tracing",
@@ -3707,6 +3743,8 @@
         ":include_perfetto_ext_tracing_core_core",
         ":include_perfetto_ext_tracing_ipc_ipc",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
         ":include_perfetto_tracing_core_core",
         ":include_perfetto_tracing_core_forward_decls",
         ":include_perfetto_tracing_tracing",
@@ -3814,6 +3852,8 @@
         ":include_perfetto_ext_trace_processor_export_json",
         ":include_perfetto_ext_trace_processor_importers_memory_tracker_memory_tracker",
         ":include_perfetto_ext_traced_sys_stats_counters",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
         ":include_perfetto_trace_processor_basic_types",
         ":include_perfetto_trace_processor_storage",
         ":include_perfetto_trace_processor_trace_processor",
@@ -3880,6 +3920,8 @@
         ":include_perfetto_ext_trace_processor_importers_memory_tracker_memory_tracker",
         ":include_perfetto_ext_traced_sys_stats_counters",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
         ":include_perfetto_trace_processor_basic_types",
         ":include_perfetto_trace_processor_storage",
         ":include_perfetto_trace_processor_trace_processor",
@@ -3988,6 +4030,8 @@
         ":include_perfetto_ext_base_base",
         ":include_perfetto_profiling_pprof_builder",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
         ":include_perfetto_trace_processor_basic_types",
         ":include_perfetto_trace_processor_storage",
         ":include_perfetto_trace_processor_trace_processor",
@@ -4042,6 +4086,8 @@
         ":include_perfetto_ext_traced_sys_stats_counters",
         ":include_perfetto_profiling_pprof_builder",
         ":include_perfetto_protozero_protozero",
+        ":include_perfetto_public_abi_base",
+        ":include_perfetto_public_base",
         ":include_perfetto_trace_processor_basic_types",
         ":include_perfetto_trace_processor_storage",
         ":include_perfetto_trace_processor_trace_processor",
diff --git a/CHANGELOG b/CHANGELOG
index db4ed93..ef536b9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,24 +1,61 @@
 Unreleased:
   Tracing service and probes:
+    *
+  Trace Processor:
+    *
+  UI:
+    *
+  SDK:
+    *
+
+
+v26.0 - 2022-06-13:
+  Tracing service and probes:
     * Added wildcard (*) support when targeting processes by their command line
       in the Android perf profiler ("linux.perf" data source) and Java heap
       snapshots ("android.java_hprof").
     * Added support for kernel thread sampling, and kernel-only callstacks in
       the Android perf profiler.
+    * Fixed rare crash when parsing zero-length ftrace __data_loc strings.
+    * Fixed rare crash on 4.19 kernel when encountering unexpected zero-padded
+      ftrace pages.
+    * Removed capturing of thread_time_in_state (per-UID, per-OOM-adj time).
+      The data was unused and subsumed by correlating sched data with power
+      rail monitors.
   Trace Processor:
+    * Added CREATE_VIEW_FUNCTION operator to define a SQL function that can
+      return a temporary table and yield multiple rows and columns.
     * Changed kernel threads to be represented as single-thread processes in
       Linux system traces. The (incorrect) legacy behaviour was to treat them
       as threads of the kthreadd process.
     * Added ABS_TIME_STR function which converts a trace timestamp to
       an ISO8601 string.
+    * Added ingestion for phase='R' events, used by performance.{now,mark}().
     * Changed 'trace_to_text' to be named 'traceconv'. The source
       location also moved from 'tools/trace_to_text' to 'src/traceconv'.
     * Changed compiler flags, added -mavx2. The previous patch in v22.0 was
       supposed to add AVX2 support but added only AVX.
+    * Changed the handling of the last per-cpu sched slices: rather than
+      extending the last event to the end of the trace, the last scheduling
+      event has a -1 duration. UIs are supposed to deal with visual extension.
+    * Removed android_thread_time_in_state metric. It was an experiment and was
+      unused.
+    * Removed `instant` table. All instant events are now 0-duration events in
+      the `slice` table.
+    * Removed the /raw_query REST endpoint from --httpd. This will break very
+      old clients that have not switched over the new streaming-based /query
+      endoint or even newer /websocket.
   UI:
-    *
+    * Changed detail panel to separate slice args from generic slice properties.
+    * Automatically enabled sched_compact when generating trace configs for 
+      Android S+ targets.
   SDK:
-    *
+    * Added option for recording thread CPU times at the beginning and end of
+      each slice.
+    * Added perfetto::DynamicString() to use non-literal strings as event names
+      in the TRACE_EVENT API.
+    * Remove the pre-SDK consumer_api_deprecated interface. It was introduced
+      for iorapd, now deleted from the Android tree.
 
 
 v25.0 - 2022-04-01:
diff --git a/docs/design-docs/api-and-abi.md b/docs/design-docs/api-and-abi.md
index e24624a..c930c95 100644
--- a/docs/design-docs/api-and-abi.md
+++ b/docs/design-docs/api-and-abi.md
@@ -10,6 +10,8 @@
   occasionally break at compile-time throughout 2020.
 * The C++ API within `include/perfetto/ext/` is internal-only and exposed only
   for Chromium.
+* A new C API/ABI for a tracing shared library is in the works in
+  `include/perfetto/public`. It is not stable yet.
 * The tracing protocol ABI is based on protobuf-over-UNIX-socket and shared
   memory. It is long-term stable and maintains compatibility in both directions
   (old service + newer client and vice-versa).
@@ -486,16 +488,17 @@
 
 ## Static linking vs shared library
 
-The Perfetto Client Library is only available in the form of a static library
-and a single-source amalgamated SDK (which is effectively a static library).
-The library implements the Tracing Protocol ABI so, once statically linked,
-depends only on the socket and shared memory protocol ABI, which are guaranteed
-to be stable.
+The Perfetto C++ Client Library is only available in the form of a static
+library and a single-source amalgamated SDK (which is effectively a static
+library). The library implements the Tracing Protocol ABI so, once statically
+linked, depends only on the socket and shared memory protocol ABI, which are
+guaranteed to be stable.
 
-No shared library distributions are available. We strongly discourage teams from
-attempting to build the tracing library as shared library and use it from a
-different linker unit. It is fine to link AND use the client library within
-the same shared library, as long as none of the perfetto C++ API is exported.
+No shared library distributions for the C++ are available. We strongly
+discourage teams from attempting to build the C++ tracing library as shared
+library and use it from a different linker unit. It is fine to link AND use the
+client library within the same shared library, as long as none of the perfetto
+C++ API is exported.
 
 The `PERFETTO_EXPORT_COMPONENT` annotations are only used when building the
 third tier of the client library in chromium component builds and cannot be
@@ -511,6 +514,8 @@
 ways. For this reason the team has ruled out shared library distributions for
 the time being.
 
+A new C Client library API/ABI is in the works, but it's not stable yet.
+
 [cli_lib]: /docs/instrumentation/tracing-sdk.md
 [selinux_producer]: https://cs.android.com/search?q=perfetto_producer%20f:sepolicy.*%5C.te&sq=
 [selinux_consumer]:https://cs.android.com/search?q=f:sepolicy%2F.*%5C.te%20traced_consumer&sq=
diff --git a/include/README.md b/include/README.md
index 3be92c4..fc2e788 100644
--- a/include/README.md
+++ b/include/README.md
@@ -3,13 +3,13 @@
 **This API surface is not stable yet, don't depend on it**
 
 This folder contains the public perfetto API headers. This allows an app to
-inject trace events into perfetto with ~10 lines of code (see
-api_usage_example.cc).
+inject trace events into perfetto with ~10 lines of code (see examples in
+examples/sdk/).
 
 The ext/ subdirectory expose the API-unstable classes and types that are
 exposed to emvbedders that have exceptional requirements in terms of interposing
 their own custom IPC layer. To the day the only case is chromium. Nothing else
-should depend on ext/. Contact perfetto-dev@ if you think you need to 
+should depend on ext/. Contact perfetto-dev@ if you think you need to
 depend on an ext/ header.
 
 Headers in this folder must be hermetic. No ext/ perfetto header must be
@@ -21,7 +21,7 @@
 Source code layout: what goes where?
 ------------------------------------
 
-**include/perfetto (this folder):**
+**include/perfetto:**
 Embedders are allowed to access and depend on any folder of this but ext/.
 This contains classes to: (i) use tracing; (ii) extend the tracing internals
 (i.e. implement the Platform).
@@ -59,6 +59,20 @@
   library can only be statically linked) but we guarantee source-level
   compatibility and ABI of the UNIX socket and shared memory buffers.
 
+**include/perfetto/public:**
+This contains headers that can be used when dynamic linking with the perfetto
+shared library.
+
+These headers are not supposed to be exposed as part of the shared library ABI.
+
+All symbols, macros and types here start with the `perfetto_` or `PERFETTO_`
+prefix. These prefixes are reserved by perfetto and should not be used elsewhere
+when linking with the perfetto shared library.
+
+**include/perfetto/public/abi:**
+Subset of headers that are part of the shared library ABI (**not stable yet**).
+These headers are supposed to be hermetic (i.e. they should not include anything
+outside the abi directory).
 
 Usage example
 -------------
diff --git a/include/perfetto/base/BUILD.gn b/include/perfetto/base/BUILD.gn
index 031d7b0..357f89a 100644
--- a/include/perfetto/base/BUILD.gn
+++ b/include/perfetto/base/BUILD.gn
@@ -29,4 +29,5 @@
     "thread_utils.h",
     "time.h",
   ]
+  public_deps = [ "../public:base" ]
 }
diff --git a/include/perfetto/base/build_config.h b/include/perfetto/base/build_config.h
index bd3623f..5002529 100644
--- a/include/perfetto/base/build_config.h
+++ b/include/perfetto/base/build_config.h
@@ -137,7 +137,7 @@
 //   default cflags add this path to the default include path.
 // - Similarly, in bazel builds, this file is generated by tools/gen_bazel and
 //   checked in into include/perfetto/base/build_configs/bazel/.
-// - In amaglamated builds, this file is generated by tools/gen_amalgamated and
+// - In amalgamated builds, this file is generated by tools/gen_amalgamated and
 //   added to the amalgamated headers.
 #include "perfetto_build_flags.h"  // no-include-violation-check
 
diff --git a/include/perfetto/base/compiler.h b/include/perfetto/base/compiler.h
index 8ad8943..e95b676 100644
--- a/include/perfetto/base/compiler.h
+++ b/include/perfetto/base/compiler.h
@@ -21,6 +21,7 @@
 #include <type_traits>
 
 #include "perfetto/base/build_config.h"
+#include "perfetto/public/compiler.h"
 
 // __has_attribute is supported only by clang and recent versions of GCC.
 // Add a layer to wrap the __has_attribute macro.
@@ -31,14 +32,6 @@
 #endif
 
 #if defined(__GNUC__) || defined(__clang__)
-#define PERFETTO_LIKELY(_x) __builtin_expect(!!(_x), 1)
-#define PERFETTO_UNLIKELY(_x) __builtin_expect(!!(_x), 0)
-#else
-#define PERFETTO_LIKELY(_x) (_x)
-#define PERFETTO_UNLIKELY(_x) (_x)
-#endif
-
-#if defined(__GNUC__) || defined(__clang__)
 #define PERFETTO_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
 #else
 #define PERFETTO_WARN_UNUSED_RESULT
diff --git a/include/perfetto/base/export.h b/include/perfetto/base/export.h
index 53c4eeb..019aaa5 100644
--- a/include/perfetto/base/export.h
+++ b/include/perfetto/base/export.h
@@ -18,14 +18,7 @@
 #define INCLUDE_PERFETTO_BASE_EXPORT_H_
 
 #include "perfetto/base/build_config.h"
-
-#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
-#define PERFETTO_INTERNAL_DLL_EXPORT __declspec(dllexport)
-#define PERFETTO_INTERNAL_DLL_IMPORT __declspec(dllimport)
-#else
-#define PERFETTO_INTERNAL_DLL_EXPORT __attribute__((visibility("default")))
-#define PERFETTO_INTERNAL_DLL_IMPORT
-#endif
+#include "perfetto/public/abi/export.h"
 
 // PERFETTO_EXPORT_COMPONENT: Exports a symbol among C++ components when
 // building with is_component = true (mostly used by chromium build).
diff --git a/include/perfetto/public/BUILD.gn b/include/perfetto/public/BUILD.gn
new file mode 100644
index 0000000..5f01d93
--- /dev/null
+++ b/include/perfetto/public/BUILD.gn
@@ -0,0 +1,20 @@
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+source_set("base") {
+  sources = [
+    "compiler.h",
+  ]
+  public_deps = [ "./abi:base" ]
+}
diff --git a/include/perfetto/public/abi/BUILD.gn b/include/perfetto/public/abi/BUILD.gn
new file mode 100644
index 0000000..398fa35
--- /dev/null
+++ b/include/perfetto/public/abi/BUILD.gn
@@ -0,0 +1,19 @@
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+source_set("base") {
+  sources = [
+    "export.h",
+  ]
+}
diff --git a/include/perfetto/public/abi/export.h b/include/perfetto/public/abi/export.h
new file mode 100644
index 0000000..d11f5a2
--- /dev/null
+++ b/include/perfetto/public/abi/export.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INCLUDE_PERFETTO_PUBLIC_ABI_EXPORT_H_
+#define INCLUDE_PERFETTO_PUBLIC_ABI_EXPORT_H_
+
+#ifdef _WIN32
+#define PERFETTO_INTERNAL_DLL_EXPORT __declspec(dllexport)
+#define PERFETTO_INTERNAL_DLL_IMPORT __declspec(dllimport)
+#else
+#define PERFETTO_INTERNAL_DLL_EXPORT __attribute__((visibility("default")))
+#define PERFETTO_INTERNAL_DLL_IMPORT
+#endif
+
+// PERFETTO_SDK_EXPORT: Exports a symbol from the perfetto SDK shared library.
+#if defined(PERFETTO_IMPLEMENTATION)
+#define PERFETTO_SDK_EXPORT PERFETTO_INTERNAL_DLL_EXPORT
+#else
+#define PERFETTO_SDK_EXPORT PERFETTO_INTERNAL_DLL_IMPORT
+#endif
+
+#endif  // INCLUDE_PERFETTO_PUBLIC_ABI_EXPORT_H_
diff --git a/include/perfetto/public/compiler.h b/include/perfetto/public/compiler.h
new file mode 100644
index 0000000..79acdfe
--- /dev/null
+++ b/include/perfetto/public/compiler.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INCLUDE_PERFETTO_PUBLIC_COMPILER_H_
+#define INCLUDE_PERFETTO_PUBLIC_COMPILER_H_
+
+#if defined(__GNUC__) || defined(__clang__)
+#define PERFETTO_LIKELY(_x) __builtin_expect(!!(_x), 1)
+#define PERFETTO_UNLIKELY(_x) __builtin_expect(!!(_x), 0)
+#else
+#define PERFETTO_LIKELY(_x) (_x)
+#define PERFETTO_UNLIKELY(_x) (_x)
+#endif
+
+#endif  // INCLUDE_PERFETTO_PUBLIC_COMPILER_H_
diff --git a/src/trace_processor/metrics/sql/android/composer_execution.sql b/src/trace_processor/metrics/sql/android/composer_execution.sql
index bec4fdc..448b0f8 100644
--- a/src/trace_processor/metrics/sql/android/composer_execution.sql
+++ b/src/trace_processor/metrics/sql/android/composer_execution.sql
@@ -16,9 +16,9 @@
 
 -- The HWC execution time will be calculated based on the runtime of
 -- HwcPresentOrValidateDisplay, HwcValidateDisplay, and/or HwcPresentDisplay
--- which are happened in the same onMessageRefresh.
+-- which are happened in the same onMessageRefresh/composite.
 -- There are 3 possible combinations how those functions will be called in
--- a single onMessageRefresh, i.e.:
+-- a single onMessageRefresh/composite, i.e.:
 -- 1. HwcPresentOrValidateDisplay and then HwcPresentDisplay
 -- 2. HwcPresentOrValidateDisplay
 -- 3. HwcValidateDisplay and then HwcPresentDisplay
@@ -38,7 +38,7 @@
   LEAD(dur, 2, 0) OVER (PARTITION BY track_id ORDER BY ts) AS second_next_dur
 FROM slice
 WHERE name = 'HwcPresentOrValidateDisplay' OR name = 'HwcValidateDisplay'
-  OR name = 'HwcPresentDisplay' OR name = 'onMessageRefresh'
+  OR name = 'HwcPresentDisplay' OR name = 'onMessageRefresh' OR name GLOB 'composite *'
 ORDER BY ts;
 
 DROP VIEW IF EXISTS {{output}};
@@ -64,4 +64,4 @@
     ELSE 'unknown'
   END AS validation_type
 FROM raw_hwc_function_spans
-WHERE name = 'onMessageRefresh' AND dur > 0;
+WHERE (name = 'onMessageRefresh' OR name GLOB 'composite *') AND dur > 0;
diff --git a/test/trace_processor/graphics/composer_execution.py b/test/trace_processor/graphics/composer_execution.py
index 7ff5524..cdf6cd6 100644
--- a/test/trace_processor/graphics/composer_execution.py
+++ b/test/trace_processor/graphics/composer_execution.py
@@ -37,13 +37,13 @@
 trace.add_atrace_end(ts=600, tid=10335, pid=10335)
 
 # skipped validation
-trace.add_atrace_begin(ts=1_100, tid=10335, pid=10335, buf="onMessageRefresh")
+trace.add_atrace_begin(ts=1_100, tid=10335, pid=10335, buf="composite 2")
 trace.add_atrace_begin(ts=1_200, tid=10335, pid=10335, buf="HwcPresentOrValidateDisplay")
 trace.add_atrace_end(ts=1_300, tid=10335, pid=10335)
 trace.add_atrace_end(ts=1_400, tid=10335, pid=10335)
 
 # separated validation
-trace.add_atrace_begin(ts=2_100, tid=10335, pid=10335, buf="onMessageRefresh")
+trace.add_atrace_begin(ts=2_100, tid=10335, pid=10335, buf="composite 3")
 trace.add_atrace_begin(ts=2_200, tid=10335, pid=10335, buf="otherFunction")
 trace.add_atrace_begin(ts=2_300, tid=10335, pid=10335, buf="HwcValidateDisplay")
 trace.add_atrace_end(ts=2_400, tid=10335, pid=10335)