Use scoped class to implement CEF_TRACE_EVENTx (issue #971).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1261 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
ac4c19159c
commit
3d16a39e9e
|
@ -157,12 +157,6 @@ extern "C" {
|
|||
// - |id| is used to disambiguate counters with the same name, or match async
|
||||
// trace events
|
||||
|
||||
CEF_EXPORT void cef_trace_event(const char* category,
|
||||
const char* name,
|
||||
const char* arg1_name,
|
||||
uint64 arg1_val,
|
||||
const char* arg2_name,
|
||||
uint64 arg2_val);
|
||||
CEF_EXPORT void cef_trace_event_instant(const char* category,
|
||||
const char* name,
|
||||
const char* arg1_name,
|
||||
|
@ -233,12 +227,31 @@ CEF_EXPORT void cef_trace_event_async_end(const char* category,
|
|||
// - category and name strings must have application lifetime (statics or
|
||||
// literals). They may not include " chars.
|
||||
#define CEF_TRACE_EVENT0(category, name) \
|
||||
cef_trace_event(category, name, NULL, 0, NULL, 0)
|
||||
cef_trace_event_begin(category, name, NULL, 0, NULL, 0, false); \
|
||||
CEF_INTERNAL_TRACE_END_ON_SCOPE_CLOSE(category, name)
|
||||
#define CEF_TRACE_EVENT1(category, name, arg1_name, arg1_val) \
|
||||
cef_trace_event(category, name, arg1_name, arg1_val, NULL, 0)
|
||||
cef_trace_event_begin(category, name, arg1_name, arg1_val, NULL, 0, false); \
|
||||
CEF_INTERNAL_TRACE_END_ON_SCOPE_CLOSE(category, name)
|
||||
#define CEF_TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, \
|
||||
arg2_val) \
|
||||
cef_trace_event(category, name, arg1_name, arg1_val, arg2_name, arg2_val)
|
||||
cef_trace_event_begin(category, name, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val, false); \
|
||||
CEF_INTERNAL_TRACE_END_ON_SCOPE_CLOSE(category, name)
|
||||
|
||||
// Implementation detail: trace event macros create temporary variable names.
|
||||
// These macros give each temporary variable a unique name based on the line
|
||||
// number to prevent name collisions.
|
||||
#define CEF_INTERNAL_TRACE_EVENT_UID3(a,b) \
|
||||
cef_trace_event_unique_##a##b
|
||||
#define CEF_INTERNAL_TRACE_EVENT_UID2(a,b) \
|
||||
CEF_INTERNAL_TRACE_EVENT_UID3(a,b)
|
||||
#define CEF_INTERNAL_TRACE_EVENT_UID(name_prefix) \
|
||||
CEF_INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__)
|
||||
|
||||
// Implementation detail: internal macro to end end event when the scope ends.
|
||||
#define CEF_INTERNAL_TRACE_END_ON_SCOPE_CLOSE(category, name) \
|
||||
cef_trace_event_internal::CefTraceEndOnScopeClose \
|
||||
CEF_INTERNAL_TRACE_EVENT_UID(profileScope)(category, name)
|
||||
|
||||
// Records a single event called "name" immediately, with 0, 1 or 2
|
||||
// associated arguments. If the category is not enabled, then this
|
||||
|
@ -436,4 +449,23 @@ CEF_EXPORT void cef_trace_event_async_end(const char* category,
|
|||
cef_trace_event_async_end(category, name, id, arg1_name, arg1_val, \
|
||||
arg2_name, arg2_val, true)
|
||||
|
||||
namespace cef_trace_event_internal {
|
||||
|
||||
// Used by CEF_TRACE_EVENTx macro. Do not use directly.
|
||||
class CefTraceEndOnScopeClose {
|
||||
public:
|
||||
CefTraceEndOnScopeClose(const char* category, const char* name)
|
||||
: category_(category), name_(name) {
|
||||
}
|
||||
~CefTraceEndOnScopeClose() {
|
||||
cef_trace_event_end(category_, name_, NULL, 0, NULL, 0, false);
|
||||
}
|
||||
|
||||
private:
|
||||
const char* category_;
|
||||
const char* name_;
|
||||
};
|
||||
|
||||
} // cef_trace_event_internal
|
||||
|
||||
#endif // CEF_INCLUDE_CEF_TRACE_EVENT_H_
|
||||
|
|
|
@ -72,27 +72,6 @@ int64 CefNowFromSystemTraceTime() {
|
|||
|
||||
// The below functions can be called from any process.
|
||||
|
||||
CEF_EXPORT void cef_trace_event(const char* category,
|
||||
const char* name,
|
||||
const char* arg1_name,
|
||||
uint64 arg1_val,
|
||||
const char* arg2_name,
|
||||
uint64 arg2_val) {
|
||||
DCHECK(category);
|
||||
DCHECK(name);
|
||||
if (!category || !name)
|
||||
return;
|
||||
|
||||
if (arg1_name == NULL && arg2_name == NULL) {
|
||||
TRACE_EVENT0(category, name);
|
||||
} else if (arg2_name == NULL) {
|
||||
TRACE_EVENT1(category, name, arg1_name, arg1_val);
|
||||
} else {
|
||||
TRACE_EVENT2(category, name, arg1_name, arg1_val,
|
||||
arg2_name, arg2_val);
|
||||
}
|
||||
}
|
||||
|
||||
CEF_EXPORT void cef_trace_event_instant(const char* category,
|
||||
const char* name,
|
||||
const char* arg1_name,
|
||||
|
|
|
@ -121,16 +121,16 @@ class TracingTestHandler : public CefTraceClient {
|
|||
WaitForUIThread();
|
||||
|
||||
switch (type_) {
|
||||
case CEF_TRACE_EVENT0:
|
||||
case CEF_TRACE_EVENT0: {
|
||||
CEF_TRACE_EVENT0(kTraceTestCategory, "CEF_TRACE_EVENT0");
|
||||
break;
|
||||
case CEF_TRACE_EVENT1:
|
||||
} break;
|
||||
case CEF_TRACE_EVENT1: {
|
||||
CEF_TRACE_EVENT1(kTraceTestCategory, "CEF_TRACE_EVENT1", "arg1", 1);
|
||||
break;
|
||||
case CEF_TRACE_EVENT2:
|
||||
} break;
|
||||
case CEF_TRACE_EVENT2: {
|
||||
CEF_TRACE_EVENT2(kTraceTestCategory, "CEF_TRACE_EVENT2", "arg1", 1,
|
||||
"arg2", 2);
|
||||
break;
|
||||
} break;
|
||||
case CEF_TRACE_EVENT_INSTANT0:
|
||||
CEF_TRACE_EVENT_INSTANT0(kTraceTestCategory,
|
||||
"CEF_TRACE_EVENT_INSTANT0");
|
||||
|
|
Loading…
Reference in New Issue