Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/cvd/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bazel_dep(name = "nasm", version = "2.16.03.bcr.1")
bazel_dep(name = "pcre2", version = "10.45")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "protobuf", version = "31.1")
bazel_dep(name = "re2")
bazel_dep(name = "rootcanal")
bazel_dep(name = "rules_cc", version = "0.2.16")
bazel_dep(name = "rules_flex", version = "0.4")
Expand Down
1 change: 1 addition & 0 deletions base/cvd/build_external/build_external.MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ include("//build_external/mkbootimg:mkbootimg.MODULE.bazel")
include("//build_external/ms-tpm-20-ref:ms-tpm-20-ref.MODULE.bazel")
include("//build_external/mtools:mtools.MODULE.bazel")
include("//build_external/opengl_headers:opengl_headers.MODULE.bazel")
include("//build_external/perfetto:perfetto.MODULE.bazel")
include("//build_external/pyyaml:pyyaml.MODULE.bazel")
include("//build_external/re2:re2.MODULE.bazel")
include("//build_external/rootcanal:rootcanal.MODULE.bazel")
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
From 45c2b6299505b133fdce117649f457e36640d824 Mon Sep 17 00:00:00 2001
From: Jason Macnak <natsu@google.com>
Date: Fri, 15 May 2026 11:28:54 -0700
Subject: [PATCH 1/4] Disable Android components to avoid extra dependencies

---
bazel/rules.bzl | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/bazel/rules.bzl b/bazel/rules.bzl
index 6195465a67..a3e367cde8 100644
--- a/bazel/rules.bzl
+++ b/bazel/rules.bzl
@@ -13,9 +13,7 @@
# limitations under the License.

load("@perfetto//bazel:proto_gen.bzl", "proto_descriptor_gen", "proto_gen")
-load("@perfetto//bazel:run_ait_with_adb.bzl", "android_instrumentation_test")
load("@perfetto_cfg//:perfetto_cfg.bzl", "PERFETTO_CONFIG")
-load("@rules_android//android:rules.bzl", "android_binary", "android_library")

# +----------------------------------------------------------------------------+
# | Base C++ rules. |
@@ -113,11 +111,11 @@ def perfetto_jspb_proto_library(**kwargs):
# +----------------------------------------------------------------------------+
def perfetto_android_binary(**kwargs):
if not _rule_override("android_binary", **kwargs):
- android_binary(**kwargs)
+ return

def perfetto_android_library(**kwargs):
if not _rule_override("android_library", **kwargs):
- android_library(**kwargs)
+ return

