diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2023-05-12 20:48:19 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2023-05-13 16:42:04 +0100 |
commit | 6c0d5b11c05254d91a2d0025d556251404f8f05f (patch) | |
tree | a42e691c54a4b7c7d11a1733f0d106f7339266f9 /src/cli/progress.c | |
parent | 905e4d19c2c401cef3964c2e28bf64b0dad77331 (diff) | |
download | libgit2-6c0d5b11c05254d91a2d0025d556251404f8f05f.tar.gz |
util: make monotonic time fn return ms
`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.
Diffstat (limited to 'src/cli/progress.c')
-rw-r--r-- | src/cli/progress.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/cli/progress.c b/src/cli/progress.c index ba52655e7..ddfbafb73 100644 --- a/src/cli/progress.c +++ b/src/cli/progress.c @@ -15,10 +15,10 @@ /* * Show updates to the percentage and number of objects received * separately from the throughput to give an accurate progress while - * avoiding too much noise on the screen. + * avoiding too much noise on the screen. (In milliseconds.) */ -#define PROGRESS_UPDATE_TIME 0.10 -#define THROUGHPUT_UPDATE_TIME 1.00 +#define PROGRESS_UPDATE_TIME 60 +#define THROUGHPUT_UPDATE_TIME 500 #define is_nl(c) ((c) == '\r' || (c) == '\n') @@ -54,7 +54,7 @@ static int progress_write(cli_progress *progress, bool force, git_str *line) bool has_nl; size_t no_nl = no_nl_len(line->ptr, line->size); size_t nl = nl_len(&has_nl, line->ptr + no_nl, line->size - no_nl); - double now = git__timer(); + uint64_t now = git_time_monotonic(); size_t i; /* Avoid spamming the console with progress updates */ @@ -191,20 +191,21 @@ static int fetch_receiving( { char *recv_units[] = { "B", "KiB", "MiB", "GiB", "TiB", NULL }; char *rate_units[] = { "B/s", "KiB/s", "MiB/s", "GiB/s", "TiB/s", NULL }; + uint64_t now, elapsed; - double now, recv_len, rate, elapsed; + double recv_len, rate; size_t recv_unit_idx = 0, rate_unit_idx = 0; bool done = (stats->received_objects == stats->total_objects); if (!progress->action_start) - progress->action_start = git__timer(); + progress->action_start = git_time_monotonic(); if (done && progress->action_finish) now = progress->action_finish; else if (done) - progress->action_finish = now = git__timer(); + progress->action_finish = now = git_time_monotonic(); else - now = git__timer(); + now = git_time_monotonic(); if (progress->throughput_update && now - progress->throughput_update < THROUGHPUT_UPDATE_TIME) { |