diff options
author | fmeawad <fmeawad@chromium.org> | 2016-02-15 21:20:21 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-16 05:21:35 +0000 |
commit | 0207cb1393d5f8094c1f5c1323c64aae1cc40077 (patch) | |
tree | 3ab3e294c39d5dd05d929ab77c2afce9f3273752 /base | |
parent | 18ec5733a1da90cb5f6ad87f7cad2b77d6c64d3c (diff) | |
download | chromium_src-0207cb1393d5f8094c1f5c1323c64aae1cc40077.zip chromium_src-0207cb1393d5f8094c1f5c1323c64aae1cc40077.tar.gz chromium_src-0207cb1393d5f8094c1f5c1323c64aae1cc40077.tar.bz2 |
[Tracing] Fix scoped context trace events category handling
By moving all the necessary code into a single MACRO, we avoid jumping
from macro to code and back, which would loose the __LINE__ number of
the original call site.
BUG=585528
Review URL: https://codereview.chromium.org/1682123002
Cr-Commit-Position: refs/heads/master@{#375518}
Diffstat (limited to 'base')
-rw-r--r-- | base/trace_event/trace_event.h | 42 | ||||
-rw-r--r-- | base/trace_event/trace_event_unittest.cc | 11 |
2 files changed, 26 insertions, 27 deletions
diff --git a/base/trace_event/trace_event.h b/base/trace_event/trace_event.h index 311f73c..ed49fe4 100644 --- a/base/trace_event/trace_event.h +++ b/base/trace_event/trace_event.h @@ -350,8 +350,24 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ // Implementation detail: internal macro to enter and leave a context based on // the current scope. #define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \ - trace_event_internal::TraceScopedContext INTERNAL_TRACE_EVENT_UID( \ - scoped_trace)(category_group, name, context) + struct INTERNAL_TRACE_EVENT_UID(ScopedContext) { \ + public: \ + INTERNAL_TRACE_EVENT_UID(ScopedContext)(uint64_t cid) : cid_(cid) { \ + TRACE_EVENT_ENTER_CONTEXT(category_group, name, cid_); \ + } \ + ~INTERNAL_TRACE_EVENT_UID(ScopedContext)() { \ + TRACE_EVENT_LEAVE_CONTEXT(category_group, name, cid_); \ + } \ + \ + private: \ + uint64_t cid_; \ + /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \ + INTERNAL_TRACE_EVENT_UID(ScopedContext) \ + (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ + void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ + }; \ + INTERNAL_TRACE_EVENT_UID(ScopedContext) \ + INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id()); namespace trace_event_internal { @@ -940,28 +956,6 @@ class TraceEventSamplingStateScope { const char* previous_state_; }; -using TraceContext = trace_event_internal::TraceID; - -class TraceScopedContext { - public: - TraceScopedContext(const char* category_group, - const char* name, - trace_event_internal::TraceID::DontMangle context) - : category_group_(category_group), name_(name), context_(context) { - TRACE_EVENT_ENTER_CONTEXT(category_group_, name_, context_); - } - - ~TraceScopedContext() { - TRACE_EVENT_LEAVE_CONTEXT(category_group_, name_, context_); - } - - private: - const char* category_group_; - const char* name_; - trace_event_internal::TraceID::DontMangle context_; - DISALLOW_COPY_AND_ASSIGN(TraceScopedContext); -}; - } // namespace trace_event_internal namespace base { diff --git a/base/trace_event/trace_event_unittest.cc b/base/trace_event/trace_event_unittest.cc index a39c190..f3dc16d 100644 --- a/base/trace_event/trace_event_unittest.cc +++ b/base/trace_event/trace_event_unittest.cc @@ -498,12 +498,17 @@ void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) { TRACE_EVENT1(kControlCharacters, kControlCharacters, kControlCharacters, kControlCharacters); + uint64_t context_id = 0x20151021; + TRACE_EVENT_ENTER_CONTEXT("all", "TRACE_EVENT_ENTER_CONTEXT call", - TRACE_ID_WITH_SCOPE("scope", 0x20151021)); + TRACE_ID_WITH_SCOPE("scope", context_id)); TRACE_EVENT_LEAVE_CONTEXT("all", "TRACE_EVENT_LEAVE_CONTEXT call", - TRACE_ID_WITH_SCOPE("scope", 0x20151021)); + TRACE_ID_WITH_SCOPE("scope", context_id)); + TRACE_EVENT_SCOPED_CONTEXT("disabled-by-default-cat", + "TRACE_EVENT_SCOPED_CONTEXT disabled call", + context_id); TRACE_EVENT_SCOPED_CONTEXT("all", "TRACE_EVENT_SCOPED_CONTEXT call", - 0x20151021); + context_id); } // Scope close causes TRACE_EVENT0 etc to send their END events. if (task_complete_event) |