[proflog] Add counters sampling on profiler shutdown
authorLudovic Henry <ludovic.henry@xamarin.com>
Thu, 6 Nov 2014 20:17:08 +0000 (15:17 -0500)
committerLudovic Henry <ludovic.henry@xamarin.com>
Thu, 6 Nov 2014 20:17:17 +0000 (15:17 -0500)
mono/profiler/proflog.c

index edf903a7442d604deab53af852b0b0a5ea0a7d9a..5e0f6727439dfda4f9bf89645f1b7ed993d991e0 100644 (file)
@@ -1980,8 +1980,10 @@ counters_init (MonoProfiler *profiler)
 }
 
 static void
-counters_sample (MonoProfiler *profiler, uint64_t timestamp)
+counters_sample (MonoProfiler *profiler)
 {
+       static uint64_t start = -1, timestamp;
+
        MonoCounterAgent *agent;
        MonoCounter *counter;
        LogBuffer *logbuffer;
@@ -1990,9 +1992,14 @@ counters_sample (MonoProfiler *profiler, uint64_t timestamp)
        void *buffer;
        int size;
 
+       if (start == -1)
+               start = current_time ();
+
        if (!counters_initialized)
                return;
 
+       timestamp = (current_time () - start) / 1000/ 1000;
+
        buffer_size = 8;
        buffer = calloc (1, buffer_size);
 
@@ -2098,6 +2105,8 @@ log_shutdown (MonoProfiler *prof)
 {
        in_shutdown = 1;
 #ifndef DISABLE_HELPER_THREAD
+       counters_sample (prof);
+
        if (prof->command_port) {
                char c = 1;
                void *res;
@@ -2197,10 +2206,8 @@ helper_thread (void* arg)
        int len;
        char buf [64];
        MonoThread *thread = NULL;
-       uint64_t start, now;
 
        //fprintf (stderr, "Server listening\n");
-       start = current_time ();
        command_socket = -1;
        while (1) {
                fd_set rfds;
@@ -2229,8 +2236,8 @@ helper_thread (void* arg)
                        }
                }
 #endif
-               now = current_time ();
-               counters_sample (prof, (now - start) / 1000/ 1000);
+
+               counters_sample (prof);
 
                tv.tv_sec = 1;
                tv.tv_usec = 0;