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

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: rebase. 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
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..51a11ff039cfc7bac2de509c42dd27ba9a337017 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,34 @@ 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
petrcermak 2016/03/29 13:07:46 Shouldn't you also do this for the main thread?
ssid 2016/03/29 18:19:11 replied below.
+ // is valid for the lifetime of the process.
+ trace_event::AllocationContextTracker::SetCurrentThreadName(
danakj 2016/03/29 00:47:36 Why not call GetName() when you need the name?
ssid 2016/03/29 18:19:11 I cannot call GetName from AllocationTracker becau
danakj 2016/03/29 20:12:41 Sorry I'm not understanding this, but why is it a
Primiano Tucci (use gerrit) 2016/03/31 15:48:28 Yeah that was my initial proposal, unfortunately w
+ leaked_str->c_str());
}
const char* ThreadIdNameManager::GetName(PlatformThreadId id) {

Powered by Google App Engine
This is Rietveld 408576698