diff --git a/BUILD.gn b/BUILD.gn index eb9ad83547..f090f16120 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -272,26 +272,29 @@ config("rtc_prod_config") { } group("tracing") { + all_dependent_configs = [ "//third_party/perfetto/gn:public_config" ] if (rtc_use_perfetto) { if (build_with_chromium) { public_deps = # no-presubmit-check TODO(webrtc:8603) [ "//third_party/perfetto:libperfetto" ] } else { - public_deps = # no-presubmit-check TODO(webrtc:8603) - [ ":webrtc_libperfetto" ] + public_deps = [ # no-presubmit-check TODO(webrtc:8603) + ":webrtc_libperfetto", + "//third_party/perfetto/include/perfetto/tracing", + ] } + } else { + public_deps = # no-presubmit-check TODO(webrtc:8603) + [ "//third_party/perfetto/include/perfetto/tracing" ] } } if (rtc_use_perfetto) { rtc_library("webrtc_libperfetto") { - public_configs = [ "//third_party/perfetto/gn:public_config" ] deps = [ "//third_party/perfetto/src/tracing:client_api_without_backends", "//third_party/perfetto/src/tracing:platform_impl", ] - public_deps += # no-presubmit-check TODO(webrtc:8603) - [ "//third_party/perfetto/include/perfetto/tracing" ] } } diff --git a/DEPS b/DEPS index 18145ea484..b8e5b51f82 100644 --- a/DEPS +++ b/DEPS @@ -2669,9 +2669,10 @@ include_rules = [ # Abseil flags are allowed in tests and tools. "+absl/flags", - # Perfetto - '+third_party/perfetto/include/perfetto/tracing', - '+third_party/perfetto/include/perfetto/test', + # Perfetto should be used through rtc_base/trace_event.h + '-third_party/perfetto', + '-perfetto', + '-protos/perfetto', ] specific_include_rules = { diff --git a/modules/video_coding/generic_decoder.cc b/modules/video_coding/generic_decoder.cc index 0a9920a176..0bfc628d2c 100644 --- a/modules/video_coding/generic_decoder.cc +++ b/modules/video_coding/generic_decoder.cc @@ -103,9 +103,9 @@ void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage, absl::optional decode_time_ms, absl::optional qp) { RTC_DCHECK(_receiveCallback) << "Callback must not be null at this point"; - TRACE_EVENT_INSTANT1("webrtc", "VCMDecodedFrameCallback::Decoded", - TRACE_EVENT_SCOPE_GLOBAL, "timestamp", - decodedImage.rtp_timestamp()); + TRACE_EVENT( + "webrtc", "VCMDecodedFrameCallback::Decoded", + perfetto::TerminatingFlow::ProcessScoped(decodedImage.rtp_timestamp())); // TODO(holmer): We should improve this so that we can handle multiple // callbacks from one call to Decode(). absl::optional frame_info; @@ -293,8 +293,8 @@ int32_t VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, Timestamp now) { int32_t VCMGenericDecoder::Decode(const EncodedImage& frame, Timestamp now, int64_t render_time_ms) { - TRACE_EVENT1("webrtc", "VCMGenericDecoder::Decode", "timestamp", - frame.RtpTimestamp()); + TRACE_EVENT("webrtc", "VCMGenericDecoder::Decode", + perfetto::Flow::ProcessScoped(frame.RtpTimestamp())); FrameInfo frame_info; frame_info.rtp_timestamp = frame.RtpTimestamp(); frame_info.decode_start = now; diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index f761c36400..b6e1697682 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -210,6 +210,7 @@ rtc_library("event_tracer") { ":platform_thread_types", ":rtc_event", ":timeutils", + "..:tracing", "../api:sequence_checker", "synchronization:mutex", "system:rtc_export", @@ -220,7 +221,6 @@ rtc_library("event_tracer") { "trace_categories.cc", "trace_categories.h", ] - deps += [ "..:tracing" ] } } diff --git a/rtc_base/DEPS b/rtc_base/DEPS index 4ba8c92e33..bb985b94be 100644 --- a/rtc_base/DEPS +++ b/rtc_base/DEPS @@ -13,9 +13,12 @@ specific_include_rules = { "+testing/base/public/gunit.h" ], "trace_categories\.h": [ - "+perfetto", + "+third_party/perfetto", ], "event_tracer\.cc": [ - "+perfetto", + "+third_party/perfetto", + ], + "trace_event\.h": [ + "+third_party/perfetto", ] } diff --git a/rtc_base/event_tracer.cc b/rtc_base/event_tracer.cc index 677b95bb70..7e9ecba584 100644 --- a/rtc_base/event_tracer.cc +++ b/rtc_base/event_tracer.cc @@ -15,8 +15,8 @@ #include "rtc_base/trace_event.h" #if defined(RTC_USE_PERFETTO) -#include "perfetto/tracing/tracing.h" #include "rtc_base/trace_categories.h" +#include "third_party/perfetto/include/perfetto/tracing/tracing.h" #else #include #include diff --git a/rtc_base/trace_categories.h b/rtc_base/trace_categories.h index c22ce911d3..e355bbbbbe 100644 --- a/rtc_base/trace_categories.h +++ b/rtc_base/trace_categories.h @@ -13,10 +13,10 @@ #define PERFETTO_ENABLE_LEGACY_TRACE_EVENTS 1 -#include "perfetto/tracing/track_event.h" // IWYU pragma: export -#include "perfetto/tracing/track_event_category_registry.h" -#include "perfetto/tracing/track_event_legacy.h" // IWYU pragma: export #include "rtc_base/system/rtc_export.h" +#include "third_party/perfetto/include/perfetto/tracing/track_event.h" // IWYU pragma: export +#include "third_party/perfetto/include/perfetto/tracing/track_event_category_registry.h" +#include "third_party/perfetto/include/perfetto/tracing/track_event_legacy.h" // IWYU pragma: export PERFETTO_DEFINE_TEST_CATEGORY_PREFIXES("webrtc-test"); diff --git a/rtc_base/trace_event.h b/rtc_base/trace_event.h index ab628022ef..4a2d234a67 100644 --- a/rtc_base/trace_event.h +++ b/rtc_base/trace_event.h @@ -17,9 +17,16 @@ #define RTC_TRACE_EVENTS_ENABLED 1 #endif +// IWYU pragma: begin_exports #if defined(RTC_USE_PERFETTO) +#include "rtc_base/trace_categories.h" +#endif +#include "third_party/perfetto/include/perfetto/tracing/event_context.h" +#include "third_party/perfetto/include/perfetto/tracing/track.h" +#include "third_party/perfetto/include/perfetto/tracing/track_event_args.h" +// IWYU pragma: end_exports -#include "rtc_base/trace_categories.h" // IWYU pragma: export +#if defined(RTC_USE_PERFETTO) // TODO(webrtc:15917): Replace these events. #define TRACE_EVENT_ASYNC_STEP0(category_group, name, id, step) \ @@ -34,6 +41,21 @@ #include #include "rtc_base/event_tracer.h" +#include "third_party/perfetto/include/perfetto/tracing/event_context.h" +#include "third_party/perfetto/include/perfetto/tracing/track.h" +#include "third_party/perfetto/include/perfetto/tracing/track_event_args.h" + +#define RTC_NOOP() \ + do { \ + } while (0) + +// TODO(b/42226290): Add implementation for these events with Perfetto. +#define TRACE_EVENT_BEGIN(category, name, ...) RTC_NOOP(); +#define TRACE_EVENT_END(category, ...) RTC_NOOP(); +#define TRACE_EVENT(category, name, ...) RTC_NOOP(); +#define TRACE_EVENT_INSTANT(category, name, ...) RTC_NOOP(); +#define TRACE_EVENT_CATEGORY_ENABLED(category) RTC_NOOP(); +#define TRACE_COUNTER(category, track, ...) RTC_NOOP(); // Type values for identifying types in the TraceValue union. #define TRACE_VALUE_TYPE_BOOL (static_cast(1)) @@ -731,10 +753,6 @@ class TraceEndOnScopeClose { // This section defines no-op alternatives to the tracing macros when // RTC_DISABLE_TRACE_EVENTS is defined. -#define RTC_NOOP() \ - do { \ - } while (0) - #define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name #define TRACE_ID_MANGLE(id) 0 diff --git a/test/BUILD.gn b/test/BUILD.gn index aeb51465dc..180297f5c2 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -616,6 +616,7 @@ if (rtc_include_tests) { "../rtc_base:threading", "../system_wrappers:field_trial", "../system_wrappers:metrics", + "//third_party/perfetto/include/perfetto/tracing", ] absl_deps = [ "//third_party/abseil-cpp/absl/flags:flag", diff --git a/test/DEPS b/test/DEPS index f9f47e16a7..95193e753a 100644 --- a/test/DEPS +++ b/test/DEPS @@ -50,8 +50,7 @@ specific_include_rules = { "+p2p/base/stun.h", ], ".*test_main_lib\.cc": [ - "+perfetto/tracing", - "+protos/perfetto/config", + "+third_party/perfetto", ], ".*test_main\.cc": [ "+absl/debugging/failure_signal_handler.h", diff --git a/test/test_main_lib.cc b/test/test_main_lib.cc index 76b5a16851..e35029b943 100644 --- a/test/test_main_lib.cc +++ b/test/test_main_lib.cc @@ -44,10 +44,10 @@ #include "test/testsupport/resources_dir_flag.h" #if defined(RTC_USE_PERFETTO) -#include "perfetto/tracing/backend_type.h" -#include "perfetto/tracing/tracing.h" -#include "protos/perfetto/config/trace_config.gen.h" #include "rtc_base/event_tracer.h" +#include "third_party/perfetto/include/perfetto/tracing/backend_type.h" +#include "third_party/perfetto/include/perfetto/tracing/tracing.h" +#include "third_party/perfetto/protos/perfetto/config/trace_config.gen.h" #endif #if defined(WEBRTC_WIN) diff --git a/tools_webrtc/libs/generate_licenses.py b/tools_webrtc/libs/generate_licenses.py index 7d34ec6e82..10d6f67521 100755 --- a/tools_webrtc/libs/generate_licenses.py +++ b/tools_webrtc/libs/generate_licenses.py @@ -79,6 +79,7 @@ LIB_TO_LICENSES_DICT = { 'kotlin_stdlib': ['third_party/kotlin_stdlib/LICENSE'], 'jni_zero': ['third_party/jni_zero/LICENSE'], 'protobuf-javascript': ['third_party/protobuf-javascript/LICENSE'], + 'perfetto': ['third_party/perfetto/LICENSE'], # TODO(bugs.webrtc.org/1110): Remove this hack. This is not a lib. # For some reason it is listed as so in _get_third_party_libraries. 'android_deps': [], diff --git a/webrtc.gni b/webrtc.gni index f7a8e7317a..af341d7e2a 100644 --- a/webrtc.gni +++ b/webrtc.gni @@ -394,10 +394,6 @@ if (build_with_chromium && use_perfetto_client_library) { rtc_use_perfetto = true } -if (rtc_use_perfetto) { - rtc_common_configs += [ "//third_party/perfetto/gn:public_config" ] -} - # Global public configuration that should be applied to all WebRTC targets. You # normally shouldn't need to include this in your target as it's automatically # included when using the rtc_* templates. It set the defines, include paths and