Chromium Code Reviews| Index: base/debug/trace_event.h |
| diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h |
| index 0fcdaff165927c405a33d1dd012cc8d2680bf86f..3873d870125d969af11a7003c9326ca41472f3a0 100644 |
| --- a/base/debug/trace_event.h |
| +++ b/base/debug/trace_event.h |
| @@ -96,6 +96,11 @@ |
| #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| #include "base/timer.h" |
| +// Short hand convenience macro for specifying unscoped strings as argument |
| +// values to avoid allocating/copying. The string pointer must remain valid |
| +// until tracing is disabled. |
| +#define TRACE_STATIC_STR(str) base::debug::TraceValue::StaticString(str) |
| + |
| // Older style trace macros with explicit id and extra data |
| // Only these macros result in publishing data to ETW as currently implemented. |
| #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ |
| @@ -313,7 +318,8 @@ class BASE_EXPORT TraceValue { |
| TRACE_TYPE_INT, |
| TRACE_TYPE_DOUBLE, |
| TRACE_TYPE_POINTER, |
| - TRACE_TYPE_STRING |
| + TRACE_TYPE_STRING, |
| + TRACE_TYPE_STATIC_STRING |
| }; |
| TraceValue() : type_(TRACE_TYPE_UNDEFINED) { |
| @@ -355,6 +361,10 @@ class BASE_EXPORT TraceValue { |
| TraceValue(const char* rhs) : type_(TRACE_TYPE_STRING) { |
| value_.as_string = rhs; |
| } |
| + // User this if your string is already global and does not need to be copied. |
| + static TraceValue StaticString(const char* rhs) { |
| + return TraceValue(rhs, 0); |
|
scheib
2011/08/29 21:46:09
nit: Can you just call the string constructor and
jbates
2011/08/29 22:22:20
Done.
|
| + } |
| void AppendAsJSON(std::string* out) const; |
| @@ -382,7 +392,7 @@ class BASE_EXPORT TraceValue { |
| return value_.as_pointer; |
| } |
| const char* as_string() const { |
| - DCHECK_EQ(TRACE_TYPE_STRING, type_); |
| + DCHECK(type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING); |
| return value_.as_string; |
| } |
| const char** as_assignable_string() { |
| @@ -400,6 +410,11 @@ class BASE_EXPORT TraceValue { |
| const char* as_string; |
| }; |
| + TraceValue(const char* rhs, int ignore) : type_(TRACE_TYPE_STATIC_STRING) { |
| + (void)ignore; |
| + value_.as_string = rhs; |
| + } |
| + |
| Type type_; |
| Value value_; |
| }; |
| @@ -431,6 +446,14 @@ class TraceEvent { |
| TimeTicks timestamp() const { return timestamp_; } |
| + // Exposed for unittesting: |
| + |
| + const base::RefCountedString* parameter_copy_storage() const { |
| + return parameter_copy_storage_.get(); |
| + } |
| + |
| + const char* name() const { return name_; } |
| + |
| private: |
| unsigned long process_id_; |
| unsigned long thread_id_; |
| @@ -502,10 +525,18 @@ class BASE_EXPORT TraceLog { |
| AddTraceEventEtw(phase, name, id, extra.c_str()); |
| } |
| - // Exposed for unittesting only, allows resurrecting our |
| - // singleton instance post-AtExit processing. |
| + // Exposed for unittesting: |
| + |
| + // Allows resurrecting our singleton instance post-AtExit processing. |
| static void Resurrect(); |
| + // Allow tests to inspect TraceEvents. |
| + size_t GetEventsSize() const { return logged_events_.size(); } |
| + const TraceEvent& GetEventAt(size_t index) const { |
| + DCHECK(index < logged_events_.size()); |
| + return logged_events_[index]; |
| + } |
| + |
| private: |
| // This allows constructor and destructor to be private and usable only |
| // by the Singleton class. |