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

Unified Diff: base/threading/thread_id_name_manager.cc

Issue 1814083002: [tracing] Add thread name to the pseudo stack of heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@profiler
Patch Set: Add comment. Created 4 years, 9 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
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_context_tracker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/thread_id_name_manager.cc
diff --git a/base/threading/thread_id_name_manager.cc b/base/threading/thread_id_name_manager.cc
index 56cfa273a87d72df8ed3163bed0348e1d09203dc..107e0dc498573a3c1777c41048954b285f819271 100644
--- a/base/threading/thread_id_name_manager.cc
+++ b/base/threading/thread_id_name_manager.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/strings/string_util.h"
+#include "base/trace_event/heap_profiler_allocation_context_tracker.h"
namespace base {
namespace {
@@ -50,27 +51,37 @@ void ThreadIdNameManager::RegisterThread(PlatformThreadHandle::Handle handle,
void ThreadIdNameManager::SetName(PlatformThreadId id,
const std::string& name) {
- AutoLock locked(lock_);
- NameToInternedNameMap::iterator iter = name_to_interned_name_.find(name);
std::string* leaked_str = NULL;
- if (iter != name_to_interned_name_.end()) {
- leaked_str = iter->second;
- } else {
- leaked_str = new std::string(name);
- name_to_interned_name_[name] = leaked_str;
+ {
+ AutoLock locked(lock_);
+ NameToInternedNameMap::iterator iter = name_to_interned_name_.find(name);
+ if (iter != name_to_interned_name_.end()) {
+ leaked_str = iter->second;
+ } else {
+ leaked_str = new std::string(name);
+ name_to_interned_name_[name] = leaked_str;
+ }
+
+ ThreadIdToHandleMap::iterator id_to_handle_iter =
+ thread_id_to_handle_.find(id);
+
+ // The main thread of a process will not be created as a Thread object which
+ // means there is no PlatformThreadHandler registered.
+ if (id_to_handle_iter == thread_id_to_handle_.end()) {
+ main_process_name_ = leaked_str;
+ main_process_id_ = id;
+ return;
+ }
+ thread_handle_to_interned_name_[id_to_handle_iter->second] = leaked_str;
}
- ThreadIdToHandleMap::iterator id_to_handle_iter =
- thread_id_to_handle_.find(id);
-
- // The main thread of a process will not be created as a Thread object which
- // means there is no PlatformThreadHandler registered.
- if (id_to_handle_iter == thread_id_to_handle_.end()) {
- main_process_name_ = leaked_str;
- main_process_id_ = id;
- return;
- }
- thread_handle_to_interned_name_[id_to_handle_iter->second] = leaked_str;
+ // Add the leaked thread name to heap profiler context tracker. The name added
+ // is valid for the lifetime of the process. AllocationContextTracker cannot
+ // call GetName(which holds a lock) during the first allocation because it can
+ // cause a deadlock when the first allocation happens in the
+ // ThreadIdNameManager itself when holding the lock.
+ trace_event::AllocationContextTracker::SetCurrentThreadName(
+ leaked_str->c_str());
}
const char* ThreadIdNameManager::GetName(PlatformThreadId id) {
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_context_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698