[profiler] Flush the dumper thread every second.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Mon, 19 Jun 2017 23:34:14 +0000 (01:34 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Tue, 20 Jun 2017 01:19:44 +0000 (03:19 +0200)
If a program is idle, we likely won't get enough samples to prompt the dumper
thread to send its log buffer to the writer thread. This can make it seem like
the profiler isn't working when it actually is. So, just send the dumper
thread's log buffer every second to make sure data is delivered in a timely
fashion.

mono/profiler/log.c

index d08b6246f65b5824a1b54cc970183c4fd639c3a4..7fbf71f6725b4b22bbd94c21a5dee1de4779a7f8 100644 (file)
@@ -4396,7 +4396,13 @@ dumper_thread (void *arg)
        MonoProfilerThread *thread = init_thread (prof, FALSE);
 
        while (InterlockedRead (&prof->run_dumper_thread)) {
-               mono_os_sem_wait (&prof->dumper_queue_sem, MONO_SEM_FLAGS_NONE);
+               /*
+                * Flush samples every second so it doesn't seem like the profiler is
+                * not working if the program is mostly idle.
+                */
+               if (mono_os_sem_timedwait (&prof->dumper_queue_sem, 1000, MONO_SEM_FLAGS_NONE) == MONO_SEM_TIMEDWAIT_RET_TIMEDOUT)
+                       send_log_unsafe (FALSE);
+
                handle_dumper_queue_entry (prof);
        }