mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-29 04:41:35 +00:00
Converted cl_perf_timer to use git__timer internally.
This commit is contained in:
parent
9a859ef55a
commit
e5cf1c704c
@ -7,77 +7,25 @@ void cl_perf_timer__init(cl_perf_timer *t)
|
|||||||
memset(t, 0, sizeof(cl_perf_timer));
|
memset(t, 0, sizeof(cl_perf_timer));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(GIT_WIN32)
|
|
||||||
|
|
||||||
void cl_perf_timer__start(cl_perf_timer *t)
|
void cl_perf_timer__start(cl_perf_timer *t)
|
||||||
{
|
{
|
||||||
QueryPerformanceCounter(&t->time_started);
|
t->time_started = git__timer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cl_perf_timer__stop(cl_perf_timer *t)
|
void cl_perf_timer__stop(cl_perf_timer *t)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER time_now;
|
double time_now = git__timer();
|
||||||
QueryPerformanceCounter(&time_now);
|
|
||||||
|
|
||||||
t->last.QuadPart = (time_now.QuadPart - t->time_started.QuadPart);
|
t->last = time_now - t->time_started;
|
||||||
t->sum.QuadPart += (time_now.QuadPart - t->time_started.QuadPart);
|
t->sum += t->last;
|
||||||
}
|
}
|
||||||
|
|
||||||
double cl_perf_timer__last(const cl_perf_timer *t)
|
double cl_perf_timer__last(const cl_perf_timer *t)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER freq;
|
return t->last;
|
||||||
double fraction;
|
|
||||||
|
|
||||||
QueryPerformanceFrequency(&freq);
|
|
||||||
|
|
||||||
fraction = ((double)t->last.QuadPart) / ((double)freq.QuadPart);
|
|
||||||
return fraction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double cl_perf_timer__sum(const cl_perf_timer *t)
|
double cl_perf_timer__sum(const cl_perf_timer *t)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER freq;
|
return t->sum;
|
||||||
double fraction;
|
|
||||||
|
|
||||||
QueryPerformanceFrequency(&freq);
|
|
||||||
|
|
||||||
fraction = ((double)t->sum.QuadPart) / ((double)freq.QuadPart);
|
|
||||||
return fraction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
static uint32_t now_in_ms(void)
|
|
||||||
{
|
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
return (uint32_t)((now.tv_sec * 1000) + (now.tv_usec / 1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
void cl_perf_timer__start(cl_perf_timer *t)
|
|
||||||
{
|
|
||||||
t->time_started = now_in_ms();
|
|
||||||
}
|
|
||||||
|
|
||||||
void cl_perf_timer__stop(cl_perf_timer *t)
|
|
||||||
{
|
|
||||||
uint32_t now = now_in_ms();
|
|
||||||
t->last = (now - t->time_started);
|
|
||||||
t->sum += (now - t->time_started);
|
|
||||||
}
|
|
||||||
|
|
||||||
double cl_perf_timer__last(const cl_perf_timer *t)
|
|
||||||
{
|
|
||||||
double fraction = ((double)t->last) / 1000;
|
|
||||||
return fraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
double cl_perf_timer__sum(const cl_perf_timer *t)
|
|
||||||
{
|
|
||||||
double fraction = ((double)t->sum) / 1000;
|
|
||||||
return fraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,33 +1,20 @@
|
|||||||
#ifndef __CLAR_LIBGIT2_TIMER__
|
#ifndef __CLAR_LIBGIT2_TIMER__
|
||||||
#define __CLAR_LIBGIT2_TIMER__
|
#define __CLAR_LIBGIT2_TIMER__
|
||||||
|
|
||||||
#if defined(GIT_WIN32)
|
|
||||||
|
|
||||||
struct cl_perf_timer
|
struct cl_perf_timer
|
||||||
{
|
{
|
||||||
/* cummulative running time across all start..stop intervals */
|
/* cummulative running time across all start..stop intervals */
|
||||||
LARGE_INTEGER sum;
|
double sum;
|
||||||
|
|
||||||
/* value of last start..stop interval */
|
/* value of last start..stop interval */
|
||||||
LARGE_INTEGER last;
|
double last;
|
||||||
|
|
||||||
/* clock value at start */
|
/* clock value at start */
|
||||||
LARGE_INTEGER time_started;
|
double time_started;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CL_PERF_TIMER_INIT {0}
|
#define CL_PERF_TIMER_INIT {0}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
struct cl_perf_timer
|
|
||||||
{
|
|
||||||
uint32_t sum;
|
|
||||||
uint32_t last;
|
|
||||||
uint32_t time_started;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define CL_PERF_TIMER_INIT {0}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct cl_perf_timer cl_perf_timer;
|
typedef struct cl_perf_timer cl_perf_timer;
|
||||||
|
|
||||||
void cl_perf_timer__init(cl_perf_timer *t);
|
void cl_perf_timer__init(cl_perf_timer *t);
|
||||||
|
Loading…
Reference in New Issue
Block a user