| Index: base/debug/trace_event.h
|
| diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h
|
| index 0fcdaff165927c405a33d1dd012cc8d2680bf86f..2b6b9e15f4ec50bb586e290acaad6efdde659652 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,12 @@ class BASE_EXPORT TraceValue {
|
| TraceValue(const char* rhs) : type_(TRACE_TYPE_STRING) {
|
| value_.as_string = rhs;
|
| }
|
| + // Use this if your string is already global and does not need to be copied.
|
| + static TraceValue StaticString(const char* rhs) {
|
| + TraceValue tv(rhs);
|
| + tv.type_ = TRACE_TYPE_STATIC_STRING;
|
| + return tv;
|
| + }
|
|
|
| void AppendAsJSON(std::string* out) const;
|
|
|
| @@ -382,7 +394,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() {
|
| @@ -431,6 +443,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 +522,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.
|
|
|