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

Unified Diff: base/debug/trace_event_impl.cc

Issue 11438022: Add ability to retrieve a thread_name given a thread_id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review cleanups. Created 8 years 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
« no previous file with comments | « base/base.gypi ('k') | base/debug/trace_event_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/trace_event_impl.cc
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index 07679d1131250fb101401191d02434dc6e59e8b8..3b2b9306fd0c18e79a1ea26409349a23e6ea4b5f 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -10,7 +10,6 @@
#include "base/debug/leak_annotations.h"
#include "base/debug/trace_event.h"
#include "base/format_macros.h"
-#include "base/lazy_instance.h"
#include "base/memory/singleton.h"
#include "base/process_util.h"
#include "base/stl_util.h"
@@ -20,6 +19,7 @@
#include "base/sys_info.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/platform_thread.h"
+#include "base/threading/thread_id_name_manager.h"
#include "base/threading/thread_local.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
@@ -65,9 +65,12 @@ const int g_category_categories_exhausted = 1;
const int g_category_metadata = 2;
int g_category_index = 3; // skip initial 3 categories
-// The most-recently captured name of the current thread
-LazyInstance<ThreadLocalPointer<const char> >::Leaky
- g_current_thread_name = LAZY_INSTANCE_INITIALIZER;
+// The version number for the name of the current thread. This is used to
+// decide if the current thread name has changed. We combine all the seen
+// thread names into the output name for the thread. We can't use the pointer
+// as ThreadIdNameManager has a higher chance of giving us the same memory
jar (doing other things) 2012/12/26 22:41:11 I still don't get the use case. I think you're say
+// address.
+uint32 g_current_thread_name_version = 0;
} // namespace
@@ -635,15 +638,18 @@ void TraceLog::AddTraceEvent(char phase,
return;
int thread_id = static_cast<int>(PlatformThread::CurrentId());
+ ThreadIdNameManager* manager = ThreadIdNameManager::GetInstance();
+ const char* new_name = manager->GetNameForId(thread_id);
+ uint32 new_version = manager->GetVersionForId(thread_id);
- const char* new_name = PlatformThread::GetName();
// Check if the thread name has been set or changed since the previous
// call (if any), but don't bother if the new name is empty. Note this will
// not detect a thread name change within the same char* buffer address: we
// favor common case performance over corner case correctness.
- if (new_name != g_current_thread_name.Get().Get() &&
+ if (new_version != g_current_thread_name_version &&
new_name && *new_name) {
- g_current_thread_name.Get().Set(new_name);
+ g_current_thread_name_version = new_version;
+
base::hash_map<int, std::string>::iterator existing_name =
thread_names_.find(thread_id);
if (existing_name == thread_names_.end()) {
« no previous file with comments | « base/base.gypi ('k') | base/debug/trace_event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698