Add directive to make TRACE_EVENT macros optional.
Bug: webrtc:11132 Change-Id: I801994ad262e1acff73e4c20afd7a7343b56268c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160654 Commit-Queue: Doudou Kisabaka <doudouk@google.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29949}
This commit is contained in:

committed by
Commit Bot

parent
b8306cc9bb
commit
2dec496f80
4
BUILD.gn
4
BUILD.gn
@ -263,6 +263,10 @@ config("common_config") {
|
||||
defines += [ "RTC_DISABLE_LOGGING" ]
|
||||
}
|
||||
|
||||
if (rtc_disable_trace_events) {
|
||||
defines += [ "RTC_DISABLE_TRACE_EVENTS" ]
|
||||
}
|
||||
|
||||
if (build_with_chromium) {
|
||||
defines += [
|
||||
# NOTICE: Since common_inherited_config is used in public_configs for our
|
||||
|
@ -30,6 +30,7 @@ namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
const char* FrameTypeToString(AudioFrameType frame_type) {
|
||||
switch (frame_type) {
|
||||
case AudioFrameType::kEmptyFrame:
|
||||
@ -40,6 +41,7 @@ const char* FrameTypeToString(AudioFrameType frame_type) {
|
||||
return "audio_cn";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -133,8 +135,10 @@ bool RTPSenderAudio::SendAudio(AudioFrameType frame_type,
|
||||
uint32_t rtp_timestamp,
|
||||
const uint8_t* payload_data,
|
||||
size_t payload_size) {
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
TRACE_EVENT_ASYNC_STEP1("webrtc", "Audio", rtp_timestamp, "Send", "type",
|
||||
FrameTypeToString(frame_type));
|
||||
#endif
|
||||
|
||||
// From RFC 4733:
|
||||
// A source has wide latitude as to how often it sends event updates. A
|
||||
|
@ -180,6 +180,7 @@ bool IsBaseLayer(const RTPVideoHeader& video_header) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
const char* FrameTypeToString(VideoFrameType frame_type) {
|
||||
switch (frame_type) {
|
||||
case VideoFrameType::kEmptyFrame:
|
||||
@ -193,6 +194,7 @@ const char* FrameTypeToString(VideoFrameType frame_type) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -418,8 +420,10 @@ bool RTPSenderVideo::SendVideo(
|
||||
const RTPFragmentationHeader* fragmentation,
|
||||
RTPVideoHeader video_header,
|
||||
absl::optional<int64_t> expected_retransmission_time_ms) {
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
TRACE_EVENT_ASYNC_STEP1("webrtc", "Video", capture_time_ms, "Send", "type",
|
||||
FrameTypeToString(video_header.frame_type));
|
||||
#endif
|
||||
RTC_CHECK_RUNS_SERIALIZED(&send_checker_);
|
||||
|
||||
if (video_header.frame_type == VideoFrameType::kEmptyFrame)
|
||||
|
@ -998,7 +998,10 @@ TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) {
|
||||
|
||||
rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller();
|
||||
RTCStatsReportVerifier(report.get()).VerifyReport({});
|
||||
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
|
||||
@ -1006,7 +1009,10 @@ TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
|
||||
|
||||
rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee();
|
||||
RTCStatsReportVerifier(report.get()).VerifyReport({});
|
||||
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
|
||||
#endif
|
||||
}
|
||||
|
||||
// These tests exercise the integration of the stats selection algorithm inside
|
||||
@ -1086,8 +1092,10 @@ TEST_F(RTCStatsIntegrationTest,
|
||||
// Any pending stats requests should have completed in the act of destroying
|
||||
// the peer connection.
|
||||
ASSERT_TRUE(stats_obtainer->report());
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
EXPECT_EQ(stats_obtainer->report()->ToJson(),
|
||||
RTCStatsReportTraceListener::last_trace());
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(RTCStatsIntegrationTest, GetsStatsWhileClosingPeerConnection) {
|
||||
@ -1099,8 +1107,10 @@ TEST_F(RTCStatsIntegrationTest, GetsStatsWhileClosingPeerConnection) {
|
||||
caller_->pc()->Close();
|
||||
|
||||
ASSERT_TRUE(stats_obtainer->report());
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
EXPECT_EQ(stats_obtainer->report()->ToJson(),
|
||||
RTCStatsReportTraceListener::last_trace());
|
||||
#endif
|
||||
}
|
||||
|
||||
// GetStatsReferencedIds() is optimized to recognize what is or isn't a
|
||||
|
@ -45,22 +45,6 @@ class TestStatistics {
|
||||
int events_logged_ RTC_GUARDED_BY(crit_) = 0;
|
||||
};
|
||||
|
||||
const unsigned char* GetCategoryEnabledHandler(const char* /*name*/) {
|
||||
return reinterpret_cast<const unsigned char*>("test");
|
||||
}
|
||||
|
||||
void TraceEventHandler(char /*phase*/,
|
||||
const unsigned char* /*category_enabled*/,
|
||||
const char* /*name*/,
|
||||
unsigned long long /*id*/,
|
||||
int /*num_args*/,
|
||||
const char** /*arg_names*/,
|
||||
const unsigned char* /*arg_types*/,
|
||||
const unsigned long long* /*arg_values*/,
|
||||
unsigned char /*flags*/) {
|
||||
TestStatistics::Get()->Increment();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace webrtc {
|
||||
@ -71,11 +55,27 @@ TEST(EventTracerTest, EventTracerDisabled) {
|
||||
TestStatistics::Get()->Reset();
|
||||
}
|
||||
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
TEST(EventTracerTest, ScopedTraceEvent) {
|
||||
SetupEventTracer(&GetCategoryEnabledHandler, &TraceEventHandler);
|
||||
SetupEventTracer(
|
||||
[](const char* /*name*/) {
|
||||
return reinterpret_cast<const unsigned char*>("test");
|
||||
},
|
||||
[](char /*phase*/,
|
||||
const unsigned char* /*category_enabled*/,
|
||||
const char* /*name*/,
|
||||
unsigned long long /*id*/,
|
||||
int /*num_args*/,
|
||||
const char** /*arg_names*/,
|
||||
const unsigned char* /*arg_types*/,
|
||||
const unsigned long long* /*arg_values*/,
|
||||
unsigned char /*flags*/) {
|
||||
TestStatistics::Get()->Increment();
|
||||
});
|
||||
{ TRACE_EVENT0("test", "ScopedTraceEvent"); }
|
||||
EXPECT_EQ(2, TestStatistics::Get()->Count());
|
||||
TestStatistics::Get()->Reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -14,6 +14,23 @@
|
||||
#error "Another copy of trace_event.h has already been included."
|
||||
#endif
|
||||
|
||||
#if defined(RTC_DISABLE_TRACE_EVENTS)
|
||||
#define RTC_TRACE_EVENTS_ENABLED 0
|
||||
#else
|
||||
#define RTC_TRACE_EVENTS_ENABLED 1
|
||||
#endif
|
||||
|
||||
// Type values for identifying types in the TraceValue union.
|
||||
#define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1))
|
||||
#define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2))
|
||||
#define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3))
|
||||
#define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4))
|
||||
#define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5))
|
||||
#define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6))
|
||||
#define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7))
|
||||
|
||||
#if RTC_TRACE_EVENTS_ENABLED
|
||||
|
||||
// Extracted from Chromium's src/base/debug/trace_event.h.
|
||||
|
||||
// This header is designed to give you trace_event macros without specifying
|
||||
@ -626,15 +643,6 @@
|
||||
#define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned char>(1 << 1))
|
||||
#define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned char>(1 << 2))
|
||||
|
||||
// Type values for identifying types in the TraceValue union.
|
||||
#define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1))
|
||||
#define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2))
|
||||
#define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3))
|
||||
#define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4))
|
||||
#define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5))
|
||||
#define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6))
|
||||
#define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7))
|
||||
|
||||
namespace webrtc {
|
||||
namespace trace_event_internal {
|
||||
|
||||
@ -882,5 +890,133 @@ class TraceEndOnScopeClose {
|
||||
|
||||
} // namespace trace_event_internal
|
||||
} // namespace webrtc
|
||||
#else
|
||||
|
||||
#endif // RTC_BASE_TRACE_EVENT_H_
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_STR_COPY(str) RTC_NOOP()
|
||||
|
||||
#define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name
|
||||
|
||||
#define TRACE_ID_MANGLE(id) 0
|
||||
|
||||
#define TRACE_EVENT0(category, name) RTC_NOOP()
|
||||
#define TRACE_EVENT1(category, name, arg1_name, arg1_val) RTC_NOOP()
|
||||
#define TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val) \
|
||||
RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_INSTANT0(category, name) RTC_NOOP()
|
||||
#define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_COPY_INSTANT0(category, name) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \
|
||||
RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_BEGIN0(category, name) RTC_NOOP()
|
||||
#define TRACE_EVENT_BEGIN1(category, name, arg1_name, arg1_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_BEGIN0(category, name) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_END0(category, name) RTC_NOOP()
|
||||
#define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_END0(category, name) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_COUNTER1(category, name, value) RTC_NOOP()
|
||||
#define TRACE_COPY_COUNTER1(category, name, value) RTC_NOOP()
|
||||
|
||||
#define TRACE_COUNTER2(category, name, value1_name, value1_val, \
|
||||
value2_name, value2_val) RTC_NOOP()
|
||||
#define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \
|
||||
value2_name, value2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_COUNTER_ID1(category, name, id, value) RTC_NOOP()
|
||||
#define TRACE_COPY_COUNTER_ID1(category, name, id, value) RTC_NOOP()
|
||||
|
||||
#define TRACE_COUNTER_ID2(category, name, id, value1_name, value1_val, \
|
||||
value2_name, value2_val) RTC_NOOP()
|
||||
#define TRACE_COPY_COUNTER_ID2(category, name, id, value1_name, value1_val, \
|
||||
value2_name, value2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_ASYNC_BEGIN0(category, name, id) RTC_NOOP()
|
||||
#define TRACE_EVENT_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \
|
||||
RTC_NOOP()
|
||||
#define TRACE_EVENT_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_ASYNC_BEGIN0(category, name, id) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \
|
||||
RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_ASYNC_STEP0(category, name, id, step) RTC_NOOP()
|
||||
#define TRACE_EVENT_ASYNC_STEP1(category, name, id, step, \
|
||||
arg1_name, arg1_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_ASYNC_STEP0(category, name, id, step) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_ASYNC_STEP1(category, name, id, step, \
|
||||
arg1_name, arg1_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_ASYNC_END0(category, name, id) RTC_NOOP()
|
||||
#define TRACE_EVENT_ASYNC_END1(category, name, id, arg1_name, arg1_val) \
|
||||
RTC_NOOP()
|
||||
#define TRACE_EVENT_ASYNC_END2(category, name, id, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_ASYNC_END0(category, name, id) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_ASYNC_END1(category, name, id, arg1_name, arg1_val) \
|
||||
RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_ASYNC_END2(category, name, id, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_FLOW_BEGIN0(category, name, id) RTC_NOOP()
|
||||
#define TRACE_EVENT_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \
|
||||
RTC_NOOP()
|
||||
#define TRACE_EVENT_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_FLOW_BEGIN0(category, name, id) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \
|
||||
RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_FLOW_STEP0(category, name, id, step) RTC_NOOP()
|
||||
#define TRACE_EVENT_FLOW_STEP1(category, name, id, step, \
|
||||
arg1_name, arg1_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_FLOW_STEP0(category, name, id, step) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_FLOW_STEP1(category, name, id, step, \
|
||||
arg1_name, arg1_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_FLOW_END0(category, name, id) RTC_NOOP()
|
||||
#define TRACE_EVENT_FLOW_END1(category, name, id, arg1_name, arg1_val) \
|
||||
RTC_NOOP()
|
||||
#define TRACE_EVENT_FLOW_END2(category, name, id, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_FLOW_END0(category, name, id) RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_FLOW_END1(category, name, id, arg1_name, arg1_val) \
|
||||
RTC_NOOP()
|
||||
#define TRACE_EVENT_COPY_FLOW_END2(category, name, id, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val) RTC_NOOP()
|
||||
|
||||
#define TRACE_EVENT_API_GET_CATEGORY_ENABLED ""
|
||||
|
||||
#define TRACE_EVENT_API_ADD_TRACE_EVENT RTC_NOOP()
|
||||
|
||||
#endif // RTC_TRACE_EVENTS_ENABLED
|
||||
|
||||
#endif // RTC_BASE_TRACE_EVENT_H_
|
@ -245,6 +245,9 @@ declare_args() {
|
||||
|
||||
# Set this to true to fully remove logging from WebRTC.
|
||||
rtc_disable_logging = false
|
||||
|
||||
# Set this to true to disable trace events.
|
||||
rtc_disable_trace_events = false
|
||||
}
|
||||
|
||||
# Make it possible to provide custom locations for some libraries (move these
|
||||
|
Reference in New Issue
Block a user