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..28f78eaed887f7f18ac7b47b7e34c7812c5bdb0f 100644 |
| --- a/base/trace_event/trace_event.h |
| +++ b/base/trace_event/trace_event.h |
| @@ -15,10 +15,13 @@ |
| #include <string> |
| #include "base/atomicops.h" |
| +#include "base/format_macros.h" |
| #include "base/macros.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/time/time.h" |
| #include "base/trace_event/common/trace_event_common.h" |
| #include "base/trace_event/heap_profiler.h" |
| +#include "base/trace_event/trace_event_argument.h" |
| #include "base/trace_event/trace_event_system_stats_monitor.h" |
| #include "base/trace_event/trace_log.h" |
| #include "build/build_config.h" |
| @@ -28,20 +31,30 @@ |
| #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 (GLOBAL_)TRACE_ID(_WITH_SCOPE) 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 (GLOBAL_)TRACE_ID(_WITH_SCOPE) macros, |
|
Primiano Tucci (use gerrit)
2016/08/05 14:20:07
so the doubt that I have when I see that both thes
|
| +// 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) |
| +// Sets a flag to indicate that the ID is global across all processes. |
| +#define GLOBAL_TRACE_ID(...) \ |
|
Primiano Tucci (use gerrit)
2016/08/05 14:20:07
I thought that the ID is already global, reason fo
|
| + trace_event_internal::TraceID::WithScope( \ |
| + trace_event_internal::kGlobalScope, true, __VA_ARGS__) |
| + |
| // By default, trace IDs are eventually converted to a single 64-bit number. Use |
| // this macro to add a scope string. |
| -#define TRACE_ID_WITH_SCOPE(scope, id) \ |
| - trace_event_internal::TraceID::WithScope(scope, id) |
| +#define TRACE_ID_WITH_SCOPE(scope, ...) \ |
| + trace_event_internal::TraceID::WithScope(scope, false, __VA_ARGS__) |
| +#define GLOBAL_TRACE_ID_WITH_SCOPE(scope, ...) \ |
| + trace_event_internal::TraceID::WithScope(scope, true, __VA_ARGS__) |
| // Sets the current sample state to the given category and name (both must be |
| // constant strings). These states are intended for a sampling profiler. |
| @@ -349,33 +362,45 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ |
| } \ |
| } while (0) |
| -// The trace ID and bind ID will never be mangled by this macro. |
| -#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); \ |
| - 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__); \ |
| - } 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(), \ |
| - "bind_scope", target_id.scope(), ##__VA_ARGS__); \ |
| - } \ |
| - } \ |
| +// The linked ID will not be mangled. |
| +#define INTERNAL_TRACE_EVENT_ADD_LINK_IDS(category_group, name, id1, id2) \ |
| + do { \ |
| + INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| + if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| + unsigned int flags = TRACE_EVENT_FLAG_HAS_ID; \ |
| + trace_event_internal::TraceID id(id1, &flags); \ |
| + unsigned int args_id_flags = TRACE_EVENT_FLAG_NONE; \ |
| + trace_event_internal::TraceID args_id(id2, &args_id_flags); \ |
| + std::unique_ptr<TracedValue> value(new TracedValue()); \ |
|
Primiano Tucci (use gerrit)
2016/08/05 14:20:07
I don't see any precedent of using TracedValue dir
|
| + if (args_id.has_prefix()) { \ |
| + value->BeginArray("id"); \ |
| + value->AppendString( \ |
| + StringPrintf("0x%" PRIx64, \ |
| + static_cast<uint64_t>(args_id.prefix()))); \ |
| + value->AppendString( \ |
| + StringPrintf("0x%" PRIx64, \ |
| + static_cast<uint64_t>(args_id.raw_id()))); \ |
| + value->EndArray(); \ |
| + } else { \ |
| + value->SetString( \ |
| + "id", \ |
| + StringPrintf("0x%" PRIx64, \ |
| + static_cast<uint64_t>(args_id.raw_id()))); \ |
| + } \ |
| + if (args_id_flags & TRACE_EVENT_FLAG_ID_IS_GLOBAL) \ |
| + value->SetBoolean("id_is_global", true); \ |
| + if (args_id.scope() != trace_event_internal::kGlobalScope) \ |
| + value->SetString("scope", args_id.scope()); \ |
| + trace_event_internal::AddTraceEvent( \ |
| + TRACE_EVENT_PHASE_BIND_IDS, \ |
| + INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| + name, id.scope(), id.raw_id(), flags, trace_event_internal::kNoId, \ |
| + "linked_id", std::move(value)); \ |
| + } \ |
| } while (0) |
| // Implementation detail: internal macro to create static category and add |
| -// metadata event if the category is enabled. |
| +// metadata event if the category is enabled |
| #define INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, ...) \ |
| do { \ |
| INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| @@ -406,7 +431,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. |
| @@ -432,12 +457,22 @@ class TraceID { |
| public: |
| class WithScope { |
| public: |
| - WithScope(const char* scope, unsigned long long raw_id) |
| - : scope_(scope), raw_id_(raw_id) {} |
| - unsigned long long raw_id() const { return raw_id_; } |
| + WithScope(const char* scope, bool is_global, unsigned long long raw_id) |
| + : scope_(scope), is_global_(is_global), raw_id_(raw_id) {} |
| + WithScope(const char* scope, bool is_global, unsigned long long prefix, |
|
Primiano Tucci (use gerrit)
2016/08/05 14:20:07
what is this prefix? I don't see documented this a
|
| + unsigned long long raw_id) |
| + : scope_(scope), is_global_(is_global), has_prefix_(true), |
| + prefix_(prefix), raw_id_(raw_id) {} |
| const char* scope() const { return scope_; } |
| + unsigned long long raw_id() const { return raw_id_; } |
| + bool has_prefix() const { return has_prefix_; } |
| + unsigned long long prefix() const { return prefix_; } |
| + bool is_global() const { return is_global_; } |
| private: |
| const char* scope_ = nullptr; |
| + bool is_global_ = false; |
| + bool has_prefix_ = false; |
| + unsigned long long prefix_; |
| unsigned long long raw_id_; |
| }; |
| @@ -461,12 +496,8 @@ 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_; |
| }; |
| @@ -500,7 +531,8 @@ class TraceID { |
| *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()) { |
| + : raw_id_(maybe_scoped_id.raw_id()) { |
| + *flags |= TRACE_EVENT_FLAG_ID_IS_GLOBAL; |
| } |
| TraceID(unsigned long long raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| (void)flags; |
| @@ -528,13 +560,21 @@ class TraceID { |
| TraceID(signed char raw_id, unsigned int* flags) |
| : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } |
| TraceID(WithScope scoped_id, unsigned int* flags) |
| - : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {} |
| + : scope_(scoped_id.scope()), has_prefix_(scoped_id.has_prefix()), |
| + prefix_(scoped_id.prefix()), raw_id_(scoped_id.raw_id()) { |
| + if (scoped_id.is_global()) |
| + *flags |= TRACE_EVENT_FLAG_ID_IS_GLOBAL; |
| + } |
| unsigned long long raw_id() const { return raw_id_; } |
| const char* scope() const { return scope_; } |
| + bool has_prefix() const { return has_prefix_; } |
| + unsigned long long prefix() const { return prefix_; } |
| private: |
| const char* scope_ = nullptr; |
| + bool has_prefix_ = false; |
| + unsigned long long prefix_; |
| unsigned long long raw_id_; |
| }; |