aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-07-13 12:37:58 +0200
committerGitHub <noreply@github.com>2019-07-13 12:37:58 +0200
commit4013f670537246826dae738d5cb86fd075f59f82 (patch)
treee1b5f8e8327f585f5ca3fdc5353312645aee15a2 /src
parente1fae8f1fe940db6a0ecddfcf88afeaacf6bb9d4 (diff)
downloadrneovim-4013f670537246826dae738d5cb86fd075f59f82.tar.gz
rneovim-4013f670537246826dae738d5cb86fd075f59f82.tar.bz2
rneovim-4013f670537246826dae738d5cb86fd075f59f82.zip
viml/profile: revert gettimeofday() #10488
e2ce5ff9d616 was proven to be bogus, so revert it. close #10328 ref #10356 ref #10452
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/os/time.c21
-rw-r--r--src/nvim/profile.c36
3 files changed, 25 insertions, 34 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 418725fa44..6a5149614b 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -16563,7 +16563,7 @@ static void f_reltimefloat(typval_T *argvars , typval_T *rettv, FunPtr fptr)
rettv->v_type = VAR_FLOAT;
rettv->vval.v_float = 0;
if (list2proftime(&argvars[0], &tm) == OK) {
- rettv->vval.v_float = ((float_T)tm) / 1000000;
+ rettv->vval.v_float = ((float_T)tm) / 1000000000;
}
}
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c
index 1094fbc946..4dd0614fe2 100644
--- a/src/nvim/os/time.c
+++ b/src/nvim/os/time.c
@@ -31,27 +31,6 @@ void time_init(void)
uv_cond_init(&delay_cond);
}
-/// Gets the current time with microsecond (μs) precision.
-///
-/// Subject to system-clock quirks (drift, going backwards, skipping).
-/// But it is much faster than os_hrtime() on some systems. #10328
-///
-/// @see gettimeofday(2)
-///
-/// @return Current time in microseconds.
-int64_t os_utime(void)
- FUNC_ATTR_WARN_UNUSED_RESULT
-{
- uv_timeval64_t tm;
- int e = uv_gettimeofday(&tm);
- if (e != 0 || tm.tv_sec < 0 || tm.tv_usec < 0) {
- return 0;
- }
- int64_t rv = tm.tv_sec * 1000 * 1000; // s => μs
- STRICT_ADD(rv, tm.tv_usec, &rv, int64_t);
- return rv;
-}
-
/// Gets a high-resolution (nanosecond), monotonically-increasing time relative
/// to an arbitrary time in the past.
///
diff --git a/src/nvim/profile.c b/src/nvim/profile.c
index ae3f1d9b5e..e486095fe7 100644
--- a/src/nvim/profile.c
+++ b/src/nvim/profile.c
@@ -5,6 +5,7 @@
#include <math.h>
#include <assert.h>
+#include "nvim/assert.h"
#include "nvim/profile.h"
#include "nvim/os/time.h"
#include "nvim/func_attr.h"
@@ -23,7 +24,9 @@ static proftime_T prof_wait_time;
/// @return the current time
proftime_T profile_start(void) FUNC_ATTR_WARN_UNUSED_RESULT
{
- return os_utime();
+ uint64_t now = os_hrtime();
+ assert(now <= INT64_MAX);
+ return (proftime_T)now;
}
/// Computes the time elapsed.
@@ -31,7 +34,9 @@ proftime_T profile_start(void) FUNC_ATTR_WARN_UNUSED_RESULT
/// @return Elapsed time from `tm` until now.
proftime_T profile_end(proftime_T tm) FUNC_ATTR_WARN_UNUSED_RESULT
{
- return profile_sub(os_utime(), tm);
+ uint64_t now = os_hrtime();
+ assert(now <= INT64_MAX);
+ return profile_sub((proftime_T)now, tm);
}
/// Gets a string representing time `tm`.
@@ -43,7 +48,7 @@ proftime_T profile_end(proftime_T tm) FUNC_ATTR_WARN_UNUSED_RESULT
const char *profile_msg(proftime_T tm) FUNC_ATTR_WARN_UNUSED_RESULT
{
static char buf[50];
- snprintf(buf, sizeof(buf), "%10.6lf", (double)tm / 1000000.0);
+ snprintf(buf, sizeof(buf), "%10.6lf", (double)tm / 1000000000.0);
return buf;
}
@@ -59,10 +64,11 @@ proftime_T profile_setlimit(int64_t msec) FUNC_ATTR_WARN_UNUSED_RESULT
// no limit
return profile_zero();
}
- assert(msec <= (INT64_MAX / 1000LL) - 1);
-
- proftime_T usec = msec * 1000;
- return os_utime() + usec;
+ assert(msec <= (INT64_MAX / 1000000LL) - 1);
+ proftime_T nsec = msec * 1000000LL;
+ int64_t rv;
+ STRICT_ADD(os_hrtime(), nsec, &rv, int64_t);
+ return rv;
}
/// Checks if current time has passed `tm`.
@@ -75,7 +81,9 @@ bool profile_passed_limit(proftime_T tm) FUNC_ATTR_WARN_UNUSED_RESULT
// timer was not set
return false;
}
- return profile_cmp(os_utime(), tm) < 0;
+ uint64_t now = os_hrtime();
+ assert(now <= INT64_MAX);
+ return profile_cmp((proftime_T)now, tm) < 0;
}
/// Gets the zero time.
@@ -103,15 +111,19 @@ proftime_T profile_divide(proftime_T tm, int count) FUNC_ATTR_CONST
/// @return `tm1` + `tm2`
proftime_T profile_add(proftime_T tm1, proftime_T tm2) FUNC_ATTR_CONST
{
- return tm1 + tm2;
+ int64_t rv;
+ STRICT_ADD(tm1, tm2, &rv, int64_t);
+ return rv;
}
-/// Subtracts time `tm2` from `tm1`.
+/// Subtracts time `tm2` from `tm1` (may be negative).
///
/// @return `tm1` - `tm2`
proftime_T profile_sub(proftime_T tm1, proftime_T tm2) FUNC_ATTR_CONST
{
- return tm1 - tm2;
+ int64_t rv;
+ STRICT_SUB(tm1, tm2, &rv, int64_t);
+ return rv;
}
/// Adds the `self` time from the total time and the `children` time.
@@ -219,7 +231,7 @@ void time_pop(proftime_T tp)
static void time_diff(proftime_T then, proftime_T now)
{
proftime_T diff = profile_sub(now, then);
- fprintf(time_fd, "%07.3lf", (double)diff / 1.0E3);
+ fprintf(time_fd, "%07.3lf", (double)diff / 1.0E6);
}
/// Initializes the startuptime code.