From 0e6229fc9af040fa9f2e5cef94afc3979a5952e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Dalleau?= Date: Wed, 18 Sep 2013 17:37:50 +0200 Subject: [PATCH] VirtioGL: Add some performance measurements on guest MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Similar to what is done on host side It can be enabled by shell using following command : export DEBUG_GL_PERF=1 Signed-off-by: Frédéric Dalleau Change-Id: I13254bbef23b1fda4ef9eff61c3e583cd25b78b2 --- libGL/opengl_client.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/libGL/opengl_client.c b/libGL/opengl_client.c index 2216dc4..cbeb4d7 100755 --- a/libGL/opengl_client.c +++ b/libGL/opengl_client.c @@ -34,6 +34,8 @@ #include #include +#include +#include #include #include "opengl_func.h" @@ -86,6 +88,7 @@ static const char* interestingEnvVars[] = /**/ int debug_gl = 0; +int debug_gl_perf = 0; int debug_array_ptr = 0; int disable_optim = 0; @@ -93,6 +96,14 @@ static int glfd; static char* xfer_buffer = NULL; +struct GLCallStatInfo { + uint64_t n; // Number of time a function is called + uint64_t max; // Maximum number of ms spent here + uint64_t total; // Total number of ms spent here +}; + +static struct GLCallStatInfo g_stats[GL_N_CALLS]; + static inline int call_opengl(char *buffer, int args_len, int ret_len, char *ret_buffer) { volatile int *i = (volatile int*)xfer_buffer; @@ -198,6 +209,11 @@ void do_opengl_call_no_lock(int func_number, void* ret_ptr, long* args, int* arg int current_thread; int ret_int = 0; static int init, nr_serial, cur_ret_buf; + struct timeval t0, t1; + + if (debug_gl_perf) { + gettimeofday(&t0, NULL); + } if( ! (func_number >= 0 && func_number < GL_N_CALLS) ) { @@ -357,6 +373,22 @@ void do_opengl_call_no_lock(int func_number, void* ret_ptr, long* args, int* arg } } } while (again); + + + if (debug_gl_perf) { + gettimeofday(&t1, NULL); + timersub(&t1, &t0, &t1); + unsigned long duration = t1.tv_sec * 1000000 + t1.tv_usec; + struct GLCallStatInfo *stats = &(g_stats[func_number]); + stats->n++; + stats->total += duration; + if (duration > stats->max) + stats->max = duration; + if (stats->total > 0) + fprintf(stderr, "< %s (n %llu, total %llu, max %llu, moy %llu)\n", + tab_opengl_calls_name[func_number], + stats->n, stats->total, stats->max, stats->total / stats->n); + } } #define GLINIT_FAIL_ABI 3 @@ -434,6 +466,7 @@ static char *do_init(void) last_current_thread = current_thread; debug_gl = getenv("DEBUG_GL") != NULL; + debug_gl_perf = getenv("DEBUG_GL_PERF") != NULL; debug_array_ptr = getenv("DEBUG_ARRAY_PTR") != NULL; disable_optim = getenv("DISABLE_OPTIM") != NULL; -- 2.7.4