Fix regression in thread name reporting in the profiler.
authorPaolo Molaro <lupus@oddwiz.org>
Tue, 29 Apr 2014 15:25:16 +0000 (17:25 +0200)
committerPaolo Molaro <lupus@oddwiz.org>
Tue, 29 Apr 2014 15:25:16 +0000 (17:25 +0200)
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.

mono/metadata/threads.c
mono/profiler/decode.c
mono/profiler/proflog.c

index 43e57280ee1f22ce9510fca0d439f5a36fc6c4bd..8d8352665efc6185c94b6a24b79793f351bb5ad5 100755 (executable)
@@ -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);
        }
 }
index 1383ae90b27e10fb2f9434cd9e856184a82fd5d3..50c811f6a98d23baa4f8c0fd78fb7b9fe91fa62a 100644 (file)
@@ -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);
index 342f6e9d4f6c10ea8096967fadc9e41438e8c3b4..a9cfd3583ef337acff2cf7a0d40dac725d8617aa 100644 (file)
@@ -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));
 }
 
 /*