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

Unified Diff: base/debug/trace_event.h

Issue 11366109: Adding raw tracing to trace framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changing AddTraceEvent API to always accept a tid and timestamp. Created 8 years 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/debug/trace_event.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/trace_event.h
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h
index 58bd02370bff9bbefb4f02c1aa5c4535d33112b4..9f9bde8890cebe48af3810254d0a44ead69b2f5c 100644
--- a/base/debug/trace_event.h
+++ b/base/debug/trace_event.h
@@ -265,6 +265,23 @@
category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
arg2_name, arg2_val)
+// Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided.
+// - |id| is used to match the _BEGIN event with the _END event.
+// Events are considered to match if their category, name and id values all
+// match. |id| must either be a pointer or an integer value up to 64 bits. If
+// it's a pointer, the bits will be xored with a hash of the process ID so
+// that the same pointer on two different processes will not collide.
+#define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category, \
+ name, id, tid, ts) \
+ INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
+ TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, tid, ts, \
+ TRACE_EVENT_FLAG_NONE)
+#define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \
+ category, name, id, tid, ts) \
+ INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
+ TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, tid, ts, \
+ TRACE_EVENT_FLAG_COPY)
+
// Records a single END event for "name" immediately. If the category
// is not enabled, then this does nothing.
// - category and name strings must have application lifetime (statics or
@@ -292,6 +309,23 @@
category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \
arg2_name, arg2_val)
+// Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided.
+// - |id| is used to match the _BEGIN event with the _END event.
+// Events are considered to match if their category, name and id values all
+// match. |id| must either be a pointer or an integer value up to 64 bits. If
+// it's a pointer, the bits will be xored with a hash of the process ID so
+// that the same pointer on two different processes will not collide.
+#define TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0(category, \
+ name, id, tid, ts) \
+ INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
+ TRACE_EVENT_PHASE_ASYNC_END, category, name, id, tid, ts, \
+ TRACE_EVENT_FLAG_NONE)
+#define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \
+ category, name, id, tid, ts) \
+ INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
+ TRACE_EVENT_PHASE_ASYNC_END, category, name, id, tid, ts, \
+ TRACE_EVENT_FLAG_COPY)
+
// Records the value of a counter called "name" immediately. Value
// must be representable as a 32 bit integer.
// - category and name strings must have application lifetime (statics or
@@ -561,12 +595,15 @@
#define TRACE_EVENT_API_GET_CATEGORY_ENABLED \
base::debug::TraceLog::GetCategoryEnabled
-// Add a trace event to the platform tracing system.
-// void TRACE_EVENT_API_ADD_TRACE_EVENT(
+// Add a trace event to the platform tracing system. Returns thresholdBeginId
+// for use in a corresponding end TRACE_EVENT_API_ADD_TRACE_EVENT call.
+// int TRACE_EVENT_API_ADD_TRACE_EVENT(
// char phase,
// const unsigned char* category_enabled,
// const char* name,
// unsigned long long id,
+// int thread_id,
+// int64 timestamp,
// int num_args,
// const char** arg_names,
// const unsigned char* arg_types,
@@ -650,6 +687,23 @@
} \
} 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, \
+ name, id, tid, ts, flags, ...) \
+ do { \
+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \
+ if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \
+ unsigned char 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(catstatic), \
+ name, trace_event_trace_id.data(), tid, ts, \
+ trace_event_flags, ##__VA_ARGS__); \
+ } \
+ } while (0)
+
// Notes regarding the following definitions:
// New values can be added and propagated to third party libraries, but existing
// definitions must never be changed, because third party libraries may use old
@@ -836,44 +890,78 @@ static inline void SetTraceValue(const std::string& arg,
// these procedures.
static inline void AddTraceEvent(char phase,
- const unsigned char* category_enabled,
- const char* name,
- unsigned long long id,
- unsigned char flags) {
+ const unsigned char* category_enabled,
+ const char* name,
+ unsigned long long id,
+ int thread_id,
+ int64 timestamp,
+ unsigned char flags) {
TRACE_EVENT_API_ADD_TRACE_EVENT(
- phase, category_enabled, name, id,
+ phase, category_enabled, name, id, thread_id, timestamp,
kZeroNumArgs, NULL, NULL, NULL,
flags);
}
+static inline void AddTraceEvent(char phase,
+ const unsigned char* category_enabled,
+ const char* name,
+ unsigned long long id,
+ unsigned char flags) {
+ int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
+ base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime() -
nduca 2012/12/20 20:19:27 Can we take off the TimeOffset inside the TraceLog
dsinclair 2013/01/28 16:45:07 Done.
+ base::debug::TraceLog::GetInstance()->GetTimeOffset();
+ AddTraceEvent(phase, category_enabled, name, id, thread_id,
+ now.ToInternalValue(), flags);
+}
+
template<class ARG1_TYPE>
static inline void AddTraceEvent(char phase,
- const unsigned char* category_enabled,
- const char* name,
- unsigned long long id,
- unsigned char flags,
- const char* arg1_name,
- const ARG1_TYPE& arg1_val) {
+ const unsigned char* category_enabled,
+ const char* name,
+ unsigned long long id,
+ int thread_id,
+ int64 timestamp,
+ unsigned char flags,
+ const char* arg1_name,
+ const ARG1_TYPE& arg1_val) {
const int num_args = 1;
unsigned char arg_types[1];
unsigned long long arg_values[1];
SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
TRACE_EVENT_API_ADD_TRACE_EVENT(
- phase, category_enabled, name, id,
+ phase, category_enabled, name, id, thread_id, timestamp,
num_args, &arg1_name, arg_types, arg_values,
flags);
}
+template<class ARG1_TYPE>
+static inline void AddTraceEvent(char phase,
+ const unsigned char* category_enabled,
+ const char* name,
+ unsigned long long id,
+ unsigned char flags,
+ const char* arg1_name,
+ const ARG1_TYPE& arg1_val) {
+ int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
+ base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime() -
+ base::debug::TraceLog::GetInstance()->GetTimeOffset();
+ AddTraceEvent(phase, category_enabled, name, id, thread_id,
+ now.ToInternalValue(), flags,
+ arg1_name, arg1_val);
+}
+
template<class ARG1_TYPE, class ARG2_TYPE>
static inline void AddTraceEvent(char phase,
- const unsigned char* category_enabled,
- const char* name,
- unsigned long long id,
- unsigned char flags,
- const char* arg1_name,
- const ARG1_TYPE& arg1_val,
- const char* arg2_name,
- const ARG2_TYPE& arg2_val) {
+ const unsigned char* category_enabled,
+ const char* name,
+ unsigned long long id,
+ int thread_id,
+ int64 timestamp,
+ unsigned char flags,
+ const char* arg1_name,
+ const ARG1_TYPE& arg1_val,
+ const char* arg2_name,
+ const ARG2_TYPE& arg2_val) {
const int num_args = 2;
const char* arg_names[2] = { arg1_name, arg2_name };
unsigned char arg_types[2];
@@ -881,11 +969,29 @@ static inline void AddTraceEvent(char phase,
SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
TRACE_EVENT_API_ADD_TRACE_EVENT(
- phase, category_enabled, name, id,
+ phase, category_enabled, name, id, thread_id, timestamp,
num_args, arg_names, arg_types, arg_values,
flags);
}
+template<class ARG1_TYPE, class ARG2_TYPE>
+static inline void AddTraceEvent(char phase,
+ const unsigned char* category_enabled,
+ const char* name,
+ unsigned long long id,
+ unsigned char flags,
+ 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::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime() -
+ base::debug::TraceLog::GetInstance()->GetTimeOffset();
+ AddTraceEvent(phase, category_enabled, name, id, thread_id,
+ now.ToInternalValue(), flags,
+ arg1_name, arg1_val, arg2_name, arg2_val);
+}
+
// Used by TRACE_EVENTx macro. Do not use directly.
class BASE_EXPORT TraceEndOnScopeClose {
public:
« no previous file with comments | « no previous file | base/debug/trace_event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698