From 5b4926e1893925ce5be80d1e43fe753f27952e9c Mon Sep 17 00:00:00 2001 From: "nduca@chromium.org" Date: Tue, 9 Aug 2011 15:16:25 +0000 Subject: Implement backend for thread names and process names. Added a new trace event phase 'M'/TRACE_EVENT_PHASE_METADATA, which can become a general mechanism for adding metadata to traces. The two M-type events that we then add are: {ph=M pid= name="process_name" args={ name="name of pid" }} {ph=M pid= tid= name="thread_name" args={ name="name of tid" }} base::thread is instrumented to set names automatically. I will do a followon changelist to add instrumentation to Chrome for its various processes and threads. Review URL: http://codereview.chromium.org/7495031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95997 0039d316-1c4b-4281-b951-d872f2087c98 --- base/threading/platform_thread_mac.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'base/threading/platform_thread_mac.mm') diff --git a/base/threading/platform_thread_mac.mm b/base/threading/platform_thread_mac.mm index 7d59064..9894a1d 100644 --- a/base/threading/platform_thread_mac.mm +++ b/base/threading/platform_thread_mac.mm @@ -11,9 +11,12 @@ #include #include "base/logging.h" +#include "base/threading/thread_local.h" namespace base { +static ThreadLocalPointer current_thread_name; + // If Cocoa is to be used on more than one thread, it must know that the // application is multithreaded. Since it's possible to enter Cocoa code // from threads created by pthread_thread_create, Cocoa won't necessarily @@ -37,6 +40,8 @@ void InitThreading() { // static void PlatformThread::SetName(const char* name) { + current_thread_name.Set(const_cast(name)); + // pthread_setname_np is only available in 10.6 or later, so test // for it at runtime. int (*dynamic_pthread_setname_np)(const char*); @@ -54,6 +59,11 @@ void PlatformThread::SetName(const char* name) { dynamic_pthread_setname_np(shortened_name.c_str()); } +// static +const char* PlatformThread::GetName() { + return current_thread_name.Get(); +} + namespace { void SetPriorityNormal(mach_port_t mach_thread_id) { -- cgit v1.1