]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Improve virtual ticks obtaining methods
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 26 Aug 2018 13:16:33 +0000 (14:16 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 26 Aug 2018 13:26:41 +0000 (14:26 +0100)
CMakeLists.txt
config.h.in
src/libmime/mime_encoding.c
src/libutil/util.c

index e81368296f3d2e62f7b2f46f70b5520b1157392c..d0438aabea39b2f87710bc858e3206270c2d55b5 100644 (file)
@@ -999,6 +999,8 @@ CHECK_SYMBOL_EXISTS(SSL_set_tlsext_host_name "openssl/ssl.h" HAVE_SSL_TLSEXT_HOS
 CHECK_SYMBOL_EXISTS(dirfd "sys/types.h;unistd.h;dirent.h" HAVE_DIRFD)
 CHECK_SYMBOL_EXISTS(fpathconf "sys/types.h;unistd.h" HAVE_FPATHCONF)
 CHECK_SYMBOL_EXISTS(sigaltstack "signal.h" HAVE_SIGALTSTACK)
+CHECK_SYMBOL_EXISTS(clock_getcpuclockid "sys/types.h;time.h" HAVE_CLOCK_GETCPUCLOCKID)
+CHECK_SYMBOL_EXISTS(RUSAGE_SELF "sys/types.h;sys/resource.h" HAVE_RUSAGE_SELF)
 
 IF(ENABLE_PCRE2 MATCHES "ON")
        IF(HAVE_PCRE_JIT)
index 1e9aab7bdf7cf5e0db257e1a640deee6615c08c6..8f96a7642f1446535d058a911bb7910523b84bb8 100644 (file)
@@ -13,6 +13,7 @@
 #cmakedefine HAVE_ARPA_INET_H    1
 #cmakedefine HAVE_ASM_PAUSE      1
 #cmakedefine HAVE_ATOMIC_BUILTINS 1
+#cmakedefine HAVE_CLOCK_GETCPUCLOCKID 1
 #cmakedefine HAVE_CLOCK_GETTIME  1
 #cmakedefine HAVE_CLOCK_PROCESS_CPUTIME_ID  1
 #cmakedefine HAVE_CLOCK_VIRTUAL  1
@@ -73,6 +74,7 @@
 #cmakedefine HAVE_PWD_H          1
 #cmakedefine HAVE_RDTSC          1
 #cmakedefine HAVE_READPASSPHRASE_H  1
+#cmakedefine HAVE_RUSAGE_SELF    1
 #cmakedefine HAVE_SA_SIGINFO     1
 #cmakedefine HAVE_SANE_SHMEM     1
 #cmakedefine HAVE_SANE_TZSET     1
index 0aec2d5c06a7a2d5421c15ac6029a1c5caea21c2..2f0df38eb050745fd7c3e2c3ea96b4e2d90d59da 100644 (file)
@@ -651,7 +651,9 @@ rspamd_mime_text_part_maybe_convert (struct rspamd_task *task,
        GByteArray *part_content;
        rspamd_ftok_t charset_tok;
        struct rspamd_mime_part *part = text_part->mime_part;
+       gdouble t1, t2;
 
+       t1 = rspamd_get_ticks (TRUE);
        if (rspamd_str_has_8bit (text_part->raw.begin, text_part->raw.len)) {
                text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_8BIT;
        }
@@ -727,6 +729,8 @@ rspamd_mime_text_part_maybe_convert (struct rspamd_task *task,
                rspamd_mime_text_part_ucs_from_utf (task, text_part);
                rspamd_mime_text_part_normalise (task, text_part);
                rspamd_mime_text_part_maybe_renormalise (task, text_part);
+               t2 = rspamd_get_ticks (TRUE);
+               msg_err_task ("conversion time: %.0f ticks", t2 - t1);
 
                return;
        }
@@ -748,4 +752,6 @@ rspamd_mime_text_part_maybe_convert (struct rspamd_task *task,
        }
 
        SET_PART_UTF (text_part);
+       t2 = rspamd_get_ticks (TRUE);
+       msg_err_task ("conversion time: %.0f ticks", t2 - t1);
 }
index 6554da63b259174bf7bce3f082c94d429ec04f05..9c943108f5400e55c7fc02c9f15d7058cc604e49 100644 (file)
@@ -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