def perfetto_android_jni_library(**kwargs):
if not _rule_override("android_jni_library", **kwargs):
@@ -171,7 +169,7 @@ def _perfetto_android_jni_library(

def perfetto_android_instrumentation_test(**kwargs):
if not _rule_override("android_instrumentation_test", **kwargs):
- android_instrumentation_test(**kwargs)
+ return

# +----------------------------------------------------------------------------+
# | Misc rules. |
--
2.54.0.563.g4f69b47b94-goog

131 changes: 131 additions & 0 deletions base/cvd/build_external/perfetto/PATCH.0002_add_load_statements.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
From 5e991031fa757ade8a7be54e5bfab69ec627a432 Mon Sep 17 00:00:00 2001
From: Jason Macnak <natsu@google.com>
Date: Fri, 15 May 2026 11:29:26 -0700
Subject: [PATCH 2/4] Add load statements for Bazel 9

---
bazel/proto_gen.bzl | 2 ++
bazel/rules.bzl | 30 ++++++++++++++++++------------
2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/bazel/proto_gen.bzl b/bazel/proto_gen.bzl
index 74f91cad89..1764cb2d9a 100644
--- a/bazel/proto_gen.bzl
+++ b/bazel/proto_gen.bzl
@@ -15,6 +15,8 @@
# This file defines the proto_gen() rule that is used for generating protos
# with custom plugins (ipc and protozero).

+load("@protobuf//bazel/common:proto_info.bzl", "ProtoInfo")
+
def _proto_gen_impl(ctx):
proto_src = [
f
diff --git a/bazel/rules.bzl b/bazel/rules.bzl
index a3e367cde8..15f6d52d5b 100644
--- a/bazel/rules.bzl
+++ b/bazel/rules.bzl
@@ -14,6 +14,12 @@

load("@perfetto//bazel:proto_gen.bzl", "proto_descriptor_gen", "proto_gen")
load("@perfetto_cfg//:perfetto_cfg.bzl", "PERFETTO_CONFIG")
+load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
+load("@protobuf//bazel:proto_library.bzl", "proto_library")
+load("@protobuf//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
+load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+load("@rules_python//python:defs.bzl", "py_binary", "py_library")

# +----------------------------------------------------------------------------+
# | Base C++ rules. |
@@ -38,7 +44,7 @@ def default_cc_args():

def perfetto_build_config_cc_library(**kwargs):
if not _rule_override("cc_library", **kwargs):
- native.cc_library(**kwargs)
+ cc_library(**kwargs)

def perfetto_filegroup(**kwargs):
if not _rule_override("filegroup", **kwargs):
@@ -51,20 +57,20 @@ def perfetto_genrule(**kwargs):
def perfetto_cc_library(**kwargs):
args = _merge_dicts(default_cc_args(), kwargs)
if not _rule_override("cc_library", **args):
- native.cc_library(**args)
+ cc_library(**args)

def perfetto_cc_binary(**kwargs):
args = _merge_dicts(default_cc_args(), kwargs)
if not _rule_override("cc_binary", **args):
- native.cc_binary(**args)
+ cc_binary(**args)

def perfetto_py_binary(**kwargs):
if not _rule_override("py_binary", **kwargs):
- native.py_binary(**kwargs)
+ py_binary(**kwargs)

def perfetto_py_library(**kwargs):
if not _rule_override("py_library", **kwargs):
- native.py_library(**kwargs)
+ py_library(**kwargs)

# +----------------------------------------------------------------------------+
# | Proto-related rules |
@@ -72,11 +78,11 @@ def perfetto_py_library(**kwargs):

def perfetto_proto_library(**kwargs):
if not _rule_override("proto_library", **kwargs):
- native.proto_library(**kwargs)
+ proto_library(**kwargs)

def perfetto_cc_proto_library(**kwargs):
if not _rule_override("cc_proto_library", **kwargs):
- native.cc_proto_library(**kwargs)
+ cc_proto_library(**kwargs)

def perfetto_java_proto_library(**kwargs):
if not _rule_override("java_proto_library", **kwargs):
@@ -84,7 +90,7 @@ def perfetto_java_proto_library(**kwargs):

def perfetto_java_lite_proto_library(**kwargs):
if not _rule_override("java_lite_proto_library", **kwargs):
- native.java_lite_proto_library(**kwargs)
+ java_lite_proto_library(**kwargs)

# Unlike the other rules, this is an noop by default because Bazel does not
# support Go proto libraries.
@@ -142,7 +148,7 @@ def _perfetto_android_jni_library(
if not (binary_name.startswith("lib") and binary_name.endswith(".so")):
fail("'binary_name' should sharts with 'lib' and ends with '.so'" +
", got %s instead" % binary_name)
- # We strip the name, since `native.cc_binary` adds prefix and suffix
+ # We strip the name, since `cc_binary` adds prefix and suffix
# to the generated library name.
binary_target_name = binary_name.removeprefix("lib").removesuffix(".so")
input_cc_library_name = name + "_input"
@@ -150,18 +156,18 @@ def _perfetto_android_jni_library(
# exclude them from being build when invoke `bazel build :all`,
# since these targets won't be able to compile anyway, see
# https://bazel.build/docs/android-ndk#cclibrary-android.
- native.cc_library(
+ cc_library(
name = input_cc_library_name,
target_compatible_with = ["@platforms//os:android"],
**input_cc_library_kwargs
)
- native.cc_binary(
+ cc_binary(
name = binary_target_name,
linkshared = True,
deps = [input_cc_library_name],
target_compatible_with = ["@platforms//os:android"],
)
- native.cc_library(
+ cc_library(
name = name,
srcs = [binary_target_name],
target_compatible_with = ["@platforms//os:android"],
--
2.54.0.563.g4f69b47b94-goog

39 changes: 39 additions & 0 deletions base/cvd/build_external/perfetto/PATCH.0003_expose_shutdown.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 8ae64deaf5cb13bcdfb87d576b6d207a2fef13df Mon Sep 17 00:00:00 2001
From: Jason Macnak <natsu@google.com>
Date: Fri, 15 May 2026 11:33:40 -0700
Subject: [PATCH 3/4] Expose shutdown in perfetto_c

---
include/perfetto/public/abi/producer_abi.h | 3 +++
src/shared_lib/producer.cc | 4 ++++
2 files changed, 7 insertions(+)

diff --git a/include/perfetto/public/abi/producer_abi.h b/include/perfetto/public/abi/producer_abi.h
index 8899d0098e..e43da137c5 100644
--- a/include/perfetto/public/abi/producer_abi.h
+++ b/include/perfetto/public/abi/producer_abi.h
@@ -79,6 +79,9 @@ PERFETTO_SDK_EXPORT void PerfettoProducerActivateTriggers(
const char* trigger_names[],
uint32_t ttl_ms);

+
+PERFETTO_SDK_EXPORT void PerfettoProducerShutdown(void);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this going to work for the google-internal import of the Cuttlefish code? I assume the shared library we get there isn't going to export these functions.

Are we going to define our own shared library that is similar-but-not-quite to the perfetto shared library? Or is this going to be removed as part of the upstreaming work mentioned in your comment?

This needs a couple upstream changes to Perfetto but generally ready for a first look.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goal is to get everything in upstream. fingers crossed

+
#ifdef __cplusplus
}
#endif
diff --git a/src/shared_lib/producer.cc b/src/shared_lib/producer.cc
index 06599f97e1..8f90bedb2d 100644
--- a/src/shared_lib/producer.cc
+++ b/src/shared_lib/producer.cc
@@ -81,3 +81,7 @@ void PerfettoProducerActivateTriggers(const char* trigger_names[],
}
perfetto::Tracing::ActivateTriggers(triggers, ttl_ms);
}
+
+void PerfettoProducerShutdown(void) {
+ perfetto::Tracing::Shutdown();
+}
--
2.54.0.563.g4f69b47b94-goog

54 changes: 54 additions & 0 deletions base/cvd/build_external/perfetto/PATCH.0004_expose_flush.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From 3c24b5504feba80a1f48c22cf4bfaf27733aee34 Mon Sep 17 00:00:00 2001
From: Jason Macnak <natsu@google.com>
Date: Fri, 15 May 2026 11:37:20 -0700
Subject: [PATCH 4/4] Expose flush in libperfetto_c

---
include/perfetto/public/abi/track_event_abi.h | 2 ++
src/shared_lib/track_event/ds.h | 4 ++++
src/shared_lib/track_event/track_event.cc | 4 ++++
3 files changed, 10 insertions(+)

diff --git a/include/perfetto/public/abi/track_event_abi.h b/include/perfetto/public/abi/track_event_abi.h
index 6c07b30bd4..5c315ea942 100644
--- a/include/perfetto/public/abi/track_event_abi.h
+++ b/include/perfetto/public/abi/track_event_abi.h
@@ -145,6 +145,8 @@ enum PerfettoTeType {
PERFETTO_TE_TYPE_COUNTER = 4,
};

+PERFETTO_SDK_EXPORT void PerfettoTeFlush(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/shared_lib/track_event/ds.h b/src/shared_lib/track_event/ds.h
index 199a1e3d6a..be13a0593b 100644
--- a/src/shared_lib/track_event/ds.h
+++ b/src/shared_lib/track_event/ds.h
@@ -127,6 +127,10 @@ class TrackEvent
Register(dsd);
}

+ static void Flush() {
+ TrackEvent::Trace([](TrackEvent::TraceContext ctx) { ctx.Flush(); });
+ }
+
static void UpdateDescriptorFromCategories(DataSourceDescriptor dsd) {
dsd.set_name("track_event");
UpdateDescriptor(dsd);
diff --git a/src/shared_lib/track_event/track_event.cc b/src/shared_lib/track_event/track_event.cc
index b6f9000ad3..70dd68d61b 100644
--- a/src/shared_lib/track_event/track_event.cc
+++ b/src/shared_lib/track_event/track_event.cc
@@ -86,3 +86,7 @@ void PerfettoTeCategoryImplDestroy(struct PerfettoTeCategoryImpl* cat) {
perfetto::shlib::GlobalState::Instance().UnregisterCategory(cat);
delete cat;
}
+
+void PerfettoTeFlush(void) {
+ perfetto::shlib::TrackEvent::Flush();
+}
--
2.54.0.563.g4f69b47b94-goog

3 changes: 3 additions & 0 deletions base/cvd/build_external/perfetto/perfetto.MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
perfetto_ext = use_extension("//build_external/perfetto:repositories.bzl", "perfetto_extension")
use_repo(perfetto_ext, "perfetto")
use_repo(perfetto_ext, "perfetto_cfg")
32 changes: 32 additions & 0 deletions base/cvd/build_external/perfetto/repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# https://github.com/google/perfetto/issues/2787 for Perfetto getting into the
# Central Repository.
def _perfetto_extension_impl(_):
# From commit 877553985565ab10fe20ea844891aacabd0f70c7:
URL = "https://github.com/google/perfetto/archive/refs/tags/v55.2.tar.gz"
http_archive(
name = "perfetto",
url = URL,
strip_prefix = "perfetto-55.2",
patch_args = ["-p1"],
patches = [
"@//build_external/perfetto:PATCH.0001_disable_android_deps.patch",
"@//build_external/perfetto:PATCH.0002_add_load_statements.patch",
"@//build_external/perfetto:PATCH.0003_expose_shutdown.patch",
"@//build_external/perfetto:PATCH.0004_expose_flush.patch",
],
)
http_archive(
name = "perfetto_cfg",
url = URL,
strip_prefix = "perfetto-55.2/bazel/standalone",
build_file_content = "# empty BUILD to make a bazel package",
patch_cmds = [
"sed -i 's|@com_google_protobuf|@protobuf|g' perfetto_cfg.bzl",
],
)

perfetto_extension = module_extension(
implementation = _perfetto_extension_impl,
)
7 changes: 7 additions & 0 deletions base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ cf_cc_binary(
"//cuttlefish/host/libs/config/fastboot",
"//cuttlefish/host/libs/feature:inject",
"//cuttlefish/host/libs/log_names",
"//cuttlefish/host/libs/tracing",
"//cuttlefish/posix:symlink",
"//cuttlefish/pretty:vector",
"//libbase",
Expand Down Expand Up @@ -169,6 +170,7 @@ cf_cc_library(
"//cuttlefish/common/libs/utils:subprocess",
"//cuttlefish/common/libs/utils:subprocess_managed_stdio",
"//cuttlefish/host/libs/config:config_utils",
"//cuttlefish/host/libs/tracing",
"//cuttlefish/posix:strerror",
"//cuttlefish/result",
"//libbase",
Expand Down Expand Up @@ -223,6 +225,7 @@ cf_cc_library(
"//cuttlefish/host/libs/config:file_source",
"//cuttlefish/host/libs/config:instance_nums",
"//cuttlefish/host/libs/feature:inject",
"//cuttlefish/host/libs/tracing",
"//cuttlefish/result",
"//libbase",
"@abseil-cpp//absl/log",
Expand All @@ -240,6 +243,7 @@ cf_cc_library(
"//cuttlefish/host/libs/config:vmm_mode",
"//cuttlefish/host/libs/image_aggregator",
"//cuttlefish/host/libs/image_aggregator:qcow2",
"//cuttlefish/host/libs/tracing",
"//cuttlefish/result",
"//libbase",
"@abseil-cpp//absl/log",
Expand Down Expand Up @@ -357,6 +361,7 @@ cf_cc_library(
"//cuttlefish/host/libs/config:secure_hals",
"//cuttlefish/host/libs/config:vmm_mode",
"//cuttlefish/host/libs/config/defaults",
"//cuttlefish/host/libs/tracing",
"//cuttlefish/host/libs/vhal_proxy_server",
"//cuttlefish/host/libs/vm_manager",
"//cuttlefish/result",
Expand Down Expand Up @@ -405,6 +410,7 @@ cf_cc_library(
"//cuttlefish/host/libs/config:config_utils",
"//cuttlefish/host/libs/config:display",
"//cuttlefish/host/libs/config:gpu_mode",
"//cuttlefish/host/libs/tracing",
"//cuttlefish/pretty",
"//cuttlefish/pretty:optional",
"//cuttlefish/pretty:string",
Expand Down Expand Up @@ -434,6 +440,7 @@ cf_cc_library(
"//cuttlefish/host/libs/config:guest_hwui_renderer",
"//cuttlefish/host/libs/config:guest_renderer_preload",
"//cuttlefish/host/libs/config:vmm_mode",
"//cuttlefish/host/libs/tracing",
"//cuttlefish/result",
"//libbase",
"@abseil-cpp//absl/log",
Expand Down
Loading
Loading