Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1685)

Unified Diff: base/debug/trace_event.cc

Issue 7495031: trace_event support for thread names (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove process names. With thread names, they are redundant. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/debug/trace_event.cc
diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc
index d467055be9646f6aea8216eaf80f89a0b68a48e4..d765f5195bd747eced80ad0de4578fd50698ec29 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 {
@@ -419,6 +423,33 @@ void TraceLog::AddTraceEventEtw(TraceEventPhase phase,
}
}
+void TraceLog::SetCurrentThreadName(const char* name) {
+ AutoLock lock(lock_);
+ thread_names_[PlatformThread::CurrentId()] = name;
+}
+
+void TraceLog::AddCurrentMetadataEvents() {
+ const TraceCategory* metadata_category = GetCategoryInternal("__metadata");
joth 2011/07/26 09:53:17 static const?
+#ifdef USE_UNRELIABLE_NOW
+ TimeTicks now = TimeTicks::HighResNow();
jbates 2011/07/26 20:57:00 can we replace the timestamp with 0 for metadata e
+#else
+ TimeTicks now = TimeTicks::Now();
+#endif
+ for(base::hash_map<PlatformThreadId, std::string>::iterator it =
+ thread_names_.begin();
+ it != thread_names_.end();
+ it++) {
+ logged_events_.push_back(
+ TraceEvent(static_cast<unsigned long>(base::GetCurrentProcId()),
+ it->first,
+ now, base::debug::TRACE_EVENT_PHASE_METADATA,
+ metadata_category, "thread_name",
+ "name", it->second.c_str(),
+ NULL, 0,
+ true));
joth 2011/07/26 09:53:17 you can pass false here. (The only thing that need
+ }
+}
+
void TraceLog::Resurrect() {
StaticMemorySingletonTraits<TraceLog>::Resurrect();
}

Powered by Google App Engine
This is Rietveld 408576698