-
Notifications
You must be signed in to change notification settings - Fork 207
Add perfetto tracing to host tooling #2502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jmacnak
wants to merge
1
commit into
google:main
Choose a base branch
from
jmacnak:perfetto
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
49 changes: 49 additions & 0 deletions
49
base/cvd/build_external/perfetto/PATCH.0001_disable_android_deps.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
131
base/cvd/build_external/perfetto/PATCH.0002_add_load_statements.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
39
base/cvd/build_external/perfetto/PATCH.0003_expose_shutdown.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| + | ||
| #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
54
base/cvd/build_external/perfetto/PATCH.0004_expose_flush.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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