diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-08-26 14:16:33 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-08-26 14:26:41 +0100 |
commit | a472769a452f50aa76cfd436b6919e300b55e8f1 (patch) | |
tree | 3b0474ab6479c0c21a1e7aa259446c6796685885 /src/libutil/util.c | |
parent | 99f067d9baf9c5141de5d24204d82008363cc78d (diff) | |
download | rspamd-a472769a452f50aa76cfd436b6919e300b55e8f1.tar.gz rspamd-a472769a452f50aa76cfd436b6919e300b55e8f1.zip |
[Minor] Improve virtual ticks obtaining methods
Diffstat (limited to 'src/libutil/util.c')
-rw-r--r-- | src/libutil/util.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c index 6554da63b..9c943108f 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -79,6 +79,7 @@ #include <x86intrin.h> #endif #endif + #include <math.h> /* for pow */ #include <glob.h> /* in fact, we require this file ultimately */ @@ -1852,16 +1853,24 @@ rspamd_get_virtual_ticks (void) #ifdef HAVE_CLOCK_GETTIME struct timespec ts; + static clockid_t cid = -1; + if (cid == -1) { +# ifdef HAVE_CLOCK_GETCPUCLOCKID + if (clock_getcpuclockid (0, &cid) == -1) { +# endif # ifdef CLOCK_PROCESS_CPUTIME_ID - clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts); + cid = CLOCK_PROCESS_CPUTIME_ID; # elif defined(CLOCK_PROF) - clock_gettime (CLOCK_PROF, &ts); -# elif defined(CLOCK_VIRTUAL) - clock_gettime (CLOCK_VIRTUAL, &ts); + cid = CLOCK_PROF; # else - clock_gettime (CLOCK_REALTIME, &ts); + cid = CLOCK_REALTIME; # endif +# ifdef HAVE_CLOCK_GETCPUCLOCKID + } +# endif + } + clock_gettime (cid, &ts); res = (double)ts.tv_sec + ts.tv_nsec / 1000000000.; #elif defined(__APPLE__) thread_port_t thread = mach_thread_self (); @@ -1875,6 +1884,12 @@ rspamd_get_virtual_ticks (void) res = info.user_time.seconds + info.system_time.seconds; res += ((gdouble)(info.user_time.microseconds + info.system_time.microseconds)) / 1e6; mach_port_deallocate(mach_task_self(), thread); +#elif defined(HAVE_RUSAGE_SELF) + struct rusage rusage; + if (getrusage (RUSAGE_SELF, &rusage) != -1) { + res = (double) rusage.ru_utime.tv_sec + + (double) rusage.ru_utime.tv_usec / 1000000.0; + } #else res = clock () / (double)CLOCKS_PER_SEC; #endif |