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

Unified Diff: base/trace_event/trace_event.h

Issue 1239593002: Implement a new flow event API that allows binding flow events and regular events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implement binding flow events to slices for PostTasks. Created 5 years, 5 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
Index: base/trace_event/trace_event.h
diff --git a/base/trace_event/trace_event.h b/base/trace_event/trace_event.h
index 1e5b42a753a908e3b9a32a25d9b8993290cdf580..cfbafe793abb37481c3083f429c7e03f2f1e474a 100644
--- a/base/trace_event/trace_event.h
+++ b/base/trace_event/trace_event.h
@@ -225,14 +225,29 @@
#define TRACE_EVENT0(category_group, name) \
INTERNAL_TRACE_MEMORY(category_group, name) \
INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name)
+#define TRACE_EVENT_WITH_FLOW0(category_group, name, bind_id, flow_direction) \
+ INTERNAL_TRACE_MEMORY(category_group, name) \
+ INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
+ flow_direction)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
INTERNAL_TRACE_MEMORY(category_group, name) \
INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
+#define TRACE_EVENT_WITH_FLOW1(category_group, name, bind_id, flow_direction, \
+ arg1_name, arg1_val) \
+ INTERNAL_TRACE_MEMORY(category_group, name) \
+ INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW( \
+ category_group, name, bind_id, flow_direction, arg1_name, arg1_val)
#define TRACE_EVENT2( \
category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \
INTERNAL_TRACE_MEMORY(category_group, name) \
INTERNAL_TRACE_EVENT_ADD_SCOPED( \
category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
+#define TRACE_EVENT_WITH_FLOW2(category_group, name, bind_id, flow_direction, \
+ arg1_name, arg1_val, arg2_name, arg2_val) \
+ INTERNAL_TRACE_MEMORY(category_group, name) \
+ INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, bind_id, \
+ flow_direction, arg1_name, \
+ arg1_val, arg2_name, arg2_val)
// Records events like TRACE_EVENT2 but uses |memory_tag| for memory tracing.
// Use this where |name| is too generic to accurately aggregate allocations.
@@ -242,6 +257,15 @@
INTERNAL_TRACE_EVENT_ADD_SCOPED( \
category, name, arg1_name, arg1_val, arg2_name, arg2_val)
+#define TRACE_EVENT_WITH_MEMORY_TAG_WITH_FLOW2(category, name, memory_tag, \
+ bind_id, flow_direction, \
+ arg1_name, arg1_val, arg2_name, \
+ arg2_val) \
+ INTERNAL_TRACE_MEMORY(category, memory_tag) \
+ INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category, name, bind_id, \
+ flow_direction, arg1_name, \
+ arg1_val, arg2_name, arg2_val)
+
// UNSHIPPED_TRACE_EVENT* are like TRACE_EVENT* except that they are not
// included in official builds.
@@ -1049,68 +1073,87 @@ 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(phase, category_group, name, flags, ...) \
- do { \
- INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
- if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
- trace_event_internal::AddTraceEvent( \
- phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
- trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \
- } \
- } while (0)
+#define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \
dsinclair 2015/07/17 13:39:40 Can you undo the formatting that puts the \'s line
+ do { \
+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
+ trace_event_internal::AddTraceEvent( \
+ phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
+ trace_event_internal::kNoEventId, flags, \
+ trace_event_internal::kNoBindId, ##__VA_ARGS__); \
+ } \
+ } while (0)
// Implementation detail: internal macro to create static category and add begin
// event if the category is enabled. Also adds the end event when the scope
// ends.
-#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
- INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
- trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
- if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
- base::trace_event::TraceEventHandle h = \
- trace_event_internal::AddTraceEvent( \
- TRACE_EVENT_PHASE_COMPLETE, \
- INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
- trace_event_internal::kNoEventId, TRACE_EVENT_FLAG_NONE, \
- ##__VA_ARGS__); \
- INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
- INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
- }
+#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
+ trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
+ base::trace_event::TraceEventHandle h = \
+ trace_event_internal::AddTraceEvent( \
+ TRACE_EVENT_PHASE_COMPLETE, \
+ INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
+ trace_event_internal::kNoEventId, TRACE_EVENT_FLAG_NONE, \
+ trace_event_internal::kNoBindId, ##__VA_ARGS__); \
+ INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
+ INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
+ }
+
+#define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW( \
+ category_group, name, bind_id, flow_direction, ...) \
+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
+ trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
+ unsigned int trace_event_flags = flow_direction; \
+ trace_event_internal::TraceID trace_event_bind_id(bind_id, \
+ &trace_event_flags); \
+ base::trace_event::TraceEventHandle h = \
+ trace_event_internal::AddTraceEvent( \
+ TRACE_EVENT_PHASE_COMPLETE, \
+ INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
+ trace_event_internal::kNoEventId, flow_direction, \
+ trace_event_bind_id.data(), ##__VA_ARGS__); \
+ INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
+ INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
+ }
// 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), \
- name, trace_event_trace_id.data(), trace_event_flags, \
- ##__VA_ARGS__); \
- } \
- } while (0)
+#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), name, \
+ trace_event_trace_id.data(), trace_event_flags, \
+ trace_event_internal::kNoBindId, ##__VA_ARGS__); \
+ } \
+ } while (0)
// Implementation detail: internal macro to create static category and add
// event if the category is enabled.
-#define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, \
- category_group, name, id, thread_id, timestamp, 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::AddTraceEventWithThreadIdAndTimestamp( \
- phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
- name, trace_event_trace_id.data(), \
- thread_id, base::TraceTicks::FromInternalValue(timestamp), \
- trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \
- ##__VA_ARGS__); \
- } \
- } while (0)
+#define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
+ phase, category_group, name, id, thread_id, timestamp, 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::AddTraceEventWithThreadIdAndTimestamp( \
+ phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
+ trace_event_trace_id.data(), thread_id, \
+ base::TraceTicks::FromInternalValue(timestamp), \
+ trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \
+ trace_event_internal::kNoBindId, ##__VA_ARGS__); \
+ } \
+ } while (0)
// Notes regarding the following definitions:
// New values can be added and propagated to third party libraries, but existing
@@ -1150,6 +1193,8 @@ TRACE_EVENT_API_CLASS_EXPORT extern \
#define TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP (static_cast<unsigned int>(1 << 5))
#define TRACE_EVENT_FLAG_ASYNC_TTS (static_cast<unsigned int>(1 << 6))
#define TRACE_EVENT_FLAG_BIND_TO_ENCLOSING (static_cast<unsigned int>(1 << 7))
+#define TRACE_EVENT_FLAG_FLOW_IN (static_cast<unsigned int>(1 << 8))
+#define TRACE_EVENT_FLAG_FLOW_OUT (static_cast<unsigned int>(1 << 9))
dsinclair 2015/07/17 13:39:40 nit: Can you line the ('s up on these ones with AS
#define TRACE_EVENT_FLAG_SCOPE_MASK (static_cast<unsigned int>( \
TRACE_EVENT_FLAG_SCOPE_OFFSET | TRACE_EVENT_FLAG_SCOPE_EXTRA))
@@ -1180,6 +1225,7 @@ namespace trace_event_internal {
// used.
const int kZeroNumArgs = 0;
const unsigned long long kNoEventId = 0;
+const unsigned long long kNoBindId = 0;
dsinclair 2015/07/17 13:39:40 Let's just rename kNoEventId to kNoId = 0 and use
// TraceID encapsulates an ID that can either be an integer or pointer. Pointers
// are by default mangled with the Process ID so that they are unlikely to
@@ -1393,17 +1439,18 @@ AddTraceEventWithThreadIdAndTimestamp(
int thread_id,
const base::TraceTicks& timestamp,
unsigned int flags,
+ unsigned long long bind_id,
const char* arg1_name,
const scoped_refptr<base::trace_event::ConvertableToTraceFormat>&
arg1_val) {
const int num_args = 1;
unsigned char arg_types[1] = { TRACE_VALUE_TYPE_CONVERTABLE };
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
- phase, category_group_enabled, name, id, thread_id, timestamp,
- num_args, &arg1_name, arg_types, NULL, &arg1_val, flags);
+ phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
+ &arg1_name, arg_types, NULL, &arg1_val, flags, bind_id);
}
-template<class ARG1_TYPE>
+template <class ARG1_TYPE>
static inline base::trace_event::TraceEventHandle
AddTraceEventWithThreadIdAndTimestamp(
char phase,
@@ -1413,6 +1460,7 @@ AddTraceEventWithThreadIdAndTimestamp(
int thread_id,
const base::TraceTicks& timestamp,
unsigned int flags,
+ unsigned long long bind_id,
const char* arg1_name,
const ARG1_TYPE& arg1_val,
const char* arg2_name,
@@ -1431,11 +1479,11 @@ AddTraceEventWithThreadIdAndTimestamp(
convertable_values[1] = arg2_val;
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
- phase, category_group_enabled, name, id, thread_id, timestamp,
- num_args, arg_names, arg_types, arg_values, convertable_values, flags);
+ phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
+ arg_names, arg_types, arg_values, convertable_values, flags, bind_id);
}
-template<class ARG2_TYPE>
+template <class ARG2_TYPE>
dsinclair 2015/07/17 13:39:40 nit: remove space.
static inline base::trace_event::TraceEventHandle
AddTraceEventWithThreadIdAndTimestamp(
char phase,
@@ -1445,6 +1493,7 @@ AddTraceEventWithThreadIdAndTimestamp(
int thread_id,
const base::TraceTicks& timestamp,
unsigned int flags,
+ unsigned long long bind_id,
const char* arg1_name,
const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& arg1_val,
const char* arg2_name,
@@ -1463,8 +1512,8 @@ AddTraceEventWithThreadIdAndTimestamp(
convertable_values[0] = arg1_val;
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
- phase, category_group_enabled, name, id, thread_id, timestamp,
- num_args, arg_names, arg_types, arg_values, convertable_values, flags);
+ phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
+ arg_names, arg_types, arg_values, convertable_values, flags, bind_id);
}
static inline base::trace_event::TraceEventHandle
@@ -1476,6 +1525,7 @@ AddTraceEventWithThreadIdAndTimestamp(
int thread_id,
const base::TraceTicks& timestamp,
unsigned int flags,
+ unsigned long long bind_id,
const char* arg1_name,
const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& arg1_val,
const char* arg2_name,
@@ -1489,8 +1539,8 @@ AddTraceEventWithThreadIdAndTimestamp(
convertable_values[2] = {arg1_val, arg2_val};
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
- phase, category_group_enabled, name, id, thread_id, timestamp,
- num_args, arg_names, arg_types, NULL, convertable_values, flags);
+ phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
+ arg_names, arg_types, NULL, convertable_values, flags, bind_id);
}
static inline base::trace_event::TraceEventHandle
@@ -1501,10 +1551,11 @@ AddTraceEventWithThreadIdAndTimestamp(
unsigned long long id,
int thread_id,
const base::TraceTicks& timestamp,
- unsigned int flags) {
+ unsigned int flags,
+ unsigned long long bind_id) {
dsinclair 2015/07/17 13:39:40 Let's move bind_id up below int thread_id so we ke
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
phase, category_group_enabled, name, id, thread_id, timestamp,
- kZeroNumArgs, NULL, NULL, NULL, NULL, flags);
+ kZeroNumArgs, NULL, NULL, NULL, NULL, flags, bind_id);
}
static inline base::trace_event::TraceEventHandle AddTraceEvent(
@@ -1512,14 +1563,15 @@ static inline base::trace_event::TraceEventHandle AddTraceEvent(
const unsigned char* category_group_enabled,
const char* name,
unsigned long long id,
- unsigned int flags) {
+ unsigned int flags,
+ unsigned long long bind_id) {
const int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
const base::TraceTicks now = base::TraceTicks::Now();
- return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled,
- name, id, thread_id, now, flags);
+ return AddTraceEventWithThreadIdAndTimestamp(
+ phase, category_group_enabled, name, id, thread_id, now, flags, bind_id);
}
-template<class ARG1_TYPE>
+template <class ARG1_TYPE>
static inline base::trace_event::TraceEventHandle
AddTraceEventWithThreadIdAndTimestamp(
char phase,
@@ -1529,6 +1581,7 @@ AddTraceEventWithThreadIdAndTimestamp(
int thread_id,
const base::TraceTicks& timestamp,
unsigned int flags,
+ unsigned long long bind_id,
const char* arg1_name,
const ARG1_TYPE& arg1_val) {
const int num_args = 1;
@@ -1536,27 +1589,28 @@ AddTraceEventWithThreadIdAndTimestamp(
unsigned long long arg_values[1];
SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
- phase, category_group_enabled, name, id, thread_id, timestamp,
- num_args, &arg1_name, arg_types, arg_values, NULL, flags);
+ phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
+ &arg1_name, arg_types, arg_values, NULL, flags, bind_id);
}
-template<class ARG1_TYPE>
+template <class ARG1_TYPE>
static inline base::trace_event::TraceEventHandle AddTraceEvent(
char phase,
const unsigned char* category_group_enabled,
const char* name,
unsigned long long id,
unsigned int flags,
+ unsigned long long bind_id,
const char* arg1_name,
const ARG1_TYPE& arg1_val) {
int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
base::TraceTicks now = base::TraceTicks::Now();
return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled,
name, id, thread_id, now, flags,
- arg1_name, arg1_val);
+ bind_id, arg1_name, arg1_val);
}
-template<class ARG1_TYPE, class ARG2_TYPE>
+template <class ARG1_TYPE, class ARG2_TYPE>
static inline base::trace_event::TraceEventHandle
AddTraceEventWithThreadIdAndTimestamp(
char phase,
@@ -1566,6 +1620,7 @@ AddTraceEventWithThreadIdAndTimestamp(
int thread_id,
const base::TraceTicks& timestamp,
unsigned int flags,
+ unsigned long long bind_id,
const char* arg1_name,
const ARG1_TYPE& arg1_val,
const char* arg2_name,
@@ -1577,27 +1632,27 @@ AddTraceEventWithThreadIdAndTimestamp(
SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
- phase, category_group_enabled, name, id, thread_id, timestamp,
- num_args, arg_names, arg_types, arg_values, NULL, flags);
+ phase, category_group_enabled, name, id, thread_id, timestamp, num_args,
+ arg_names, arg_types, arg_values, NULL, flags, bind_id);
}
-template<class ARG1_TYPE, class ARG2_TYPE>
+template <class ARG1_TYPE, class ARG2_TYPE>
static inline base::trace_event::TraceEventHandle AddTraceEvent(
char phase,
const unsigned char* category_group_enabled,
const char* name,
unsigned long long id,
unsigned int flags,
+ unsigned long long bind_id,
const char* arg1_name,
const ARG1_TYPE& arg1_val,
const char* arg2_name,
const ARG2_TYPE& arg2_val) {
int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
base::TraceTicks now = base::TraceTicks::Now();
- return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled,
- name, id, thread_id, now, flags,
- arg1_name, arg1_val,
- arg2_name, arg2_val);
+ return AddTraceEventWithThreadIdAndTimestamp(
+ phase, category_group_enabled, name, id, thread_id, now, flags, bind_id,
+ arg1_name, arg1_val, arg2_name, arg2_val);
}
// Used by TRACE_EVENTx macros. Do not use directly.

Powered by Google App Engine
This is Rietveld 408576698