YaGL: Added batch statistics to YaGL stats
authorStanislav Vorobiov <s.vorobiov@samsung.com>
Mon, 17 Sep 2012 09:22:24 +0000 (13:22 +0400)
committerEvgeny Voevodin <e.voevodin@samsung.com>
Tue, 18 Sep 2012 06:19:06 +0000 (10:19 +0400)
hw/yagl_stats.c
hw/yagl_stats.h
hw/yagl_thread.c

index 9658c80..4368a17 100644 (file)
@@ -4,7 +4,14 @@
 
 #ifdef CONFIG_YAGL_STATS
 
+#define YAGL_STATS_MAX_BATCHES 100
+
 static uint32_t g_num_refs = 0;
+
+static uint32_t g_num_batches = 0;
+static uint32_t g_num_calls = 0;
+static uint32_t g_bytes_unused = UINT32_MAX;
+
 static QemuMutex g_stats_mutex;
 
 void yagl_stats_init(void)
@@ -33,20 +40,47 @@ void yagl_stats_delete_ref(void)
     qemu_mutex_unlock(&g_stats_mutex);
 }
 
-void yagl_stats_dump(void)
+void yagl_stats_batch(uint32_t num_calls, uint32_t bytes_unused)
 {
-    uint32_t num_refs;
+    qemu_mutex_lock(&g_stats_mutex);
+
+    if (num_calls > g_num_calls) {
+        g_num_calls = num_calls;
+    }
+
+    if (bytes_unused < g_bytes_unused) {
+        g_bytes_unused = bytes_unused;
+    }
+
+    if (++g_num_batches >= YAGL_STATS_MAX_BATCHES) {
+        qemu_mutex_unlock(&g_stats_mutex);
+        yagl_stats_dump();
+        qemu_mutex_lock(&g_stats_mutex);
 
+        g_num_batches = 0;
+        g_num_calls = 0;
+        g_bytes_unused = UINT32_MAX;
+    }
+
+    qemu_mutex_unlock(&g_stats_mutex);
+}
+
+void yagl_stats_dump(void)
+{
     YAGL_LOG_FUNC_ENTER_NPT(yagl_stats_dump, NULL);
 
     qemu_mutex_lock(&g_stats_mutex);
-    num_refs = g_num_refs;
-    qemu_mutex_unlock(&g_stats_mutex);
 
     YAGL_LOG_DEBUG("<<STATS");
-    YAGL_LOG_DEBUG("num yagl_ref's: %u", num_refs);
+    YAGL_LOG_DEBUG("num yagl_ref's: %u", g_num_refs);
+    YAGL_LOG_DEBUG("# of calls per batch: %u",
+                   g_num_calls);
+    YAGL_LOG_DEBUG("# of bytes unused per batch: %u",
+                   ((g_bytes_unused == UINT32_MAX) ? 0 : g_bytes_unused));
     YAGL_LOG_DEBUG(">>STATS");
 
+    qemu_mutex_unlock(&g_stats_mutex);
+
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
index 4f5ebc6..106c224 100644 (file)
@@ -10,9 +10,10 @@ void yagl_stats_init(void);
 void yagl_stats_cleanup(void);
 
 void yagl_stats_new_ref(void);
-
 void yagl_stats_delete_ref(void);
 
+void yagl_stats_batch(uint32_t num_calls, uint32_t bytes_unused);
+
 void yagl_stats_dump(void);
 
 #else
@@ -20,6 +21,7 @@ void yagl_stats_dump(void);
 #define yagl_stats_cleanup()
 #define yagl_stats_new_ref()
 #define yagl_stats_delete_ref()
+#define yagl_stats_batch(num_calls, bytes_unused)
 #define yagl_stats_dump()
 #endif
 
index 4b7adab..080ef15 100644 (file)
@@ -4,6 +4,7 @@
 #include "yagl_api.h"
 #include "yagl_log.h"
 #include "yagl_marshal.h"
+#include "yagl_stats.h"
 #include "kvm.h"
 #include "hax.h"
 
@@ -41,6 +42,9 @@ static void *yagl_thread_func(void* arg)
         bool ret = true;
         uint8_t *current_buff;
         uint8_t *tmp;
+#ifdef CONFIG_YAGL_STATS
+        uint32_t num_calls = 0;
+#endif
 
         yagl_event_wait(&ts->call_event);
 
@@ -127,10 +131,17 @@ static void *yagl_thread_func(void* arg)
 
                 break;
             }
+
+#ifdef CONFIG_YAGL_STATS
+            ++num_calls;
+#endif
         }
 
         tmp = ts->current_in_buff;
 
+        yagl_stats_batch(num_calls,
+            (ts->current_out_buff + YAGL_MARSHAL_SIZE - current_buff));
+
         yagl_marshal_put_uint32(&tmp, (ret ? 1 : 0));
 
         yagl_event_set(&ts->call_processed_event);