Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1950)

Unified Diff: base/trace_event/trace_event.h

Issue 2504753002: tracing: Introduce API for composite IDs (Closed)
Patch Set: Slightly more efficient implementation Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/trace_event/trace_event_impl.cc » ('j') | base/trace_event/trace_event_impl.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/trace_event.h
diff --git a/base/trace_event/trace_event.h b/base/trace_event/trace_event.h
index 0299ddd0cb70356313e3c95fa195b09e50d36246..649fd9b637c399d1b61278c7ffff0cb0ce697a07 100644
--- a/base/trace_event/trace_event.h
+++ b/base/trace_event/trace_event.h
@@ -45,10 +45,14 @@
// 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_GLOBAL(id) trace_event_internal::TraceID::GlobalId(id)
-#define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::LocalId(id)
+ trace_event_internal::TraceID::MakeScopedID(scope, id)
+// Can be nested within TRACE_ID_WITH_SCOPE macro.
+#define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::MakeGlobalID(id)
+// Can be nested within TRACE_ID_WITH_SCOPE macro.
+#define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::MakeLocalID(id)
+// Can be nested within TRACE_ID_{LOCAL, GLOBAL, WITH_SCOPE} macros.
+#define TRACE_ID_COMPOSITE(prefix, id) \
+ trace_event_internal::TraceID::CompositeID(prefix, id)
#define TRACE_EVENT_API_CURRENT_THREAD_ID \
static_cast<int>(base::PlatformThread::CurrentId())
@@ -408,38 +412,57 @@ const unsigned long long kNoId = 0;
// collide when the same pointer is used on different processes.
class BASE_EXPORT TraceID {
public:
- // Can be combined with WithScope.
- class LocalId {
+ class CompositeID {
+ public:
+ CompositeID(unsigned long long prefix, unsigned long long raw_id)
+ : prefix_(prefix), raw_id_(raw_id) {}
+
+ void set_scope(const char* scope) { scope_ = scope; }
+
+ void set_id_flags(unsigned int id_flags) { id_flags_ = id_flags; }
+
+ const char* scope() const { return scope_; }
+ unsigned long long prefix() const { return prefix_; }
+ unsigned long long raw_id() const { return raw_id_; }
+ unsigned int id_flags() const { return id_flags_; }
+
+ private:
+ const char* scope_ = nullptr;
+ unsigned long long prefix_;
+ unsigned long long raw_id_;
+ unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID;
+ };
+
+ class LocalID {
public:
- explicit LocalId(unsigned long long raw_id) : raw_id_(raw_id) {}
+ 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 {
+ class GlobalID {
public:
- explicit GlobalId(unsigned long long raw_id) : raw_id_(raw_id) {}
+ 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 {
+ class ScopedID {
public:
- WithScope(const char* scope, unsigned long long raw_id)
+ ScopedID(const char* scope, unsigned long long raw_id)
: scope_(scope), raw_id_(raw_id) {}
- WithScope(const char* scope, LocalId local_id)
+ ScopedID(const char* scope, LocalID local_id)
: scope_(scope), raw_id_(local_id.raw_id()) {
id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID;
}
- WithScope(const char* scope, GlobalId global_id)
+ ScopedID(const char* scope, GlobalID global_id)
: scope_(scope), raw_id_(global_id.raw_id()) {
id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID;
}
- unsigned long long raw_id() const { return raw_id_; }
const char* scope() const { return scope_; }
+ unsigned long long raw_id() const { return raw_id_; }
unsigned int id_flags() const { return id_flags_; }
private:
const char* scope_ = nullptr;
@@ -447,7 +470,36 @@ class BASE_EXPORT TraceID {
unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID;
};
- // DEPRECATED: consider using LocalId or GlobalId, instead.
+ static inline CompositeID MakeLocalID(CompositeID& composite_id) {
+ composite_id.set_id_flags(TRACE_EVENT_FLAG_HAS_LOCAL_ID);
+ return composite_id;
+ }
+
+ static inline LocalID MakeLocalID(unsigned long long raw_id) {
+ return LocalID(raw_id);
+ }
+
+ static inline CompositeID MakeGlobalID(CompositeID& composite_id) {
+ composite_id.set_id_flags(TRACE_EVENT_FLAG_HAS_GLOBAL_ID);
+ return composite_id;
+ }
+
+ static inline GlobalID MakeGlobalID(unsigned long long raw_id) {
+ return GlobalID(raw_id);
+ }
+
+ static inline CompositeID MakeScopedID(const char* scope,
+ CompositeID& composite_id) {
caseq 2016/11/21 19:47:20 const ComositeID&
chiniforooshan 2016/11/21 21:12:15 But composite_id is actually modified in this func
+ composite_id.set_scope(scope);
+ return composite_id;
+ }
+
+ template <typename T>
+ static inline ScopedID MakeScopedID(const char* scope, T raw_id) {
caseq 2016/11/21 19:47:20 why do we need it to be template? looks like we on
chiniforooshan 2016/11/21 21:12:15 I think you missed the other two constructors :) S
+ return ScopedID(scope, raw_id);
+ }
+
+ // DEPRECATED: consider using LocalID or GlobalID, instead.
class DontMangle {
public:
explicit DontMangle(const void* raw_id)
@@ -473,7 +525,7 @@ class BASE_EXPORT TraceID {
unsigned long long raw_id_;
};
- // DEPRECATED: consider using LocalId or GlobalId, instead.
+ // DEPRECATED: consider using LocalID or GlobalID, instead.
class ForceMangle {
public:
explicit ForceMangle(unsigned long long raw_id) : raw_id_(raw_id) {}
@@ -519,17 +571,27 @@ class BASE_EXPORT TraceID {
: raw_id_(static_cast<unsigned long long>(raw_id)) {}
TraceID(signed char raw_id)
: raw_id_(static_cast<unsigned long long>(raw_id)) {}
- TraceID(LocalId raw_id) : raw_id_(raw_id.raw_id()) {
+ TraceID(LocalID local_id) : raw_id_(local_id.raw_id()) {
id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID;
}
- TraceID(GlobalId raw_id) : raw_id_(raw_id.raw_id()) {
+ TraceID(GlobalID global_id) : raw_id_(global_id.raw_id()) {
id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID;
}
- TraceID(WithScope scoped_id) : scope_(scoped_id.scope()),
- raw_id_(scoped_id.raw_id()), id_flags_(scoped_id.id_flags()) {}
+ TraceID(ScopedID scoped_id)
+ : scope_(scoped_id.scope()),
+ raw_id_(scoped_id.raw_id()),
+ id_flags_(scoped_id.id_flags()) {}
+ TraceID(CompositeID composite_id)
+ : scope_(composite_id.scope()),
+ has_prefix_(true),
+ prefix_(composite_id.prefix()),
+ raw_id_(composite_id.raw_id()),
+ id_flags_(composite_id.id_flags()) {}
- 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_; }
+ unsigned long long raw_id() const { return raw_id_; }
unsigned int id_flags() const { return id_flags_; }
std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
@@ -537,6 +599,8 @@ class BASE_EXPORT TraceID {
private:
const char* scope_ = nullptr;
+ bool has_prefix_ = false;
+ unsigned long long prefix_;
unsigned long long raw_id_;
unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID;
};
« no previous file with comments | « no previous file | base/trace_event/trace_event_impl.cc » ('j') | base/trace_event/trace_event_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698