Chromium Code Reviews| Index: base/debug/trace_event.cc |
| diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc |
| index d467055be9646f6aea8216eaf80f89a0b68a48e4..b0cdb76cb4a539b4a0a12aaef62d9d66096850a6 100644 |
| --- a/base/debug/trace_event.cc |
| +++ b/base/debug/trace_event.cc |
| @@ -104,6 +104,8 @@ const char* GetPhaseStr(TraceEventPhase phase) { |
| return "I"; |
| case TRACE_EVENT_PHASE_END: |
| return "E"; |
| + case TRACE_EVENT_PHASE_METADATA: |
| + return "M"; |
| default: |
| NOTREACHED() << "Invalid phase argument"; |
| return "?"; |
| @@ -295,8 +297,10 @@ void TraceLog::SetEnabled(bool enabled) { |
| g_categories[i].enabled = enabled; |
| } |
| } // release lock |
| - if (!enabled) |
| + if (!enabled) { |
| + AddCurrentMetadataEvents(); |
| Flush(); |
| + } |
| } |
| float TraceLog::GetBufferPercentFull() const { |
| @@ -361,6 +365,14 @@ int TraceLog::AddTraceEvent(TraceEventPhase phase, |
| return -1; |
| if (logged_events_.size() >= kTraceEventBufferSize) |
| return -1; |
| + PlatformThreadId thread_id = PlatformThread::CurrentId(); |
| + if (thread_names_.find(thread_id) == thread_names_.end()) { |
|
Sigurður Ásgeirsson
2011/08/04 12:31:39
On Windows, thread and process IDs are reused quit
nduca
2011/08/04 18:17:38
Thats an awesome idea.
|
| + const char* name = PlatformThread::GetName(); |
| + // Store something even for unnamed threads so we don't keep searching the |
| + // thread_names_ map every time. |
| + thread_names_[thread_id] = name ? name : ""; |
| + } |
| + |
| if (threshold_begin_id > -1) { |
| DCHECK(phase == base::debug::TRACE_EVENT_PHASE_END); |
| size_t begin_i = static_cast<size_t>(threshold_begin_id); |
| @@ -380,7 +392,7 @@ 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()), |
| - PlatformThread::CurrentId(), |
| + thread_id, |
| now, phase, category, name, |
| arg1_name, arg1_val, |
| arg2_name, arg2_val, |
| @@ -419,6 +431,25 @@ void TraceLog::AddTraceEventEtw(TraceEventPhase phase, |
| } |
| } |
| +void TraceLog::AddCurrentMetadataEvents() { |
| + static const TraceCategory* metadata_category = |
| + GetCategoryInternal("__metadata"); |
| + for(base::hash_map<PlatformThreadId, std::string>::iterator it = |
|
Sigurður Ásgeirsson
2011/08/04 12:31:39
lock_.AssertHeld().
However, I don't think you're
nduca
2011/08/04 18:17:38
Nice catch!
|
| + 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, |
| + metadata_category, "thread_name", |
| + "name", it->second.c_str(), |
| + NULL, 0, |
| + false)); |
| + } |
| +} |
| + |
| void TraceLog::Resurrect() { |
| StaticMemorySingletonTraits<TraceLog>::Resurrect(); |
| } |