From e8a37363e8c0536b62a2d0a0c23abfea84b705b2 Mon Sep 17 00:00:00 2001 From: Stanislav Vorobiov Date: Mon, 17 Sep 2012 13:22:24 +0400 Subject: [PATCH] YaGL: Added batch statistics to YaGL stats --- hw/yagl_stats.c | 44 +++++++++++++++++++++++++++++++++++++++----- hw/yagl_stats.h | 4 +++- hw/yagl_thread.c | 11 +++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/hw/yagl_stats.c b/hw/yagl_stats.c index 9658c80..4368a17 100644 --- a/hw/yagl_stats.c +++ b/hw/yagl_stats.c @@ -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"); + qemu_mutex_unlock(&g_stats_mutex); + YAGL_LOG_FUNC_EXIT(NULL); } diff --git a/hw/yagl_stats.h b/hw/yagl_stats.h index 4f5ebc6..106c224 100644 --- a/hw/yagl_stats.h +++ b/hw/yagl_stats.h @@ -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 diff --git a/hw/yagl_thread.c b/hw/yagl_thread.c index 4b7adab..080ef15 100644 --- a/hw/yagl_thread.c +++ b/hw/yagl_thread.c @@ -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); -- 2.7.4