diff options
author | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 17:17:38 +0000 |
---|---|---|
committer | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 17:17:38 +0000 |
commit | 7e98cfa49189fa6ce77a729e148be50760dca9ce (patch) | |
tree | abebe7f52b4678251cdb9fd8f3eebd3901773a76 /base | |
parent | 7d2c7f9fba504cd9e07d72804b09df0a04c24527 (diff) | |
download | chromium_src-7e98cfa49189fa6ce77a729e148be50760dca9ce.zip chromium_src-7e98cfa49189fa6ce77a729e148be50760dca9ce.tar.gz chromium_src-7e98cfa49189fa6ce77a729e148be50760dca9ce.tar.bz2 |
trace_event: distinguish between scoped begin/end and global start/finish events
BUG=100131
Review URL: http://codereview.chromium.org/8590015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/debug/trace_event.cc | 185 | ||||
-rw-r--r-- | base/debug/trace_event.h | 239 | ||||
-rw-r--r-- | base/debug/trace_event_unittest.cc | 109 | ||||
-rw-r--r-- | base/debug/trace_event_win.h | 2 | ||||
-rw-r--r-- | base/debug/trace_event_win_unittest.cc | 10 | ||||
-rw-r--r-- | base/test/trace_event_analyzer.cc | 8 | ||||
-rw-r--r-- | base/test/trace_event_analyzer.h | 2 | ||||
-rw-r--r-- | base/test/trace_event_analyzer_unittest.cc | 4 |
8 files changed, 388 insertions, 171 deletions
diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc index a7ea89d..5be1557 100644 --- a/base/debug/trace_event.cc +++ b/base/debug/trace_event.cc @@ -43,6 +43,14 @@ const size_t kTraceEventBatchSize = 1000; namespace { +// Specify these values when the corresponding argument of AddTraceEvent is not +// used. +static const char* kNoArgName = NULL; +static const int kNoArgValue = 0; +static const int kNoThreshholdBeginId = -1; +static const int64 kNoThresholdValue = 0; +static const int kNoEventId = 0; + TraceCategory g_categories[TRACE_EVENT_MAX_CATEGORIES] = { { "tracing already shutdown", false }, { "tracing categories exhausted; must increase TRACE_EVENT_MAX_CATEGORIES", @@ -72,32 +80,26 @@ LazyInstance<ThreadLocalPointer<const char>, //////////////////////////////////////////////////////////////////////////////// void TraceValue::AppendAsJSON(std::string* out) const { - char temp_string[128]; std::string::size_type start_pos; switch (type_) { case TRACE_TYPE_BOOL: *out += as_bool() ? "true" : "false"; break; case TRACE_TYPE_UINT: - base::snprintf(temp_string, arraysize(temp_string), "%llu", - static_cast<unsigned long long>(as_uint())); - *out += temp_string; + StringAppendF(out, "%" PRIu64, as_uint()); break; case TRACE_TYPE_INT: - base::snprintf(temp_string, arraysize(temp_string), "%lld", - static_cast<long long>(as_int())); - *out += temp_string; + StringAppendF(out, "%" PRId64, as_int()); break; case TRACE_TYPE_DOUBLE: - base::snprintf(temp_string, arraysize(temp_string), "%f", as_double()); - *out += temp_string; + StringAppendF(out, "%f", as_double()); break; case TRACE_TYPE_POINTER: - base::snprintf(temp_string, arraysize(temp_string), "%llu", - static_cast<unsigned long long>( - reinterpret_cast<intptr_t>( - as_pointer()))); - *out += temp_string; + // JSON only supports double and int numbers. + // So as not to lose bits from a 64-bit pointer, output as a hex string. + StringAppendF(out, "\"%" PRIx64 "\"", static_cast<uint64>( + reinterpret_cast<intptr_t>( + as_pointer()))); break; case TRACE_TYPE_STRING: case TRACE_TYPE_STATIC_STRING: @@ -121,6 +123,17 @@ void TraceValue::AppendAsJSON(std::string* out) const { //////////////////////////////////////////////////////////////////////////////// // +// TraceID +// +//////////////////////////////////////////////////////////////////////////////// + +TraceID::TraceID(void* rhs) { + data_ = base::debug::TraceLog::GetInstance()->GetIntraProcessID( + static_cast<uint64>(reinterpret_cast<uintptr_t>(rhs))); +} + +//////////////////////////////////////////////////////////////////////////////// +// // TraceEvent // //////////////////////////////////////////////////////////////////////////////// @@ -145,36 +158,39 @@ void CopyTraceEventParameter(char** buffer, } // namespace TraceEvent::TraceEvent() - : process_id_(0), + : id_(0u), + category_(NULL), + name_(NULL), thread_id_(0), phase_(TRACE_EVENT_PHASE_BEGIN), - category_(NULL), - name_(NULL) { + flags_(0) { arg_names_[0] = NULL; arg_names_[1] = NULL; } -TraceEvent::TraceEvent(unsigned long process_id, - unsigned long thread_id, +TraceEvent::TraceEvent(int thread_id, TimeTicks timestamp, TraceEventPhase phase, const TraceCategory* category, const char* name, + TraceID id, const char* arg1_name, const TraceValue& arg1_val, const char* arg2_name, const TraceValue& arg2_val, - bool copy) - : process_id_(process_id), + TraceEventFlags flags) + : timestamp_(timestamp), + id_(id), + category_(category), + name_(name), thread_id_(thread_id), - timestamp_(timestamp), phase_(phase), - category_(category), - name_(name) { + flags_(flags) { COMPILE_ASSERT(kTraceMaxNumArgs == 2, TraceEvent_arg_count_out_of_sync); arg_names_[0] = arg1_name; arg_names_[1] = arg2_name; arg_values_[0] = arg1_val; arg_values_[1] = arg2_val; + bool copy = !!(flags & TRACE_EVENT_FLAG_COPY); size_t alloc_size = 0; if (copy) { alloc_size += GetAllocLength(name); @@ -213,42 +229,6 @@ TraceEvent::TraceEvent(unsigned long process_id, TraceEvent::~TraceEvent() { } -const char* TraceEvent::GetPhaseString(TraceEventPhase phase) { - switch(phase) { - case TRACE_EVENT_PHASE_BEGIN: - return "B"; - case TRACE_EVENT_PHASE_INSTANT: - return "I"; - case TRACE_EVENT_PHASE_END: - return "E"; - case TRACE_EVENT_PHASE_METADATA: - return "M"; - case TRACE_EVENT_PHASE_COUNTER: - return "C"; - default: - NOTREACHED() << "Invalid phase argument"; - return "?"; - } -} - -TraceEventPhase TraceEvent::GetPhase(const char* phase) { - switch(*phase) { - case 'B': - return TRACE_EVENT_PHASE_BEGIN; - case 'I': - return TRACE_EVENT_PHASE_INSTANT; - case 'E': - return TRACE_EVENT_PHASE_END; - case 'M': - return TRACE_EVENT_PHASE_METADATA; - case 'C': - return TRACE_EVENT_PHASE_COUNTER; - default: - NOTREACHED() << "Invalid phase name"; - return TRACE_EVENT_PHASE_METADATA; - } -} - void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events, size_t start, size_t count, @@ -261,18 +241,19 @@ void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events, } void TraceEvent::AppendAsJSON(std::string* out) const { - const char* phase_str = GetPhaseString(phase_); + const char phase_char = GetPhaseChar(phase_); int64 time_int64 = timestamp_.ToInternalValue(); + int process_id = TraceLog::GetInstance()->process_id(); // Category name checked at category creation time. DCHECK(!strchr(name_, '"')); StringAppendF(out, - "{\"cat\":\"%s\",\"pid\":%i,\"tid\":%i,\"ts\":%lld," - "\"ph\":\"%s\",\"name\":\"%s\",\"args\":{", + "{\"cat\":\"%s\",\"pid\":%i,\"tid\":%i,\"ts\":%" PRId64 "," + "\"ph\":\"%c\",\"name\":\"%s\",\"args\":{", category_->name, - static_cast<int>(process_id_), - static_cast<int>(thread_id_), - static_cast<long long>(time_int64), - phase_str, + process_id, + thread_id_, + time_int64, + phase_char, name_); // Output argument names and values, stop at first NULL argument name. @@ -284,7 +265,13 @@ void TraceEvent::AppendAsJSON(std::string* out) const { *out += "\":"; arg_values_[i].AppendAsJSON(out); } - *out += "}}"; + *out += "}"; + + // If id_ is set, print it out as a hex string so we don't loose any + // bits (it might be a 64-bit pointer). + if (flags_ & TRACE_EVENT_FLAG_HAS_ID) + StringAppendF(out, ",\"id\":\"%" PRIx64 "\"", id_.data()); + *out += "}"; } //////////////////////////////////////////////////////////////////////////////// @@ -342,6 +329,7 @@ TraceLog* TraceLog::GetInstance() { TraceLog::TraceLog() : enabled_(false) { + SetProcessID(static_cast<int>(base::GetCurrentProcId())); } TraceLog::~TraceLog() { @@ -533,11 +521,12 @@ void TraceLog::Flush() { int TraceLog::AddTraceEvent(TraceEventPhase phase, const TraceCategory* category, const char* name, + TraceID id, const char* arg1_name, TraceValue arg1_val, const char* arg2_name, TraceValue arg2_val, int threshold_begin_id, int64 threshold, - EventFlags flags) { + TraceEventFlags flags) { DCHECK(name); TimeTicks now = TimeTicks::HighResNow(); BufferFullCallback buffer_full_callback_copy; @@ -549,7 +538,7 @@ int TraceLog::AddTraceEvent(TraceEventPhase phase, if (logged_events_.size() >= kTraceEventBufferSize) return -1; - PlatformThreadId thread_id = PlatformThread::CurrentId(); + int thread_id = static_cast<int>(PlatformThread::CurrentId()); const char* new_name = PlatformThread::GetName(); // Check if the thread name has been set or changed since the previous @@ -559,7 +548,7 @@ int TraceLog::AddTraceEvent(TraceEventPhase phase, if (new_name != g_current_thread_name.Get().Get() && new_name && *new_name) { g_current_thread_name.Get().Set(new_name); - base::hash_map<PlatformThreadId, std::string>::iterator existing_name = + base::hash_map<int, std::string>::iterator existing_name = thread_names_.find(thread_id); if (existing_name == thread_names_.end()) { // This is a new thread id, and a new name. @@ -580,7 +569,7 @@ int TraceLog::AddTraceEvent(TraceEventPhase phase, } if (threshold_begin_id > -1) { - DCHECK(phase == base::debug::TRACE_EVENT_PHASE_END); + DCHECK(phase == TRACE_EVENT_PHASE_END); size_t begin_i = static_cast<size_t>(threshold_begin_id); // Return now if there has been a flush since the begin event was posted. if (begin_i >= logged_events_.size()) @@ -597,12 +586,11 @@ int TraceLog::AddTraceEvent(TraceEventPhase phase, } ret_begin_id = static_cast<int>(logged_events_.size()); logged_events_.push_back( - TraceEvent(static_cast<unsigned long>(base::GetCurrentProcId()), - thread_id, - now, phase, category, name, + TraceEvent(thread_id, + now, phase, category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, - flags & EVENT_FLAG_COPY)); + flags)); if (logged_events_.size() == kTraceEventBufferSize) { buffer_full_callback_copy = buffer_full_callback_; @@ -624,7 +612,7 @@ void TraceLog::AddTraceEventEtw(TraceEventPhase phase, #endif INTERNAL_TRACE_EVENT_ADD(phase, "ETW Trace Event", name, "id", id, "extra", TRACE_STR_COPY(extra), - base::debug::TraceLog::EVENT_FLAG_COPY); + TRACE_EVENT_FLAG_COPY); } void TraceLog::AddTraceEventEtw(TraceEventPhase phase, @@ -637,17 +625,18 @@ void TraceLog::AddTraceEventEtw(TraceEventPhase phase, #endif INTERNAL_TRACE_EVENT_ADD(phase, "ETW Trace Event", name, "id", id, "extra", extra, - base::debug::TraceLog::EVENT_FLAG_COPY); + TRACE_EVENT_FLAG_COPY); } int TraceLog::AddCounterEvent(const TraceCategory* category, const char* name, const char* value1_name, int32 value1_val, const char* value2_name, int32 value2_val, - EventFlags flags) { + TraceEventFlags flags) { return AddTraceEvent(TRACE_EVENT_PHASE_COUNTER, category, name, + 0, value1_name, value1_val, value2_name, value2_val, -1, 0, @@ -656,19 +645,17 @@ int TraceLog::AddCounterEvent(const TraceCategory* category, void TraceLog::AddCurrentMetadataEvents() { lock_.AssertAcquired(); - for(base::hash_map<PlatformThreadId, std::string>::iterator it = - thread_names_.begin(); + for(base::hash_map<int, std::string>::iterator it = thread_names_.begin(); it != thread_names_.end(); it++) { if (!it->second.empty()) logged_events_.push_back( - TraceEvent(static_cast<unsigned long>(base::GetCurrentProcId()), - it->first, - TimeTicks(), base::debug::TRACE_EVENT_PHASE_METADATA, - g_category_metadata, "thread_name", + TraceEvent(it->first, + TimeTicks(), TRACE_EVENT_PHASE_METADATA, + g_category_metadata, "thread_name", 0, "name", it->second, NULL, 0, - false)); + TRACE_EVENT_FLAG_NONE)); } } @@ -680,6 +667,16 @@ void TraceLog::Resurrect() { StaticMemorySingletonTraits<TraceLog>::Resurrect(); } +void TraceLog::SetProcessID(int process_id) { + process_id_ = process_id; + // Create a FNV hash from the process ID for XORing. + // See http://isthe.com/chongo/tech/comp/fnv/ for algorithm details. + uint64 offset_basis = 14695981039346656037ull; + uint64 fnv_prime = 1099511628211ull; + unsigned long long pid = static_cast<unsigned long long>(process_id_); + process_id_hash_ = (offset_basis ^ pid) * fnv_prime; +} + namespace internal { void TraceEndOnScopeClose::Initialize(const TraceCategory* category, @@ -693,11 +690,11 @@ void TraceEndOnScopeClose::AddEventIfEnabled() { // Only called when p_data_ is non-null. if (p_data_->category->enabled) { base::debug::TraceLog::GetInstance()->AddTraceEvent( - base::debug::TRACE_EVENT_PHASE_END, + TRACE_EVENT_PHASE_END, p_data_->category, - p_data_->name, - NULL, 0, NULL, 0, - -1, 0, TraceLog::EVENT_FLAG_NONE); + p_data_->name, kNoEventId, + kNoArgName, kNoArgValue, kNoArgName, kNoArgValue, + kNoThreshholdBeginId, kNoThresholdValue, TRACE_EVENT_FLAG_NONE); } } @@ -716,12 +713,12 @@ void TraceEndOnScopeCloseThreshold::AddEventIfEnabled() { // Only called when p_data_ is non-null. if (p_data_->category->enabled) { base::debug::TraceLog::GetInstance()->AddTraceEvent( - base::debug::TRACE_EVENT_PHASE_END, + TRACE_EVENT_PHASE_END, p_data_->category, - p_data_->name, - NULL, 0, NULL, 0, + p_data_->name, kNoEventId, + kNoArgName, kNoArgValue, kNoArgName, kNoArgValue, p_data_->threshold_begin_id, p_data_->threshold, - TraceLog::EVENT_FLAG_NONE); + TRACE_EVENT_FLAG_NONE); } } diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h index e581094..c6d62bc 100644 --- a/base/debug/trace_event.h +++ b/base/debug/trace_event.h @@ -12,10 +12,13 @@ // implicitly with a string. For example: // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") // -// Events can be INSTANT, or can be pairs of BEGIN and END: +// Events can be INSTANT, or can be pairs of BEGIN and END in the same scope: // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly") // doSomethingCostly() // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly") +// Note: our tools can't always determine the correct BEGIN/END pairs unless +// these are used in the same scope. Use START/FINISH macros if you need them +// to be in separate scopes. // // A common use case is to trace entire function scopes. This // issues a trace BEGIN and END automatically: @@ -34,6 +37,31 @@ // The trace system will automatically add to this information the // current process id, thread id, and a timestamp in microseconds. // +// To trace an asynchronous procedure such as an IPC send/receive, use START and +// FINISH: +// [single threaded sender code] +// static int send_count = 0; +// ++send_count; +// TRACE_EVENT_START0("ipc", "message", send_count); +// Send(new MyMessage(send_count)); +// [receive code] +// void OnMyMessage(send_count) { +// TRACE_EVENT_FINISH0("ipc", "message", send_count); +// } +// The third parameter is a unique ID to match START/FINISH pairs. +// START and FINISH can occur on any thread of any traced process. Pointers can +// be used for the ID parameter, and they will be mangled internally so that +// the same pointer on two different processes will not match. For example: +// class MyTracedClass { +// public: +// MyTracedClass() { +// TRACE_EVENT_START0("category", "MyTracedClass", this); +// } +// ~MyTracedClass() { +// TRACE_EVENT_FINISH0("category", "MyTracedClass", this); +// } +// } +// // Trace event also supports counters, which is a way to track a quantity // as it varies over time. Counters are created with the following macro: // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter", g_myCounterValue); @@ -137,17 +165,17 @@ // Only these macros result in publishing data to ETW as currently implemented. #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ base::debug::TraceLog::AddTraceEventEtw( \ - base::debug::TRACE_EVENT_PHASE_BEGIN, \ + TRACE_EVENT_PHASE_BEGIN, \ name, reinterpret_cast<const void*>(id), extra) #define TRACE_EVENT_END_ETW(name, id, extra) \ base::debug::TraceLog::AddTraceEventEtw( \ - base::debug::TRACE_EVENT_PHASE_END, \ + TRACE_EVENT_PHASE_END, \ name, reinterpret_cast<const void*>(id), extra) #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \ base::debug::TraceLog::AddTraceEventEtw( \ - base::debug::TRACE_EVENT_PHASE_INSTANT, \ + TRACE_EVENT_PHASE_INSTANT, \ name, reinterpret_cast<const void*>(id), extra) // Records a pair of begin and end events called "name" for the current @@ -190,20 +218,20 @@ TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) #define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_INSTANT, \ + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ - base::debug::TraceLog::EVENT_FLAG_NONE) + TRACE_EVENT_FLAG_NONE) #define TRACE_EVENT_COPY_INSTANT0(category, name) \ TRACE_EVENT_COPY_INSTANT1(category, name, NULL, 0) #define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \ TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) #define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \ arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_INSTANT, \ + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ category, name, \ arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ - base::debug::TraceLog::EVENT_FLAG_COPY) + TRACE_EVENT_FLAG_COPY) // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 // associated arguments. If the category is not enabled, then this @@ -216,20 +244,20 @@ TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) #define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, \ arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_BEGIN, \ + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ - base::debug::TraceLog::EVENT_FLAG_NONE) + TRACE_EVENT_FLAG_NONE) #define TRACE_EVENT_COPY_BEGIN0(category, name) \ TRACE_EVENT_COPY_BEGIN1(category, name, NULL, 0) #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_BEGIN, \ + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ category, name, \ arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ - base::debug::TraceLog::EVENT_FLAG_COPY) + TRACE_EVENT_FLAG_COPY) // Records a single END event for "name" immediately. If the category // is not enabled, then this does nothing. @@ -241,20 +269,20 @@ TRACE_EVENT_END2(category, name, arg1_name, arg1_val, NULL, 0) #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_END, \ + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ - base::debug::TraceLog::EVENT_FLAG_NONE) + TRACE_EVENT_FLAG_NONE) #define TRACE_EVENT_COPY_END0(category, name) \ TRACE_EVENT_COPY_END1(category, name, NULL, 0) #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, NULL, 0) #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_END, \ + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ category, name, \ arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ - base::debug::TraceLog::EVENT_FLAG_COPY) + TRACE_EVENT_FLAG_COPY) // Time threshold event: // Only record the event if the duration is greater than the specified @@ -293,14 +321,68 @@ value2_name, value2_val) \ INTERNAL_TRACE_EVENT_ADD_COUNTER( \ category, name, value1_name, value1_val, value2_name, value2_val, \ - base::debug::TraceLog::EVENT_FLAG_NONE) + TRACE_EVENT_FLAG_NONE) #define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \ value2_name, value2_val) \ INTERNAL_TRACE_EVENT_ADD_COUNTER( \ category, name, \ value1_name, value1_val, \ value2_name, value2_val, \ - base::debug::TraceLog::EVENT_FLAG_COPY) + TRACE_EVENT_FLAG_COPY) + + +// Records a single START event called "name" immediately, with 0, 1 or 2 +// associated arguments. If the category is not enabled, then this +// does nothing. +// - category and name strings must have application lifetime (statics or +// literals). They may not include " chars. +// - |id| is used to match the START event with the FINISH event. It 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_START0(category, name, id) \ + TRACE_EVENT_START1(category, name, id, NULL, 0) +#define TRACE_EVENT_START1(category, name, id, arg1_name, arg1_val) \ + TRACE_EVENT_START2(category, name, id, arg1_name, arg1_val, NULL, 0) +#define TRACE_EVENT_START2(category, name, id, arg1_name, arg1_val, \ + arg2_name, arg2_val) \ + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ + category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, \ + TRACE_EVENT_FLAG_HAS_ID) +#define TRACE_EVENT_COPY_START0(category, name, id) \ + TRACE_EVENT_COPY_START1(category, name, id, NULL, 0) +#define TRACE_EVENT_COPY_START1(category, name, id, arg1_name, arg1_val) \ + TRACE_EVENT_COPY_START2(category, name, id, arg1_name, arg1_val, NULL, 0) +#define TRACE_EVENT_COPY_START2(category, name, id, arg1_name, arg1_val, \ + arg2_name, arg2_val) \ + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ + category, name, id, \ + arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ + arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ + TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) + +// Records a single FINISH event for "name" immediately. If the category +// is not enabled, then this does nothing. +#define TRACE_EVENT_FINISH0(category, name, id) \ + TRACE_EVENT_FINISH1(category, name, id, NULL, 0) +#define TRACE_EVENT_FINISH1(category, name, id, arg1_name, arg1_val) \ + TRACE_EVENT_FINISH2(category, name, id, arg1_name, arg1_val, NULL, 0) +#define TRACE_EVENT_FINISH2(category, name, id, arg1_name, arg1_val, \ + arg2_name, arg2_val) \ + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ + category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, \ + TRACE_EVENT_FLAG_HAS_ID) +#define TRACE_EVENT_COPY_FINISH0(category, name, id) \ + TRACE_EVENT_COPY_FINISH1(category, name, id, NULL, 0) +#define TRACE_EVENT_COPY_FINISH1(category, name, id, arg1_name, arg1_val) \ + TRACE_EVENT_COPY_FINISH2(category, name, id, arg1_name, arg1_val, NULL, 0) +#define TRACE_EVENT_COPY_FINISH2(category, name, id, arg1_name, arg1_val, \ + arg2_name, arg2_val) \ + INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ + category, name, id, \ + arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ + arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ + TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) // Implementation detail: trace event macros create temporary variables @@ -324,7 +406,7 @@ INTERNAL_TRACE_EVENT_UID(catstatic) = \ base::debug::TraceLog::GetCategory(category); -// Implementation detail: internal macro to create static category and add begin +// Implementation detail: internal macro to create static category and add // event if the category is enabled. #define INTERNAL_TRACE_EVENT_ADD( \ phase, category, name, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ @@ -332,7 +414,7 @@ if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ base::debug::TraceLog::GetInstance()->AddTraceEvent( \ phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ - name, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ + name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ } // Implementation detail: internal macro to create static category and @@ -356,10 +438,10 @@ INTERNAL_TRACE_EVENT_UID(profileScope); \ if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ base::debug::TraceLog::GetInstance()->AddTraceEvent( \ - base::debug::TRACE_EVENT_PHASE_BEGIN, \ + TRACE_EVENT_PHASE_BEGIN, \ INTERNAL_TRACE_EVENT_UID(catstatic), \ - name, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ - base::debug::TraceLog::EVENT_FLAG_NONE); \ + name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ + TRACE_EVENT_FLAG_NONE); \ INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ INTERNAL_TRACE_EVENT_UID(catstatic), name); \ } @@ -375,15 +457,26 @@ if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \ base::debug::TraceLog::GetInstance()->AddTraceEvent( \ - base::debug::TRACE_EVENT_PHASE_BEGIN, \ + TRACE_EVENT_PHASE_BEGIN, \ INTERNAL_TRACE_EVENT_UID(catstatic), \ - name, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ - base::debug::TraceLog::EVENT_FLAG_NONE); \ + name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ + TRACE_EVENT_FLAG_NONE); \ INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ INTERNAL_TRACE_EVENT_UID(catstatic), name, \ INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \ } +// 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, name, id, \ + arg1_name, arg1_val, arg2_name, arg2_val, flags) \ + INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ + if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ + base::debug::TraceLog::GetInstance()->AddTraceEvent( \ + phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ + name, id, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ + } + template <typename Type> struct StaticMemorySingletonTraits; @@ -402,13 +495,19 @@ struct TraceCategory { const size_t kTraceMaxNumArgs = 2; // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. -enum TraceEventPhase { - TRACE_EVENT_PHASE_BEGIN, - TRACE_EVENT_PHASE_END, - TRACE_EVENT_PHASE_INSTANT, - TRACE_EVENT_PHASE_METADATA, - TRACE_EVENT_PHASE_COUNTER -}; +typedef char TraceEventPhase; +#define TRACE_EVENT_PHASE_BEGIN (base::debug::TraceEventPhase('B')) +#define TRACE_EVENT_PHASE_END (base::debug::TraceEventPhase('E')) +#define TRACE_EVENT_PHASE_INSTANT (base::debug::TraceEventPhase('I')) +#define TRACE_EVENT_PHASE_START (base::debug::TraceEventPhase('S')) +#define TRACE_EVENT_PHASE_FINISH (base::debug::TraceEventPhase('F')) +#define TRACE_EVENT_PHASE_METADATA (base::debug::TraceEventPhase('M')) +#define TRACE_EVENT_PHASE_COUNTER (base::debug::TraceEventPhase('C')) + +typedef uint8 TraceEventFlags; +#define TRACE_EVENT_FLAG_NONE (base::debug::TraceEventFlags(0)) +#define TRACE_EVENT_FLAG_COPY (base::debug::TraceEventFlags(1<<0)) +#define TRACE_EVENT_FLAG_HAS_ID (base::debug::TraceEventFlags(1<<1)) // Simple union of values. This is much lighter weight than base::Value, which // requires dynamic allocation and a vtable. To keep the trace runtime overhead @@ -535,6 +634,26 @@ class BASE_EXPORT TraceValue { Value value_; }; +// TraceID encapsulates an ID that can either be an integer or pointer. Pointers +// are mangled with the Process ID so that they are unlikely to collide when the +// same pointer is used on different processes. +class BASE_EXPORT TraceID { + public: + TraceID() : data_(NULL) {} + TraceID(void* rhs); + TraceID(unsigned long long rhs) : data_(static_cast<uint64>(rhs)) {} + TraceID(unsigned long rhs) : data_(static_cast<uint64>(rhs)) {} + TraceID(unsigned int rhs) : data_(static_cast<uint64>(rhs)) {} + TraceID(long long rhs) : data_(static_cast<uint64>(rhs)) {} + TraceID(long rhs) : data_(static_cast<uint64>(rhs)) {} + TraceID(int rhs) : data_(static_cast<uint64>(rhs)) {} + + uint64 data() const { return data_; } + + private: + uint64 data_; +}; + // Output records are "Events" and can be obtained via the // OutputCallback whenever the tracing system decides to flush. This // can happen at any time, on any thread, or you can programatically @@ -542,19 +661,24 @@ class BASE_EXPORT TraceValue { class BASE_EXPORT TraceEvent { public: TraceEvent(); - TraceEvent(unsigned long process_id, - unsigned long thread_id, + TraceEvent(int thread_id, TimeTicks timestamp, TraceEventPhase phase, const TraceCategory* category, const char* name, + TraceID id, const char* arg1_name, const TraceValue& arg1_val, const char* arg2_name, const TraceValue& arg2_val, - bool copy); + TraceEventFlags flags); ~TraceEvent(); - static const char* GetPhaseString(TraceEventPhase phase); - static TraceEventPhase GetPhase(const char* phase); + static char GetPhaseChar(TraceEventPhase phase) { + return static_cast<char>(phase); + } + + static TraceEventPhase GetPhase(const char* phase) { + return static_cast<TraceEventPhase>(*phase); + } // Serialize event data to JSON static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, @@ -574,15 +698,18 @@ class BASE_EXPORT TraceEvent { const char* name() const { return name_; } private: - unsigned long process_id_; - unsigned long thread_id_; + // Note: these are ordered by size (largest first) for optimal packing. TimeTicks timestamp_; - TraceEventPhase phase_; + // id_ can be used to store phase-specific data. + TraceID id_; + TraceValue arg_values_[kTraceMaxNumArgs]; + const char* arg_names_[kTraceMaxNumArgs]; const TraceCategory* category_; const char* name_; - const char* arg_names_[kTraceMaxNumArgs]; - TraceValue arg_values_[kTraceMaxNumArgs]; scoped_refptr<base::RefCountedString> parameter_copy_storage_; + int thread_id_; + TraceEventPhase phase_; + TraceEventFlags flags_; }; @@ -632,12 +759,6 @@ class BASE_EXPORT TraceResultBuffer { class BASE_EXPORT TraceLog { public: - // Flags for passing to AddTraceEvent. - enum EventFlags { - EVENT_FLAG_NONE = 0, - EVENT_FLAG_COPY = 1<<0 - }; - static TraceLog* GetInstance(); // Get set of known categories. This can change as new code paths are reached. @@ -710,11 +831,12 @@ class BASE_EXPORT TraceLog { int AddTraceEvent(TraceEventPhase phase, const TraceCategory* category, const char* name, + TraceID id, const char* arg1_name, TraceValue arg1_val, const char* arg2_name, TraceValue arg2_val, int threshold_begin_id, int64 threshold, - EventFlags flags); + TraceEventFlags flags); static void AddTraceEventEtw(TraceEventPhase phase, const char* name, const void* id, @@ -730,7 +852,13 @@ class BASE_EXPORT TraceLog { const char* name, const char* arg1_name, int32 arg1_val, const char* arg2_name, int32 arg2_val, - EventFlags flags); + TraceEventFlags flags); + + // Mangle |id| with a hash based on the process ID so that if |id| occurs on + // more than one process, it will not collide. + uint64 GetIntraProcessID(uint64 id) const { return id ^ process_id_hash_; } + + int process_id() const { return process_id_; } // Exposed for unittesting: @@ -747,6 +875,8 @@ class BASE_EXPORT TraceLog { return logged_events_[index]; } + void SetProcessID(int process_id); + private: // This allows constructor and destructor to be private and usable only // by the Singleton class. @@ -767,7 +897,12 @@ class BASE_EXPORT TraceLog { std::vector<std::string> included_categories_; std::vector<std::string> excluded_categories_; - base::hash_map<PlatformThreadId, std::string> thread_names_; + base::hash_map<int, std::string> thread_names_; + + // XORed with TraceID to make it unlikely to collide with other processes. + uint64 process_id_hash_; + + int process_id_; DISALLOW_COPY_AND_ASSIGN(TraceLog); }; diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc index 6f0a744..0ff986a 100644 --- a/base/debug/trace_event_unittest.cc +++ b/base/debug/trace_event_unittest.cc @@ -43,8 +43,12 @@ class TraceEventTestFixture : public testing::Test { void ManualTestSetUp(); void OnTraceDataCollected( scoped_refptr<TraceLog::RefCountedString> events_str); - bool FindMatchingTraceEntry(const JsonKeyValue* key_values); - bool FindNamePhase(const char* name, const char* phase); + DictionaryValue* FindMatchingTraceEntry(const JsonKeyValue* key_values); + DictionaryValue* FindNamePhase(const char* name, const char* phase); + DictionaryValue* FindNamePhaseKeyValue(const char* name, + const char* phase, + const char* key, + const char* value); bool FindMatchingValue(const char* key, const char* value); bool FindNonMatchingValue(const char* key, @@ -150,7 +154,7 @@ static bool IsAllKeyValueInDict(const JsonKeyValue* key_values, return true; } -bool TraceEventTestFixture::FindMatchingTraceEntry( +DictionaryValue* TraceEventTestFixture::FindMatchingTraceEntry( const JsonKeyValue* key_values) { // Scan all items size_t trace_parsed_count = trace_parsed_.GetSize(); @@ -162,12 +166,13 @@ bool TraceEventTestFixture::FindMatchingTraceEntry( DictionaryValue* dict = static_cast<DictionaryValue*>(value); if (IsAllKeyValueInDict(key_values, dict)) - return true; + return dict; } - return false; + return NULL; } -bool TraceEventTestFixture::FindNamePhase(const char* name, const char* phase) { +DictionaryValue* TraceEventTestFixture::FindNamePhase(const char* name, + const char* phase) { JsonKeyValue key_values[] = { {"name", name, IS_EQUAL}, {"ph", phase, IS_EQUAL}, @@ -176,6 +181,20 @@ bool TraceEventTestFixture::FindNamePhase(const char* name, const char* phase) { return FindMatchingTraceEntry(key_values); } +DictionaryValue* TraceEventTestFixture::FindNamePhaseKeyValue( + const char* name, + const char* phase, + const char* key, + const char* value) { + JsonKeyValue key_values[] = { + {"name", name, IS_EQUAL}, + {"ph", phase, IS_EQUAL}, + {key, value, IS_EQUAL}, + {0, 0, IS_EQUAL} + }; + return FindMatchingTraceEntry(key_values); +} + bool TraceEventTestFixture::FindMatchingValue(const char* key, const char* value) { JsonKeyValue key_values[] = { @@ -262,10 +281,10 @@ std::vector<DictionaryValue*> FindTraceEntries( void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) { { - TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW call", 1122, "extrastring1"); - TRACE_EVENT_END_ETW("TRACE_EVENT_END_ETW call", 3344, "extrastring2"); + TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW call", 0x1122, "extrastring1"); + TRACE_EVENT_END_ETW("TRACE_EVENT_END_ETW call", 0x3344, "extrastring2"); TRACE_EVENT_INSTANT_ETW("TRACE_EVENT_INSTANT_ETW call", - 5566, "extrastring3"); + 0x5566, "extrastring3"); TRACE_EVENT0("all", "TRACE_EVENT0 call"); TRACE_EVENT1("all", "TRACE_EVENT1 call", "name1", "value1"); @@ -315,9 +334,9 @@ void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed) { EXPECT_FIND_("all"); EXPECT_FIND_("TRACE_EVENT_BEGIN_ETW call"); { - int int_val = 0; - EXPECT_TRUE(item && item->GetInteger("args.id", &int_val)); - EXPECT_EQ(1122, int_val); + std::string str_val; + EXPECT_TRUE(item && item->GetString("args.id", &str_val)); + EXPECT_STREQ("1122", str_val.c_str()); } EXPECT_SUB_FIND_("extrastring1"); EXPECT_FIND_("TRACE_EVENT_END_ETW call"); @@ -664,6 +683,72 @@ TEST_F(TraceEventTestFixture, DataCapturedThreshold) { EXPECT_NOT_FIND_BE_("4thresholdlong2"); } +// Test Start/Finish events +TEST_F(TraceEventTestFixture, StartFinishEvents) { + ManualTestSetUp(); + TraceLog::GetInstance()->SetEnabled(true); + + unsigned long long id = 0xfeedbeeffeedbeefull; + TRACE_EVENT_START0( "cat", "name1", id); + TRACE_EVENT_FINISH0("cat", "name1", id); + TRACE_EVENT_BEGIN0( "cat", "name2"); + TRACE_EVENT_START0( "cat", "name3", 0); + + TraceLog::GetInstance()->SetEnabled(false); + + EXPECT_TRUE(FindNamePhase("name1", "S")); + EXPECT_TRUE(FindNamePhase("name1", "F")); + + std::string id_str; + StringAppendF(&id_str, "%llx", id); + + EXPECT_TRUE(FindNamePhaseKeyValue("name1", "S", "id", id_str.c_str())); + EXPECT_TRUE(FindNamePhaseKeyValue("name1", "F", "id", id_str.c_str())); + EXPECT_TRUE(FindNamePhaseKeyValue("name3", "S", "id", "0")); + + // BEGIN events should not have id + EXPECT_FALSE(FindNamePhaseKeyValue("name2", "B", "id", "0")); +} + +// Test Start/Finish events +TEST_F(TraceEventTestFixture, StartFinishPointerMangling) { + ManualTestSetUp(); + + void* ptr = this; + + TraceLog::GetInstance()->SetProcessID(100); + TraceLog::GetInstance()->SetEnabled(true); + TRACE_EVENT_START0( "cat", "name1", ptr); + TRACE_EVENT_START0( "cat", "name2", ptr); + TraceLog::GetInstance()->SetEnabled(false); + + TraceLog::GetInstance()->SetProcessID(200); + TraceLog::GetInstance()->SetEnabled(true); + TRACE_EVENT_FINISH0( "cat", "name1", ptr); + TraceLog::GetInstance()->SetEnabled(false); + + DictionaryValue* start = FindNamePhase("name1", "S"); + DictionaryValue* start2 = FindNamePhase("name2", "S"); + DictionaryValue* finish = FindNamePhase("name1", "F"); + EXPECT_TRUE(start); + EXPECT_TRUE(start2); + EXPECT_TRUE(finish); + + Value* value = NULL; + std::string start_id_str; + std::string start2_id_str; + std::string finish_id_str; + ASSERT_TRUE(start->Get("id", &value)); + ASSERT_TRUE(value->GetAsString(&start_id_str)); + ASSERT_TRUE(start2->Get("id", &value)); + ASSERT_TRUE(value->GetAsString(&start2_id_str)); + ASSERT_TRUE(finish->Get("id", &value)); + ASSERT_TRUE(value->GetAsString(&finish_id_str)); + + EXPECT_STREQ(start_id_str.c_str(), start2_id_str.c_str()); + EXPECT_STRNE(start_id_str.c_str(), finish_id_str.c_str()); +} + // Test that static strings are not copied. TEST_F(TraceEventTestFixture, StaticStringVsString) { ManualTestSetUp(); diff --git a/base/debug/trace_event_win.h b/base/debug/trace_event_win.h index e465d5b..7d66393 100644 --- a/base/debug/trace_event_win.h +++ b/base/debug/trace_event_win.h @@ -107,7 +107,7 @@ const base::win::EtwEventType kTraceEventTypeEnd = 0x11; const base::win::EtwEventType kTraceEventTypeInstant = 0x12; // If this flag is set in enable flags -enum TraceEventFlags { +enum TraceEventETWFlags { CAPTURE_STACK_TRACE = 0x0001, }; diff --git a/base/debug/trace_event_win_unittest.cc b/base/debug/trace_event_win_unittest.cc index 785943e..786b9d5 100644 --- a/base/debug/trace_event_win_unittest.cc +++ b/base/debug/trace_event_win_unittest.cc @@ -216,7 +216,7 @@ TEST_F(TraceEventWinTest, TraceLog) { // Full argument version, passing lengths explicitly. TraceEventETWProvider::Trace(kName, strlen(kName), - base::debug::TRACE_EVENT_PHASE_BEGIN, + TRACE_EVENT_PHASE_BEGIN, kId, kExtra, strlen(kExtra)); @@ -229,7 +229,7 @@ TEST_F(TraceEventWinTest, TraceLog) { // Const char* version. TraceEventETWProvider::Trace(static_cast<const char*>(kName), - base::debug::TRACE_EVENT_PHASE_END, + TRACE_EVENT_PHASE_END, kId, static_cast<const char*>(kExtra)); @@ -241,7 +241,7 @@ TEST_F(TraceEventWinTest, TraceLog) { // std::string extra version. TraceEventETWProvider::Trace(static_cast<const char*>(kName), - base::debug::TRACE_EVENT_PHASE_INSTANT, + TRACE_EVENT_PHASE_INSTANT, kId, std::string(kExtra)); @@ -255,7 +255,7 @@ TEST_F(TraceEventWinTest, TraceLog) { // Test for sanity on NULL inputs. TraceEventETWProvider::Trace(NULL, 0, - base::debug::TRACE_EVENT_PHASE_BEGIN, + TRACE_EVENT_PHASE_BEGIN, kId, NULL, 0); @@ -268,7 +268,7 @@ TEST_F(TraceEventWinTest, TraceLog) { TraceEventETWProvider::Trace(NULL, -1, - base::debug::TRACE_EVENT_PHASE_END, + TRACE_EVENT_PHASE_END, kId, NULL, -1); diff --git a/base/test/trace_event_analyzer.cc b/base/test/trace_event_analyzer.cc index 0832b86..a3e2705d 100644 --- a/base/test/trace_event_analyzer.cc +++ b/base/test/trace_event_analyzer.cc @@ -18,7 +18,7 @@ namespace trace_analyzer { TraceEvent::TraceEvent() : thread(0, 0), timestamp(0), - phase(base::debug::TRACE_EVENT_PHASE_BEGIN), + phase(TRACE_EVENT_PHASE_BEGIN), other_event(NULL) { } @@ -642,9 +642,9 @@ void TraceAnalyzer::AssociateBeginEndEvents() { using namespace trace_analyzer; Query begin(Query(EVENT_PHASE) == - Query::Phase(base::debug::TRACE_EVENT_PHASE_BEGIN)); + Query::Phase(TRACE_EVENT_PHASE_BEGIN)); Query end(Query(EVENT_PHASE) == - Query::Phase(base::debug::TRACE_EVENT_PHASE_END)); + Query::Phase(TRACE_EVENT_PHASE_END)); Query match(Query(EVENT_NAME) == Query(OTHER_NAME) && Query(EVENT_CATEGORY) == Query(OTHER_CATEGORY) && Query(EVENT_TID) == Query(OTHER_TID) && @@ -752,7 +752,7 @@ void TraceAnalyzer::ParseMetadata() { for (size_t i = 0; i < raw_events_.size(); ++i) { TraceEvent& this_event = raw_events_[i]; // Check for thread name metadata. - if (this_event.phase != base::debug::TRACE_EVENT_PHASE_METADATA || + if (this_event.phase != TRACE_EVENT_PHASE_METADATA || this_event.name != "thread_name") continue; std::map<std::string, std::string>::const_iterator string_it = diff --git a/base/test/trace_event_analyzer.h b/base/test/trace_event_analyzer.h index e20be61..b81b8ed 100644 --- a/base/test/trace_event_analyzer.h +++ b/base/test/trace_event_analyzer.h @@ -253,7 +253,7 @@ class Query { // Find BEGIN events that have a corresponding END event. static Query MatchBeginWithEnd() { return (Query(EVENT_PHASE) == - Query::Phase(base::debug::TRACE_EVENT_PHASE_BEGIN)) && + Query::Phase(TRACE_EVENT_PHASE_BEGIN)) && Query(EVENT_HAS_OTHER); } diff --git a/base/test/trace_event_analyzer_unittest.cc b/base/test/trace_event_analyzer_unittest.cc index 0ab8960..0bf644a 100644 --- a/base/test/trace_event_analyzer_unittest.cc +++ b/base/test/trace_event_analyzer_unittest.cc @@ -108,7 +108,7 @@ TEST_F(TraceEventAnalyzerTest, QueryEventMember) { event.thread.process_id = 3; event.thread.thread_id = 4; event.timestamp = 1.5; - event.phase = base::debug::TRACE_EVENT_PHASE_BEGIN; + event.phase = TRACE_EVENT_PHASE_BEGIN; event.category = "category"; event.name = "name"; event.arg_numbers["num"] = 7.0; @@ -119,7 +119,7 @@ TEST_F(TraceEventAnalyzerTest, QueryEventMember) { other.thread.process_id = 5; other.thread.thread_id = 6; other.timestamp = 2.5; - other.phase = base::debug::TRACE_EVENT_PHASE_END; + other.phase = TRACE_EVENT_PHASE_END; other.category = "category2"; other.name = "name2"; other.arg_numbers["num2"] = 8.0; |