diff --git a/webrtc/BUILD.gn b/webrtc/BUILD.gn index 58b5f5e740..ac3b02a20f 100644 --- a/webrtc/BUILD.gn +++ b/webrtc/BUILD.gn @@ -26,6 +26,17 @@ config("common_inherited_config") { if (build_with_mozilla) { defines += [ "WEBRTC_MOZILLA_BUILD" ] } + # Some tests need to declare their own trace event handlers. If this define is + # not set, the first time TRACE_EVENT_* is called it will store the return + # value for the current handler in an static variable, so that subsequent + # changes to the handler for that TRACE_EVENT_* will be ignored. + # So when tests are included, we set this define, making it possible to use + # different event handlers in different tests. + if (rtc_include_tests) { + defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1" ] + } else { + defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0" ] + } if (build_with_chromium) { defines = [ # TODO(kjellander): Cleanup unused ones and move defines closer to diff --git a/webrtc/rtc_base/trace_event.h b/webrtc/rtc_base/trace_event.h index 98f6afae94..6a1476d917 100644 --- a/webrtc/rtc_base/trace_event.h +++ b/webrtc/rtc_base/trace_event.h @@ -575,9 +575,15 @@ #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) +#if WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS +#define INTERNAL_TRACE_EVENT_INFO_TYPE const unsigned char* +#else +#define INTERNAL_TRACE_EVENT_INFO_TYPE static const unsigned char* +#endif // WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS + // Implementation detail: internal macro to create static category. #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \ - static const unsigned char* INTERNAL_TRACE_EVENT_UID(catstatic) = \ + INTERNAL_TRACE_EVENT_INFO_TYPE INTERNAL_TRACE_EVENT_UID(catstatic) = \ TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); // Implementation detail: internal macro to create static category and add