Index: base/debug/trace_event.h |
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h |
index 9f9ec1c7fdf17b4bcd7ab9db556cc0bc4684c4e7..838b2a6dd904b6f57f44bc6eccc0e61143a83194 100644 |
--- a/base/debug/trace_event.h |
+++ b/base/debug/trace_event.h |
@@ -123,6 +123,36 @@ |
// "arg1", std::string("string will be copied")); |
// |
// |
+// Convertable notes: |
+// Converting a large data type to a string can be costly. To help with this, |
+// the trace framework provides an interface ConvertableToTraceFormat. If you |
+// inherit from it and implement the AppendAsTraceFormat method the trace |
+// framework will call back to your object to convert a trace output time. This |
+// means, if the category for the event is disabled, the conversion will not |
+// happen. |
+// |
+// class MyData : public base::debug::ConvertableToTraceFormat { |
+// public: |
+// MyData() {} |
+// virtual ~MyData() {} |
+// virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { |
+// out->append("{\"foo\":1}"); |
+// } |
+// private: |
+// DISALLOW_COPY_AND_ASSIGN(MyData); |
+// }; |
+// |
+// scoped_ptr<MyData> data(new MyData()); |
+// TRACE_EVENT1("foo", "bar", "data", |
+// data.PassAs<base::debug::ConvertableToTraceFormat>()); |
+// |
+// The trace framework will take ownership if the passed pointer and it will |
+// be free'd when the trace buffer is flushed. |
+// |
+// Note, we only do the conversion when the buffer is flushed, so the provided |
+// data object should not be modified after it's passed to the trace framework. |
+// |
+// |
// Thread Safety: |
// A thread safe singleton and mutex are used for thread safety. Category |
// enabled flags are used to limit the performance impact when the system |
@@ -799,6 +829,7 @@ TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state2; |
#define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5)) |
#define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6)) |
#define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7)) |
+#define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8)) |
// Enum reflecting the scope of an INSTANT event. Must fit within |
// TRACE_EVENT_FLAG_SCOPE_MASK. |
@@ -906,9 +937,10 @@ class TraceStringWithCopy { |
#define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \ |
union_member, \ |
value_type_id) \ |
- static inline void SetTraceValue(actual_type arg, \ |
- unsigned char* type, \ |
- unsigned long long* value) { \ |
+ static inline void SetTraceValue( \ |
+ actual_type arg, \ |
+ unsigned char* type, \ |
+ unsigned long long* value) { \ |
TraceValueUnion type_value; \ |
type_value.union_member = arg; \ |
*type = value_type_id; \ |
@@ -917,9 +949,10 @@ class TraceStringWithCopy { |
// Simpler form for int types that can be safely casted. |
#define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, \ |
value_type_id) \ |
- static inline void SetTraceValue(actual_type arg, \ |
- unsigned char* type, \ |
- unsigned long long* value) { \ |
+ static inline void SetTraceValue( \ |
+ actual_type arg, \ |
+ unsigned char* type, \ |
+ unsigned long long* value) { \ |
*type = value_type_id; \ |
*value = static_cast<unsigned long long>(arg); \ |
} |
@@ -969,10 +1002,87 @@ static inline void AddTraceEventWithThreadIdAndTimestamp( |
unsigned long long id, |
int thread_id, |
const base::TimeTicks& timestamp, |
+ unsigned char flags, |
+ const char* arg1_name, |
+ scoped_ptr<base::debug::ConvertableToTraceFormat> arg1_val) { |
+ const int num_args = 1; |
+ unsigned char arg_types[1] = { TRACE_VALUE_TYPE_CONVERTABLE }; |
+ scoped_ptr<base::debug::ConvertableToTraceFormat> convertable_values[1]; |
+ convertable_values[0].reset(arg1_val.release()); |
+ |
+ TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
+ phase, category_enabled, name, id, thread_id, timestamp, |
+ num_args, &arg1_name, arg_types, NULL, convertable_values, flags); |
+} |
+ |
+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, |
+ scoped_ptr<base::debug::ConvertableToTraceFormat> arg1_val) { |
+ int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
+ base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); |
+ AddTraceEventWithThreadIdAndTimestamp(phase, category_enabled, name, id, |
+ thread_id, now, flags, arg1_name, |
+ arg1_val.Pass()); |
+} |
+ |
+static inline void AddTraceEventWithThreadIdAndTimestamp( |
+ char phase, |
+ const unsigned char* category_enabled, |
+ const char* name, |
+ unsigned long long id, |
+ int thread_id, |
+ const base::TimeTicks& timestamp, |
+ unsigned char flags, |
+ const char* arg1_name, |
+ scoped_ptr<base::debug::ConvertableToTraceFormat> arg1_val, |
+ const char* arg2_name, |
+ scoped_ptr<base::debug::ConvertableToTraceFormat> arg2_val) { |
+ const int num_args = 2; |
+ unsigned char arg_types[2] = |
+ { TRACE_VALUE_TYPE_CONVERTABLE, TRACE_VALUE_TYPE_CONVERTABLE }; |
+ scoped_ptr<base::debug::ConvertableToTraceFormat> convertable_values[2]; |
+ convertable_values[0].reset(arg1_val.release()); |
+ convertable_values[1].reset(arg2_val.release()); |
+ |
+ TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
+ phase, category_enabled, name, id, thread_id, timestamp, |
+ num_args, &arg1_name, arg_types, NULL, convertable_values, flags); |
+} |
+ |
+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, |
+ scoped_ptr<base::debug::ConvertableToTraceFormat> arg1_val, |
+ const char* arg2_name, |
+ scoped_ptr<base::debug::ConvertableToTraceFormat> arg2_val) { |
+ int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
+ base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); |
+ AddTraceEventWithThreadIdAndTimestamp(phase, category_enabled, name, id, |
+ thread_id, now, flags, |
+ arg1_name, arg1_val.Pass(), |
+ arg2_name, arg2_val.Pass()); |
+} |
+ |
+static inline void AddTraceEventWithThreadIdAndTimestamp( |
+ char phase, |
+ const unsigned char* category_enabled, |
+ const char* name, |
+ unsigned long long id, |
+ int thread_id, |
+ const base::TimeTicks& timestamp, |
unsigned char flags) { |
TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
phase, category_enabled, name, id, thread_id, timestamp, |
- kZeroNumArgs, NULL, NULL, NULL, flags); |
+ kZeroNumArgs, NULL, NULL, NULL, NULL, flags); |
} |
static inline void AddTraceEvent(char phase, |
@@ -1003,7 +1113,7 @@ static inline void AddTraceEventWithThreadIdAndTimestamp( |
SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); |
TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
phase, category_enabled, name, id, thread_id, timestamp, |
- num_args, &arg1_name, arg_types, arg_values, flags); |
+ num_args, &arg1_name, arg_types, arg_values, NULL, flags); |
} |
template<class ARG1_TYPE> |
@@ -1042,7 +1152,7 @@ static inline void AddTraceEventWithThreadIdAndTimestamp( |
SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); |
TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
phase, category_enabled, name, id, thread_id, timestamp, |
- num_args, arg_names, arg_types, arg_values, flags); |
+ num_args, arg_names, arg_types, arg_values, NULL, flags); |
} |
template<class ARG1_TYPE, class ARG2_TYPE> |
@@ -1088,7 +1198,7 @@ class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose { |
TRACE_EVENT_PHASE_END, |
p_data_->category_enabled, |
p_data_->name, kNoEventId, |
- kZeroNumArgs, NULL, NULL, NULL, |
+ kZeroNumArgs, NULL, NULL, NULL, NULL, |
TRACE_EVENT_FLAG_NONE); |
} |
} |