Chromium Code Reviews| Index: base/trace_event/trace_event.h |
| diff --git a/base/trace_event/trace_event.h b/base/trace_event/trace_event.h |
| index 250c161d46ce018ff316a0ee8ac8c44f0ba79e92..9ee9a00abded385925d7e4bfa9a44559c05561c0 100644 |
| --- a/base/trace_event/trace_event.h |
| +++ b/base/trace_event/trace_event.h |
| @@ -28,13 +28,16 @@ |
| #define TRACE_STR_COPY(str) \ |
| trace_event_internal::TraceStringWithCopy(str) |
| -// By default, uint64_t ID argument values are not mangled with the Process ID |
| -// in TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling. |
| +// DEPRECATED: do not use: Consider using TRACE_ID_{GLOBAL, LOCAL} macros, |
| +// instead. By default, uint64_t ID argument values are not mangled with the |
| +// Process ID in TRACE_EVENT_ASYNC macros. Use this macro to force Process ID |
| +// mangling. |
| #define TRACE_ID_MANGLE(id) \ |
| trace_event_internal::TraceID::ForceMangle(id) |
| -// By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC |
| -// macros. Use this macro to prevent Process ID mangling. |
| +// DEPRECATED: do not use: Consider using TRACE_ID_{GLOBAL, LOCAL} macros, |
| +// instead. By default, pointers are mangled with the Process ID in |
| +// TRACE_EVENT_ASYNC macros. Use this macro to prevent Process ID mangling. |
| #define TRACE_ID_DONT_MANGLE(id) \ |
| trace_event_internal::TraceID::DontMangle(id) |
| @@ -43,6 +46,9 @@ |
| #define TRACE_ID_WITH_SCOPE(scope, id) \ |
| trace_event_internal::TraceID::WithScope(scope, id) |
| +#define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::GlobalId(id) |
| +#define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::LocalId(id) |
| + |
| // Sets the current sample state to the given category and name (both must be |
| // constant strings). These states are intended for a sampling profiler. |
| // Implementation note: we store category and name together because we don't |
| @@ -72,6 +78,10 @@ |
| #define TRACE_EVENT_API_CURRENT_THREAD_ID \ |
| static_cast<int>(base::PlatformThread::CurrentId()) |
| +#define INTERNAL_SET_ID_FLAGS(flags, id_bits) \ |
|
caseq
2016/08/22 19:48:51
INTERNAL_SET_ID_BITS() perhaps?
chiniforooshan
2016/08/23 19:54:53
Done.
|
| + flags &= TRACE_EVENT_FLAG_ALL - TRACE_EVENT_FLAG_ID_MASK; \ |
|
caseq
2016/08/22 19:48:51
flags &= ~TRACE_EVENT_FLAG_ID_MASK
chiniforooshan
2016/08/23 19:54:53
Done.
|
| + flags |= id_bits; |
| + |
| #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ |
| UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ |
| (base::trace_event::TraceLog::ENABLED_FOR_RECORDING | \ |
| @@ -298,18 +308,18 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ |
| // Implementation detail: internal macro to create static category and add |
| // event if the category is enabled. |
| -#define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ |
| - flags, ...) \ |
| - do { \ |
| - INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| - if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| - unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ |
| - trace_event_internal::TraceID trace_event_trace_id( \ |
| - id, &trace_event_flags); \ |
| - trace_event_internal::AddTraceEvent( \ |
| - phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| +#define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ |
| + flags, ...) \ |
| + do { \ |
| + INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| + if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| + unsigned int trace_event_flags = flags; \ |
| + trace_event_internal::TraceID trace_event_trace_id( \ |
| + id, &trace_event_flags); \ |
| + trace_event_internal::AddTraceEvent( \ |
| + phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| name, trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ |
| - trace_event_flags, trace_event_internal::kNoId, ##__VA_ARGS__); \ |
| + trace_event_flags, trace_event_internal::kNoId, ##__VA_ARGS__); \ |
| } \ |
| } while (0) |
| @@ -337,7 +347,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ |
| do { \ |
| INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| - unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ |
| + unsigned int trace_event_flags = flags; \ |
| trace_event_internal::TraceID trace_event_trace_id(id, \ |
| &trace_event_flags); \ |
| trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ |
| @@ -349,26 +359,28 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ |
| } \ |
| } while (0) |
| -// The trace ID and bind ID will never be mangled by this macro. |
| +// This macro ignores whether the bind_id is local, global, or mangled. |
| #define INTERNAL_TRACE_EVENT_ADD_BIND_IDS(category_group, name, id, bind_id, \ |
| ...) \ |
| do { \ |
| INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| - trace_event_internal::TraceID::DontMangle source_id(id); \ |
| - trace_event_internal::TraceID::DontMangle target_id(bind_id); \ |
| + unsigned int source_flags = TRACE_EVENT_FLAG_NONE; \ |
| + trace_event_internal::TraceID source_id(id, &source_flags); \ |
| + unsigned int target_flags = TRACE_EVENT_FLAG_NONE; \ |
| + trace_event_internal::TraceID target_id(bind_id, &target_flags); \ |
| if (target_id.scope() == trace_event_internal::kGlobalScope) { \ |
| trace_event_internal::AddTraceEvent( \ |
| TRACE_EVENT_PHASE_BIND_IDS, \ |
| INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| name, source_id.scope(), source_id.raw_id(), \ |
| - TRACE_EVENT_FLAG_HAS_ID, target_id.raw_id(), ##__VA_ARGS__); \ |
| + source_flags, target_id.raw_id(), ##__VA_ARGS__); \ |
| } else { \ |
| trace_event_internal::AddTraceEvent( \ |
| TRACE_EVENT_PHASE_BIND_IDS, \ |
| INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| name, source_id.scope(), source_id.raw_id(), \ |
| - TRACE_EVENT_FLAG_HAS_ID, target_id.raw_id(), \ |
| + source_flags, target_id.raw_id(), \ |
| "bind_scope", target_id.scope(), ##__VA_ARGS__); \ |
| } \ |
| } \ |
| @@ -406,7 +418,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ |
| void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ |
| }; \ |
| INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
| - INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id()); |
| + INTERNAL_TRACE_EVENT_UID(scoped_context)(context); |
| // Implementation detail: internal macro to trace a task execution with the |
| // location where it was posted from. |
| @@ -430,17 +442,46 @@ const unsigned long long kNoId = 0; |
| // collide when the same pointer is used on different processes. |
| class TraceID { |
| public: |
| + // Can be combined with WithScope. |
| + class LocalId { |
| + public: |
| + explicit LocalId(unsigned long long raw_id) : raw_id_(raw_id) {} |
| + unsigned long long raw_id() const { return raw_id_; } |
| + private: |
| + unsigned long long raw_id_; |
| + }; |
| + |
| + // Can be combined with WithScope. |
| + class GlobalId { |
| + public: |
| + explicit GlobalId(unsigned long long raw_id) : raw_id_(raw_id) {} |
| + unsigned long long raw_id() const { return raw_id_; } |
| + private: |
| + unsigned long long raw_id_; |
| + }; |
| + |
| class WithScope { |
| public: |
| WithScope(const char* scope, unsigned long long raw_id) |
| : scope_(scope), raw_id_(raw_id) {} |
| + WithScope(const char* scope, LocalId local_id) |
| + : scope_(scope), raw_id_(local_id.raw_id()) { |
| + flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; |
| + } |
| + WithScope(const char* scope, GlobalId global_id) |
| + : scope_(scope), raw_id_(global_id.raw_id()) { |
| + flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; |
| + } |
| unsigned long long raw_id() const { return raw_id_; } |
| const char* scope() const { return scope_; } |
| + unsigned int flags() const { return flags_; } |
| private: |
| const char* scope_ = nullptr; |
| unsigned long long raw_id_; |
| + unsigned int flags_ = TRACE_EVENT_FLAG_HAS_ID; |
| }; |
| + // DEPRECATED: consider using LocalId or GlobalId, instead. |
| class DontMangle { |
| public: |
| explicit DontMangle(const void* raw_id) |
| @@ -461,15 +502,12 @@ class TraceID { |
| : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| explicit DontMangle(signed char raw_id) |
| : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| - explicit DontMangle(WithScope scoped_id) |
| - : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {} |
| - const char* scope() const { return scope_; } |
| unsigned long long raw_id() const { return raw_id_; } |
| private: |
| - const char* scope_ = nullptr; |
| unsigned long long raw_id_; |
| }; |
| + // DEPRECATED: consider using LocalId or GlobalId, instead. |
| class ForceMangle { |
| public: |
| explicit ForceMangle(unsigned long long raw_id) : raw_id_(raw_id) {} |
| @@ -491,44 +529,65 @@ class TraceID { |
| private: |
| unsigned long long raw_id_; |
| }; |
| + |
| TraceID(const void* raw_id, unsigned int* flags) |
| : raw_id_(static_cast<unsigned long long>( |
| reinterpret_cast<uintptr_t>(raw_id))) { |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| *flags |= TRACE_EVENT_FLAG_MANGLE_ID; |
| } |
| TraceID(ForceMangle raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| *flags |= TRACE_EVENT_FLAG_MANGLE_ID; |
| } |
| - TraceID(DontMangle maybe_scoped_id, unsigned int* flags) |
| - : scope_(maybe_scoped_id.scope()), raw_id_(maybe_scoped_id.raw_id()) { |
| + TraceID(DontMangle raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| } |
| TraceID(unsigned long long raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| - (void)flags; |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| } |
| TraceID(unsigned long raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| - (void)flags; |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| } |
| TraceID(unsigned int raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| - (void)flags; |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| } |
| TraceID(unsigned short raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| - (void)flags; |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| } |
| TraceID(unsigned char raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| - (void)flags; |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| } |
| TraceID(long long raw_id, unsigned int* flags) |
| - : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } |
| + : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| + } |
| TraceID(long raw_id, unsigned int* flags) |
| - : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } |
| + : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| + } |
| TraceID(int raw_id, unsigned int* flags) |
| - : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } |
| + : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| + } |
| TraceID(short raw_id, unsigned int* flags) |
| - : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } |
| + : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| + } |
| TraceID(signed char raw_id, unsigned int* flags) |
| - : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } |
| + : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| + } |
| + TraceID(LocalId raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { |
|
caseq
2016/08/22 19:48:52
I wonder if it's going to be cleaner to have somet
chiniforooshan
2016/08/23 19:54:53
Done (kind of... does the implementation in patch
|
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_LOCAL_ID); |
| + } |
| + TraceID(GlobalId raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { |
| + INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_GLOBAL_ID); |
| + } |
| TraceID(WithScope scoped_id, unsigned int* flags) |
| - : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {} |
| + : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) { |
| + INTERNAL_SET_ID_FLAGS(*flags, scoped_id.flags()); |
| + } |
| unsigned long long raw_id() const { return raw_id_; } |
| const char* scope() const { return scope_; } |