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

Unified Diff: base/trace_event/trace_event.h

Issue 2504753002: tracing: Introduce API for composite IDs (Closed)
Patch Set: comments Created 3 years, 11 months 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') | no next file with comments »
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 fe8f6576d697b5fccda6b624c6323687a70b0243..51e6927cbd5b1724821e77f41d848e94f11f59ad 100644
--- a/base/trace_event/trace_event.h
+++ b/base/trace_event/trace_event.h
@@ -43,9 +43,21 @@
trace_event_internal::TraceID::DontMangle(id)
// 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)
+// this macro to add a scope string. For example,
+//
+// TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
+// "network", "ResourceLoad",
+// TRACE_ID_WITH_SCOPE("BlinkResourceID", resourceID));
+//
+// Also, it is possible to prepend the ID with another number, like the process
+// ID. This is useful in creatin IDs that are unique among all processes. To do
+// that, pass two numbers after the scope string instead of one. For example,
+//
+// TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
+// "network", "ResourceLoad",
+// TRACE_ID_WITH_SCOPE("BlinkResourceID", pid, resourceID));
+#define TRACE_ID_WITH_SCOPE(scope, ...) \
+ trace_event_internal::TraceID::WithScope(scope, ##__VA_ARGS__)
#define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::GlobalId(id)
#define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::LocalId(id)
@@ -430,11 +442,27 @@ class BASE_EXPORT TraceID {
: scope_(scope), raw_id_(global_id.raw_id()) {
id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID;
}
+ WithScope(const char* scope,
+ unsigned long long prefix,
+ unsigned long long raw_id)
+ : scope_(scope), has_prefix_(true), prefix_(prefix), raw_id_(raw_id) {}
+ WithScope(const char* scope, unsigned long long prefix, GlobalId global_id)
+ : scope_(scope),
+ has_prefix_(true),
+ prefix_(prefix),
+ 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_; }
+ bool has_prefix() const { return has_prefix_; }
+ unsigned long long prefix() const { return prefix_; }
unsigned int id_flags() const { return id_flags_; }
+
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;
};
@@ -517,11 +545,17 @@ class BASE_EXPORT TraceID {
TraceID(GlobalId raw_id) : raw_id_(raw_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(WithScope scoped_id)
+ : scope_(scoped_id.scope()),
+ has_prefix_(scoped_id.has_prefix()),
+ prefix_(scoped_id.prefix()),
+ raw_id_(scoped_id.raw_id()),
+ id_flags_(scoped_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 int id_flags() const { return id_flags_; }
std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
@@ -529,6 +563,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698