diff options
author | Carlo Bramini <carlo.bramix@libero.it> | 2009-10-13 22:12:21 +0100 |
---|---|---|
committer | Carlo Bramini <carlo.bramix@libero.it> | 2009-10-13 22:12:21 +0100 |
commit | b014f51562c06d6451fc8ec35fa9d08209c9852b (patch) | |
tree | 15f62f54dbef3c9a2cfd700c1e43689aaf959dc2 | |
parent | 736cc44919cb9b010e4784821afb060b1352945a (diff) | |
download | xine-lib-b014f51562c06d6451fc8ec35fa9d08209c9852b.tar.gz xine-lib-b014f51562c06d6451fc8ec35fa9d08209c9852b.tar.bz2 |
profiler: use uint64_t & replace arrays with a struct
MSVC complained about a memset to a const object and all "long long"
variables that are GNU only. I fixed it by grouping the fields into a
structure and now even GCC is more happy.
-rw-r--r-- | src/xine-utils/monitor.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/xine-utils/monitor.c b/src/xine-utils/monitor.c index 650c10f99..77280ffc6 100644 --- a/src/xine-utils/monitor.c +++ b/src/xine-utils/monitor.c @@ -32,41 +32,42 @@ #ifndef NDEBUG -static long long int profiler_times[MAX_ID] ; -static long long int profiler_start[MAX_ID] ; -static long profiler_calls[MAX_ID] ; -static const char *profiler_label[MAX_ID] ; +typedef struct { + uint64_t p_times; + uint64_t p_start; + long p_calls; + const char *p_label; +} xine_profiler_t; + +static xine_profiler_t profiler[MAX_ID]; void xine_profiler_init () { - memset(profiler_times, 0, sizeof(profiler_times)); - memset(profiler_start, 0, sizeof(profiler_start)); - memset(profiler_calls, 0, sizeof(profiler_calls)); - memset(profiler_label, 0, sizeof(profiler_label)); + memset(profiler, 0, sizeof(profiler)); } int xine_profiler_allocate_slot (const char *label) { int id; - for (id = 0; id < MAX_ID && profiler_label[id] != NULL; id++) + for (id = 0; id < MAX_ID && profiler[id].p_label != NULL; id++) ; if (id >= MAX_ID) return -1; - profiler_label[id] = label; + profiler[id].p_label = label; return id; } #if defined(ARCH_X86_32) -static __inline__ unsigned long long int rdtsc(void) +static __inline__ uint64_t rdtsc(void) { unsigned long long int x; __asm__ volatile ("rdtsc\n\t" : "=A" (x)); return x; } #elif defined(ARCH_X86_64) -static __inline__ unsigned long long int rdtsc(void) +static __inline__ uint64_t rdtsc(void) { unsigned long long int a, d; __asm__ volatile ("rdtsc\n\t" : "=a" (a), "=d" (d)); @@ -78,7 +79,7 @@ void xine_profiler_start_count (int id) { if ( id >= MAX_ID || id < 0 ) return; #if defined(ARCH_X86) || defined(ARCH_X86_64) - profiler_start[id] = rdtsc(); + profiler[id].p_start = rdtsc(); #endif } @@ -86,18 +87,19 @@ void xine_profiler_stop_count (int id) { if ( id >= MAX_ID || id < 0 ) return; #if defined(ARCH_X86) || defined(ARCH_X86_64) - profiler_times[id] += rdtsc() - profiler_start[id]; + profiler[id].p_times += rdtsc() - profiler[id].p_start; #endif - profiler_calls[id]++; + profiler[id].p_calls++; } void xine_profiler_print_results (void) { int i; #if defined(ARCH_X86) || defined(ARCH_X86_64) - static long long int cpu_speed; /* cpu cyles/usec */ + static uint64_t cpu_speed; /* cpu cyles/usec */ + if (!cpu_speed) { - long long int tsc_start, tsc_end; + uint64_t tsc_start, tsc_end; struct timeval tv_start, tv_end; tsc_start = rdtsc(); @@ -119,13 +121,13 @@ void xine_profiler_print_results (void) { "----------------------------------------------------------------------------\n", "ID", "name", "cpu cycles", "calls", "cycles/call", "usec/call"); for (i=0; i<MAX_ID; i++) { - if (profiler_label[i]) { + if (profiler[i].p_label) { printf ("%2d: %-24.24s %12lld %9ld", - i, profiler_label[i], profiler_times[i], profiler_calls[i]); - if (profiler_calls[i]) { - printf(" %12lld", profiler_times[i] / profiler_calls[i]); + i, profiler[i].p_label, profiler[i].p_times, profiler[i].p_calls); + if (profiler[i].p_calls) { + printf(" %12lld", profiler[i].p_times / profiler[i].p_calls); #if defined(ARCH_X86) || defined(ARCH_X86_64) - printf(" %9lld", profiler_times[i] / (cpu_speed * profiler_calls[i])); + printf(" %9lld", profiler[i].p_times / (cpu_speed * profiler[i].p_calls)); #endif } printf ("\n"); |