Convert decoder TRACE_EVENT to flows

This is the first new style trace event so this CL adds and updates
WebRTCs Perfetto configuration.

* Changes all #includes to target "third_party/perfetto". Added this
to DEPS.
* Expose the Perfetto public config in the "tracing" group using
an all_dependent_configs statement. This means the config is included
in all parts that include the "//:tracing" group. However, direct
perfetto includes are banned per DEPS.
* In order to expose Perfetto types (ie Flow/TerminatingFlow) the
perfetto headers are a dependancy on all targets. This should not
affect binary size as these are not used when perfetto is not enabled
and will not be linked.

Bug: b/42226290
Change-Id: I5711d81dae95ee907cbcd41bf1ee9b55d2ec595c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/349161
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@google.com>
Cr-Commit-Position: refs/heads/main@{#42197}
This commit is contained in:
Evan Shrubsole 2024-04-30 07:57:49 +00:00 committed by WebRTC LUCI CQ
parent c3cdab00d8
commit cd09858f4a
13 changed files with 56 additions and 34 deletions

View file

@ -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" ]
}
}

7
DEPS
View file

@ -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 = {

View file

@ -103,9 +103,9 @@ void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
absl::optional<int32_t> decode_time_ms,
absl::optional<uint8_t> 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<FrameInfo> 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;

View file

@ -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" ]
}
}

View file

@ -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",
]
}

View file

@ -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 <inttypes.h>
#include <stdint.h>

View file

@ -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");

View file

@ -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 <string>
#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<unsigned char>(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

View file

@ -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",

View file

@ -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",

View file

@ -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)

View file

@ -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': [],

View file

@ -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