Fix counter and cleanup this stuff a little.

SVN revision: 35731
This commit is contained in:
Cedric BAIL 2008-08-29 13:49:06 +00:00
parent 20bd230e96
commit c0e5707e30
1 changed files with 22 additions and 19 deletions

View File

@ -28,10 +28,6 @@
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include <windows.h> # include <windows.h>
# undef WIN32_LEAN_AND_MEAN # undef WIN32_LEAN_AND_MEAN
struct timespec
{
LARGE_INTEGER pc;
};
#endif /* ! _WIN2 */ #endif /* ! _WIN2 */
#include "eina_counter.h" #include "eina_counter.h"
@ -43,6 +39,12 @@ struct timespec
* Local * * Local *
*============================================================================*/ *============================================================================*/
#ifndef _WIN32
typedef struct timespec Eina_Nano_Time;
#else
typedef LARGE_INTEGER Eina_Nano_Time;
#endif
typedef struct _Eina_Clock Eina_Clock; typedef struct _Eina_Clock Eina_Clock;
struct _Eina_Counter struct _Eina_Counter
@ -57,8 +59,8 @@ struct _Eina_Clock
{ {
Eina_Inlist __list; Eina_Inlist __list;
struct timespec start; Eina_Nano_Time start;
struct timespec end; Eina_Nano_Time end;
int specimen; int specimen;
Eina_Bool valid; Eina_Bool valid;
@ -69,7 +71,7 @@ static int EINA_COUNTER_ERROR_OUT_OF_MEMORY = 0;
#ifndef _WIN32 #ifndef _WIN32
static inline int static inline int
_eina_counter_time_get(struct timespec *tp) _eina_counter_time_get(Eina_Nano_Time *tp)
{ {
return clock_gettime(CLOCK_PROCESS_CPUTIME_ID, tp); return clock_gettime(CLOCK_PROCESS_CPUTIME_ID, tp);
} }
@ -78,9 +80,9 @@ static int EINA_COUNTER_ERROR_WINDOWS = 0;
static LARGE_INTEGER _eina_counter_frequency; static LARGE_INTEGER _eina_counter_frequency;
static inline int static inline int
_eina_counter_time_get(struct timespec *tp) _eina_counter_time_get(Eina_Nano_Time *tp)
{ {
return QueryPerformanceCounter(&tp->pc); return QueryPerformanceCounter(tp);
} }
#endif /* _WIN2 */ #endif /* _WIN2 */
@ -167,10 +169,10 @@ EAPI void
eina_counter_start(Eina_Counter *counter) eina_counter_start(Eina_Counter *counter)
{ {
Eina_Clock *clk; Eina_Clock *clk;
struct timespec tp; Eina_Nano_Time tp;
if (!counter) return ; if (!counter) return ;
if (!_eina_counter_time_get(&tp)) return; if (_eina_counter_time_get(&tp) != 0) return;
clk = calloc(1, sizeof (Eina_Clock)); clk = calloc(1, sizeof (Eina_Clock));
if (!clk) if (!clk)
@ -189,10 +191,10 @@ EAPI void
eina_counter_stop(Eina_Counter *counter, int specimen) eina_counter_stop(Eina_Counter *counter, int specimen)
{ {
Eina_Clock *clk; Eina_Clock *clk;
struct timespec tp; Eina_Nano_Time tp;
if (!counter) return ; if (!counter) return ;
if (!_eina_counter_time_get(&tp)) return; if (_eina_counter_time_get(&tp) != 0) return;
clk = (Eina_Clock *) counter->clocks; clk = (Eina_Clock *) counter->clocks;
@ -216,6 +218,8 @@ eina_counter_dump(Eina_Counter *counter, FILE *out)
long int end; long int end;
long int diff; long int diff;
if (clk->valid == EINA_FALSE) continue ;
#ifndef _WIN32 #ifndef _WIN32
start = clk->start.tv_sec * 1000000000 + clk->start.tv_nsec; start = clk->start.tv_sec * 1000000000 + clk->start.tv_nsec;
end = clk->end.tv_sec * 1000000000 + clk->end.tv_nsec; end = clk->end.tv_sec * 1000000000 + clk->end.tv_nsec;
@ -226,7 +230,6 @@ eina_counter_dump(Eina_Counter *counter, FILE *out)
diff = (long int)(((long long int)(clk->end.pc.QuadPart - clk->start.pc.QuadPart) * 1000000000LL) / (long long int)_eina_counter_frequency.QuadPart); diff = (long int)(((long long int)(clk->end.pc.QuadPart - clk->start.pc.QuadPart) * 1000000000LL) / (long long int)_eina_counter_frequency.QuadPart);
#endif /* _WIN2 */ #endif /* _WIN2 */
if (clk->valid == EINA_TRUE)
fprintf(out, "%i\t%li\t%li\t%li\n", fprintf(out, "%i\t%li\t%li\t%li\n",
clk->specimen, clk->specimen,
diff, diff,