From: Paolo Molaro Date: Tue, 29 Apr 2014 15:25:16 +0000 (+0200) Subject: Fix regression in thread name reporting in the profiler. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=1dbd5e22fa7f7922ffc448a10bee2fb219fca154;p=mono.git Fix regression in thread name reporting in the profiler. metadata/threads.c: fix regression from the 695b17f8d5967c7 change and avoid useless memory allocation. Report thread name to the profiler at thread startup if it was set before that. profiler/decode.c: fix typo. profiler/proflog.c: ensure we get a consistent first buffer header at runtime initialization. --- diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 43e57280ee1..8d8352665ef 100755 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -642,6 +642,12 @@ static guint32 WINAPI start_wrapper_internal(void *data) */ mono_profiler_thread_start (tid); + /* if the name was set before starting, we didn't invoke the profiler callback */ + if (internal->name && (internal->flags & MONO_THREAD_FLAG_NAME_SET)) { + char *tname = g_utf16_to_utf8 (internal->name, -1, NULL, NULL, NULL); + mono_profiler_thread_name (internal->tid, tname); + g_free (tname); + } /* start_func is set only for unmanaged start functions */ if (start_func) { start_func (start_arg); @@ -1182,13 +1188,10 @@ mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, g UNLOCK_THREAD (this_obj); - if (this_obj->name) { + if (this_obj->name && this_obj->tid) { char *tname = mono_string_to_utf8 (name); - - if (this_obj->tid) { - mono_profiler_thread_name (this_obj->tid, tname); - mono_thread_info_set_name (this_obj->tid, tname); - } + mono_profiler_thread_name (this_obj->tid, tname); + mono_thread_info_set_name (this_obj->tid, tname); mono_free (tname); } } diff --git a/mono/profiler/decode.c b/mono/profiler/decode.c index 1383ae90b27..50c811f6a98 100644 --- a/mono/profiler/decode.c +++ b/mono/profiler/decode.c @@ -1648,7 +1648,7 @@ decode_buffer (ProfContext *ctx) fprintf (outfile, "non-zero flags in thread\n"); return 0; } - nt = get_thread (ctx, ptr_base * ptrdiff); + nt = get_thread (ctx, ptr_base + ptrdiff); nt->name = pstrdup ((char*)p); if (debug) fprintf (outfile, "thread %p named: %s\n", (void*)(ptr_base + ptrdiff), p); diff --git a/mono/profiler/proflog.c b/mono/profiler/proflog.c index 342f6e9d4f6..a9cfd3583ef 100644 --- a/mono/profiler/proflog.c +++ b/mono/profiler/proflog.c @@ -378,6 +378,8 @@ static __thread LogBuffer* tlsbuffer = NULL; static pthread_key_t tlsbuffer; #endif +static void safe_dump (MonoProfiler *profiler, LogBuffer *logbuffer); + static char* pstrdup (const char *s) { @@ -613,6 +615,8 @@ static void runtime_initialized (MonoProfiler *profiler) { runtime_inited = 1; + /* ensure the main thread data and startup are available soon */ + safe_dump (profiler, ensure_logbuf (0)); } /*