Proxy: solve event tracing with compile time strings.
This change creates trace events with a single parameter composed of ClassName::Method. The change additionally causes the duration of the proxy call to be traced, not only the occurrence. Fixed: webrtc:12787 Change-Id: I1689862318d4c6fc1dcef343c3ccf3ae9f7e17df Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/219788 Commit-Queue: Markus Handell <handellm@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34149}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
d325f322c7
commit
3d46d0b200
192
pc/proxy.h
192
pc/proxy.h
@ -71,16 +71,30 @@
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/message_handler.h"
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
#include "rtc_base/string_utils.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
#include "rtc_base/thread.h"
|
||||
|
||||
#if !defined(RTC_DISABLE_PROXY_TRACE_EVENTS) && !defined(WEBRTC_CHROMIUM_BUILD)
|
||||
#define RTC_DISABLE_PROXY_TRACE_EVENTS
|
||||
#endif
|
||||
|
||||
namespace rtc {
|
||||
class Location;
|
||||
}
|
||||
|
||||
namespace webrtc {
|
||||
namespace proxy_internal {
|
||||
RTC_EXPORT void TraceApiCall(const char* class_name, const char* method_name);
|
||||
|
||||
// Class for tracing the lifetime of MethodCall::Marshal.
|
||||
class ScopedTrace {
|
||||
public:
|
||||
explicit ScopedTrace(const char* class_and_method_name);
|
||||
~ScopedTrace();
|
||||
|
||||
private:
|
||||
const char* const class_and_method_name_;
|
||||
};
|
||||
} // namespace proxy_internal
|
||||
|
||||
template <typename R>
|
||||
@ -195,8 +209,8 @@ class ConstMethodCall : public QueuedTask {
|
||||
template <class INTERNAL_CLASS> \
|
||||
class c##ProxyWithInternal : public c##Interface { \
|
||||
protected: \
|
||||
static constexpr char proxy_name_[] = #c "Proxy"; \
|
||||
typedef c##Interface C; \
|
||||
const char* class_name_ = PROXY_STRINGIZE(c); \
|
||||
\
|
||||
public: \
|
||||
const INTERNAL_CLASS* internal() const { return c_; } \
|
||||
@ -205,8 +219,10 @@ class ConstMethodCall : public QueuedTask {
|
||||
// clang-format off
|
||||
// clang-format would put the semicolon alone,
|
||||
// leading to a presubmit error (cpplint.py)
|
||||
#define END_PROXY_MAP() \
|
||||
};
|
||||
#define END_PROXY_MAP(c) \
|
||||
}; \
|
||||
template <class INTERNAL_CLASS> \
|
||||
constexpr char c##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
|
||||
// clang-format on
|
||||
|
||||
#define PRIMARY_PROXY_MAP_BOILERPLATE(c) \
|
||||
@ -306,53 +322,67 @@ class ConstMethodCall : public QueuedTask {
|
||||
\
|
||||
public: // NOLINTNEXTLINE
|
||||
|
||||
#define PROXY_METHOD0(r, method) \
|
||||
r method() override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
MethodCall<C, r> call(c_, &C::method); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
|
||||
#define TRACE_BOILERPLATE(method) \
|
||||
do { \
|
||||
} while (0)
|
||||
#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
|
||||
#define TRACE_BOILERPLATE(method) \
|
||||
static constexpr auto class_and_method_name = \
|
||||
rtc::MakeCompileTimeString(proxy_name_) \
|
||||
.Concat(rtc::MakeCompileTimeString("::")) \
|
||||
.Concat(rtc::MakeCompileTimeString(#method)); \
|
||||
proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
|
||||
|
||||
#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
|
||||
|
||||
#define PROXY_METHOD0(r, method) \
|
||||
r method() override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r> call(c_, &C::method); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_CONSTMETHOD0(r, method) \
|
||||
r method() const override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
ConstMethodCall<C, r> call(c_, &C::method); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
#define PROXY_CONSTMETHOD0(r, method) \
|
||||
r method() const override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
ConstMethodCall<C, r> call(c_, &C::method); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_METHOD1(r, method, t1) \
|
||||
r method(t1 a1) override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
#define PROXY_METHOD1(r, method, t1) \
|
||||
r method(t1 a1) override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_CONSTMETHOD1(r, method, t1) \
|
||||
r method(t1 a1) const override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
#define PROXY_CONSTMETHOD1(r, method, t1) \
|
||||
r method(t1 a1) const override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_METHOD2(r, method, t1, t2) \
|
||||
r method(t1 a1, t2 a2) override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2)); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
#define PROXY_METHOD2(r, method, t1, t2) \
|
||||
r method(t1 a1, t2 a2) override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2)); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_METHOD3(r, method, t1, t2, t3) \
|
||||
r method(t1 a1, t2 a2, t3 a3) override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2), std::move(a3)); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
#define PROXY_METHOD3(r, method, t1, t2, t3) \
|
||||
r method(t1 a1, t2 a2, t3 a3) override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2), std::move(a3)); \
|
||||
return call.Marshal(RTC_FROM_HERE, primary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
|
||||
r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r, t1, t2, t3, t4> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2), std::move(a3), \
|
||||
std::move(a4)); \
|
||||
@ -361,7 +391,7 @@ class ConstMethodCall : public QueuedTask {
|
||||
|
||||
#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
|
||||
r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r, t1, t2, t3, t4, t5> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2), std::move(a3), \
|
||||
std::move(a4), std::move(a5)); \
|
||||
@ -369,61 +399,61 @@ class ConstMethodCall : public QueuedTask {
|
||||
}
|
||||
|
||||
// Define methods which should be invoked on the secondary thread.
|
||||
#define PROXY_SECONDARY_METHOD0(r, method) \
|
||||
r method() override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
MethodCall<C, r> call(c_, &C::method); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
#define PROXY_SECONDARY_METHOD0(r, method) \
|
||||
r method() override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r> call(c_, &C::method); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
|
||||
r method() const override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
ConstMethodCall<C, r> call(c_, &C::method); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
|
||||
r method() const override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
ConstMethodCall<C, r> call(c_, &C::method); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_SECONDARY_METHOD1(r, method, t1) \
|
||||
r method(t1 a1) override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
#define PROXY_SECONDARY_METHOD1(r, method, t1) \
|
||||
r method(t1 a1) override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
|
||||
r method(t1 a1) const override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
|
||||
r method(t1 a1) const override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
|
||||
r method(t1 a1, t2 a2) override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
|
||||
r method(t1 a1, t2 a2) override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
|
||||
r method(t1 a1, t2 a2) const override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
ConstMethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
|
||||
r method(t1 a1, t2 a2) const override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
ConstMethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
|
||||
r method(t1 a1, t2 a2, t3 a3) override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2), std::move(a3)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
|
||||
r method(t1 a1, t2 a2, t3 a3) override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2), std::move(a3)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
}
|
||||
|
||||
#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
|
||||
r method(t1 a1, t2 a2, t3 a3) const override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
ConstMethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
|
||||
std::move(a2), std::move(a3)); \
|
||||
return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
|
||||
@ -432,10 +462,10 @@ class ConstMethodCall : public QueuedTask {
|
||||
// For use when returning purely const state (set during construction).
|
||||
// Use with caution. This method should only be used when the return value will
|
||||
// always be the same.
|
||||
#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
|
||||
r method() const override { \
|
||||
proxy_internal::TraceApiCall(class_name_, PROXY_STRINGIZE(method)); \
|
||||
return c_->method(); \
|
||||
#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
|
||||
r method() const override { \
|
||||
TRACE_BOILERPLATE(method); \
|
||||
return c_->method(); \
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user