diff --git a/core/uwsgi.c b/core/uwsgi.c index e3be6803..0b71c0c1 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -2041,6 +2041,8 @@ int main(int argc, char *argv[], char *envp[]) { uwsgi_log_initial("machine: %s\n", uuts.machine); } + uwsgi_log_initial("clock source: %s\n", uwsgi.clock->name); + #ifdef __BIG_ENDIAN__ uwsgi_log_initial("*** big endian arch detected ***\n"); diff --git a/plugins/clock_monotonic/clock_monotonic.c b/plugins/clock_monotonic/clock_monotonic.c new file mode 100644 index 00000000..e6d1c27f --- /dev/null +++ b/plugins/clock_monotonic/clock_monotonic.c @@ -0,0 +1,32 @@ +#include "../../uwsgi.h" + +// timespecs have nanoseconds resolution + +time_t uwsgi_monotonic_seconds() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec; +} + +uint64_t uwsgi_monotonic_microseconds() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (ts.tv_sec * 1000000) + (ts.tv_nsec*1000); +} + + +static struct uwsgi_clock uwsgi_monotonic_clock = { + .name = "monotonic", + .seconds = uwsgi_monotonic_seconds, + .microseconds = uwsgi_monotonic_microseconds, +}; + + +void uwsgi_monotonic_clock_load() { + uwsgi_register_clock(&uwsgi_monotonic_clock); +} + +struct uwsgi_plugin clock_monotonic_plugin = { + .name = "clock_monotonic", + .on_load = uwsgi_monotonic_clock_load +}; diff --git a/plugins/clock_monotonic/uwsgiplugin.py b/plugins/clock_monotonic/uwsgiplugin.py new file mode 100644 index 00000000..dd6b23c6 --- /dev/null +++ b/plugins/clock_monotonic/uwsgiplugin.py @@ -0,0 +1,6 @@ +NAME='clock_monotonic' + +CFLAGS = [] +LDFLAGS = [] +LIBS = [] +GCC_LIST = ['clock_monotonic']