mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
`git__timer` is now `git_time_monotonic`, and returns milliseconds since an arbitrary epoch. Using a floating point to store the number of seconds elapsed was clever, as it better supports the wide range of precision from the different monotonic clocks of different systems. But we're a version control system, not a real-time clock. Milliseconds is a good enough precision for our work _and_ it's the units that system calls like `poll` take and that our users interact with. Make `git_time_monotonic` return the monotonically increasing number of milliseconds "ticked" since some arbitrary epoch.
31 lines
533 B
C
31 lines
533 B
C
#include "clar_libgit2.h"
|
|
#include "clar_libgit2_timer.h"
|
|
|
|
void cl_perf_timer__init(cl_perf_timer *t)
|
|
{
|
|
memset(t, 0, sizeof(cl_perf_timer));
|
|
}
|
|
|
|
void cl_perf_timer__start(cl_perf_timer *t)
|
|
{
|
|
t->time_started = git_time_monotonic();
|
|
}
|
|
|
|
void cl_perf_timer__stop(cl_perf_timer *t)
|
|
{
|
|
uint64_t time_now = git_time_monotonic();
|
|
|
|
t->last = time_now - t->time_started;
|
|
t->sum += t->last;
|
|
}
|
|
|
|
uint64_t cl_perf_timer__last(const cl_perf_timer *t)
|
|
{
|
|
return t->last;
|
|
}
|
|
|
|
uint64_t cl_perf_timer__sum(const cl_perf_timer *t)
|
|
{
|
|
return t->sum;
|
|
}
|