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

Unified Diff: base/debug/trace_event.cc

Issue 8470001: TraceEvent fixes for thread name changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac Created 9 years, 1 month 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 bf59f91e91d0b7e58a99cf47fca2a9a2f22a838b..c659ed2b58e2a2b1bce245a02edaf49f77f06c20 100644
--- a/base/debug/trace_event.cc
+++ b/base/debug/trace_event.cc
@@ -12,8 +12,10 @@
#include "base/bind.h"
#include "base/format_macros.h"
#include "base/lazy_instance.h"
+#include "base/memory/singleton.h"
#include "base/process_util.h"
#include "base/stringprintf.h"
+#include "base/threading/platform_thread.h"
#include "base/threading/thread_local.h"
#include "base/utf_string_conversions.h"
#include "base/stl_util.h"
@@ -54,10 +56,10 @@ const TraceCategory* const g_category_metadata =
&g_categories[2];
int g_category_index = 3; // skip initial 3 categories
-// Flag to indicate whether we captured the current thread name
-LazyInstance<ThreadLocalBoolean,
- LeakyLazyInstanceTraits<ThreadLocalBoolean> >
- g_current_thread_name_captured(LINKER_INITIALIZED);
+// The most-recently captured name of the current thread
+LazyInstance<ThreadLocalPointer<char>,
+ LeakyLazyInstanceTraits<ThreadLocalPointer<char> > >
+ g_current_thread_name(LINKER_INITIALIZED);
} // namespace
@@ -513,27 +515,27 @@ int TraceLog::AddTraceEvent(TraceEventPhase phase,
PlatformThreadId thread_id = PlatformThread::CurrentId();
- // Record the name of the calling thread, if not done already.
- if (!g_current_thread_name_captured.Pointer()->Get()) {
- g_current_thread_name_captured.Pointer()->Set(true);
- const char* cur_name = PlatformThread::GetName();
+ const char* cur_name = PlatformThread::GetName();
+ if (cur_name && *cur_name &&
jbates 2011/11/08 18:44:38 Since the steady state is (cur_name == g_current_t
nduca 2011/11/09 04:02:24 If we do that, we might want to explain the logic,
joth 2011/11/09 13:17:58 Done.
joth 2011/11/09 13:17:58 Done.
+ cur_name != g_current_thread_name.Get().Get()) {
+ // Benign const cast.
+ g_current_thread_name.Get().Set(const_cast<char*>(cur_name));
base::hash_map<PlatformThreadId, 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.
- thread_names_[thread_id] = cur_name ? cur_name : "";
- } else if(cur_name != NULL) {
+ thread_names_[thread_id] = cur_name;
+ } else {
// This is a thread id that we've seen before, but potentially with a
// new name.
- std::vector<std::string> existing_names;
+ std::vector<base::StringPiece> existing_names;
Tokenize(existing_name->second, std::string(","), &existing_names);
bool found = std::find(existing_names.begin(),
existing_names.end(),
cur_name) != existing_names.end();
if (!found) {
- existing_names.push_back(cur_name);
- thread_names_[thread_id] =
- JoinString(existing_names, ',');
+ existing_name->second.push_back(',');
+ existing_name->second.append(cur_name);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698