#include <dlfcn.h>
#include <sys/mman.h>
+#include <sys/time.h>
+#include <stdint.h>
#include <fcntl.h>
#include "opengl_func.h"
/**/
int debug_gl = 0;
+int debug_gl_perf = 0;
int debug_array_ptr = 0;
int disable_optim = 0;
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;
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) )
{
}
}
} 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
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;