Conditionally enable the Perfetto platform profiler

PiperOrigin-RevId: 457671230
diff --git a/tensorflow/lite/profiling/BUILD b/tensorflow/lite/profiling/BUILD
index 124d76d..6860268 100644
--- a/tensorflow/lite/profiling/BUILD
+++ b/tensorflow/lite/profiling/BUILD
@@ -1,7 +1,12 @@
+load("//tensorflow:tensorflow.bzl", "clean_dep")
 load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable")
 load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings")
 load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite_combined")
 
+# copybara:uncomment_begin(google-only)
+# load("//tensorflow/lite/experimental/perfetto_profiling:build_def.bzl", "tflite_perfetto_copts")
+# copybara:uncomment_end
+
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],
@@ -68,10 +73,19 @@
     srcs = ["platform_profiler.cc"],
     hdrs = ["platform_profiler.h"],
     compatible_with = get_compatible_with_portable(),
-    copts = common_copts,
+    copts =
+        # copybara:uncomment_begin(google-only)
+        # tflite_perfetto_copts() +
+        # copybara:uncomment_end
+        common_copts,
     deps = [
         "//tensorflow/lite/core/api",
     ] + select({
+        # copybara:uncomment_begin(google-only)
+        # clean_dep("//tensorflow/lite/experimental/perfetto_profiling:enable_tflite_perfetto_profiler_explicit_true"): [
+        # "//tensorflow/lite/experimental/perfetto_profiling:perfetto_profiler",
+        # ],
+        # copybara:uncomment_end
         "//tensorflow:android": [":atrace_profiler"],
         "//tensorflow:ios": [":signpost_profiler"],
         "//conditions:default": [],
diff --git a/tensorflow/lite/profiling/platform_profiler.cc b/tensorflow/lite/profiling/platform_profiler.cc
index 788c527..acaef4b 100644
--- a/tensorflow/lite/profiling/platform_profiler.cc
+++ b/tensorflow/lite/profiling/platform_profiler.cc
@@ -26,6 +26,8 @@
 #define SIGNPOST_PLATFORM_PROFILER
 #include "tensorflow/lite/profiling/signpost_profiler.h"
 #endif
+#elif defined(ENABLE_TFLITE_PERFETTO_PROFILER)
+#include "tensorflow/lite/experimental/perfetto_profiling/perfetto_profiler.h"
 #endif
 
 namespace tflite {
@@ -36,6 +38,8 @@
   return MaybeCreateATraceProfiler();
 #elif defined(SIGNPOST_PLATFORM_PROFILER)
   return MaybeCreateSignpostProfiler();
+#elif defined(ENABLE_TFLITE_PERFETTO_PROFILER)
+  return std::make_unique<tflite::profiling::PerfettoProfiler>();
 #else
   return nullptr;
 #endif