]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Adopt task object for new timers architecture.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 May 2015 16:26:51 +0000 (17:26 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 May 2015 16:26:51 +0000 (17:26 +0100)
src/libmime/smtp_utils.c
src/libserver/protocol.c
src/libserver/symbols_cache.c
src/libserver/task.c
src/libserver/task.h

index 5a8683d7b298b8e0f90bda1bfec1851db05680f6..c4f0a7b3e875df316510a8a75e3c3a69f5a95d24 100644 (file)
@@ -208,21 +208,13 @@ smtp_metric_callback (gpointer key, gpointer value, gpointer ud)
                cd->log_buf[--cd->log_offset] = '\0';
        }
 
-#ifdef HAVE_CLOCK_GETTIME
        cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset,
                        cd->log_size - cd->log_offset,
                        "]), len: %z, time: %s,",
                        task->msg.len,
-                       calculate_check_time (&task->tv, &task->ts, task->cfg->clock_res,
-                       &task->scan_milliseconds));
-#else
-       cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset,
-                       cd->log_size - cd->log_offset,
-                       "]), len: %z, time: %s,",
-                       task->msg.len,
-                       calculate_check_time (&task->tv, task->cfg->clock_res,
-                       &task->scan_milliseconds));
-#endif
+                       calculate_check_time (task->time_real, task->time_virtual,
+                                       task->cfg->clock_res,
+                                       &task->scan_milliseconds));
 }
 
 gboolean
index 67f7567a9ea8cc9857176a81e15d932a3c5c5cb9..b5975929f649dabec7717142672d280da4890363 100644 (file)
@@ -854,18 +854,13 @@ rspamd_metric_result_ucl (struct rspamd_task *task,
                        logbuf->len--;
                }
 
-#ifdef HAVE_CLOCK_GETTIME
-               rspamd_printf_gstring (logbuf, "]), len: %z, time: %s, dns req: %d,",
-                               task->msg.len, calculate_check_time (&task->tv, &task->ts,
-                                               task->cfg->clock_res, &task->scan_milliseconds),
-                                               task->dns_requests);
-#else
                rspamd_printf_gstring (logbuf, "]), len: %z, time: %s, dns req: %d,",
                                task->msg.len,
-                               calculate_check_time (&task->tv, task->cfg->clock_res,
+                               calculate_check_time (task->time_real,
+                                               task->time_virtual,
+                                               task->cfg->clock_res,
                                                &task->scan_milliseconds),
-                                               task->dns_requests);
-#endif
+                               task->dns_requests);
        }
 
        return obj;
index 4f37de86795e089c4adae8e64c0501875c85775a..b5684efacbff9106c00f0b314ee6c42fb5393a03 100644 (file)
@@ -800,11 +800,7 @@ call_symbol_callback (struct rspamd_task * task,
        struct symbols_cache * cache,
        gpointer *save)
 {
-#ifdef HAVE_CLOCK_GETTIME
-       struct timespec ts1, ts2;
-#else
-       struct timeval tv1, tv2;
-#endif
+       double t1, t2;
        guint64 diff;
        struct cache_item *item = NULL;
        struct symbol_callback_data *s = *save;
@@ -879,19 +875,8 @@ call_symbol_callback (struct rspamd_task * task,
                return FALSE;
        }
        if (!item->is_virtual && !item->is_skipped) {
-#ifdef HAVE_CLOCK_GETTIME
-# ifdef HAVE_CLOCK_PROCESS_CPUTIME_ID
-               clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts1);
-# elif defined(HAVE_CLOCK_VIRTUAL)
-               clock_gettime (CLOCK_VIRTUAL,                    &ts1);
-# else
-               clock_gettime (CLOCK_REALTIME,                   &ts1);
-# endif
-#else
-               if (gettimeofday (&tv1, NULL) == -1) {
-                       msg_warn ("gettimeofday failed: %s", strerror (errno));
-               }
-#endif
+               t1 = rspamd_get_ticks ();
+
                if (G_UNLIKELY (check_debug_symbol (task->cfg, item->s->symbol))) {
                        rspamd_log_debug (rspamd_main->logger);
                        item->func (task, item->user_data);
@@ -901,29 +886,9 @@ call_symbol_callback (struct rspamd_task * task,
                        item->func (task, item->user_data);
                }
 
+               t2 = rspamd_get_ticks ();
 
-#ifdef HAVE_CLOCK_GETTIME
-# ifdef HAVE_CLOCK_PROCESS_CPUTIME_ID
-               clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts2);
-# elif defined(HAVE_CLOCK_VIRTUAL)
-               clock_gettime (CLOCK_VIRTUAL,                    &ts2);
-# else
-               clock_gettime (CLOCK_REALTIME,                   &ts2);
-# endif
-#else
-               if (gettimeofday (&tv2, NULL) == -1) {
-                       msg_warn ("gettimeofday failed: %s", strerror (errno));
-               }
-#endif
-
-#ifdef HAVE_CLOCK_GETTIME
-               diff =
-                       (ts2.tv_sec -
-                       ts1.tv_sec) * 1000000 + (ts2.tv_nsec - ts1.tv_nsec) / 1000;
-#else
-               diff =
-                       (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec);
-#endif
+               diff = (t2 - t1) * 1000000;
                item->s->avg_time = rspamd_set_counter (item, diff);
        }
 
index 0331498046793abfdee581ca77ef4a6f6a2b7e32..26de6a69fbc9d94c948adc64563a48694201596d 100644 (file)
@@ -54,18 +54,10 @@ rspamd_task_new (struct rspamd_worker *worker)
                        new_task->flags |= RSPAMD_TASK_FLAG_PASS_ALL;
                }
        }
-#ifdef HAVE_CLOCK_GETTIME
-# ifdef HAVE_CLOCK_PROCESS_CPUTIME_ID
-       clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &new_task->ts);
-# elif defined(HAVE_CLOCK_VIRTUAL)
-       clock_gettime (CLOCK_VIRTUAL,                    &new_task->ts);
-# else
-       clock_gettime (CLOCK_REALTIME,                   &new_task->ts);
-# endif
-#endif
-       if (gettimeofday (&new_task->tv, NULL) == -1) {
-               msg_warn ("gettimeofday failed: %s", strerror (errno));
-       }
+
+       gettimeofday (&new_task->tv, NULL);
+       new_task->time_real = rspamd_get_ticks ();
+       new_task->time_virtual = rspamd_get_virtual_ticks ();
 
        new_task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
 
index 204ea4cad2c757afc6ccc655fb6c3de880701c3d..606e4dcea7e5aae3c4c7ba84a2716bd2c63d6385 100644 (file)
@@ -138,10 +138,9 @@ struct rspamd_task {
        gchar *last_error;                                          /**< last error                                                                             */
        gint error_code;                                                /**< code of last error                                                         */
        rspamd_mempool_t *task_pool;                                    /**< memory pool for task                                                       */
-#ifdef HAVE_CLOCK_GETTIME
-       struct timespec ts;                                         /**< time of connection                                                             */
-#endif
-       struct timeval tv;                                          /**< time of connection                                                             */
+       double time_real;
+       double time_virtual;
+       struct timeval tv;
        guint32 scan_milliseconds;                                  /**< how much milliseconds passed                                   */
        guint32 parser_recursion;                                   /**< for avoiding recursion stack overflow                  */
        gboolean (*fin_callback)(struct rspamd_task *task, void *arg); /**< calback for filters finalizing                                      */