#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)
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);
}
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
#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
#include "yagl_api.h"
#include "yagl_log.h"
#include "yagl_marshal.h"
+#include "yagl_stats.h"
#include "kvm.h"
#include "hax.h"
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);
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);