aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-04 17:26:51 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-04 17:26:51 +0100
commit80b126284566e994aaae172c78345c408866ad2e (patch)
tree606e0762092f82ef053a701075e1292ad9609b95 /src
parentf4232b3a9fb8dcaad06807ff49749e41bdb9d6a2 (diff)
downloadrspamd-80b126284566e994aaae172c78345c408866ad2e.tar.gz
rspamd-80b126284566e994aaae172c78345c408866ad2e.zip
Adopt task object for new timers architecture.
Diffstat (limited to 'src')
-rw-r--r--src/libmime/smtp_utils.c14
-rw-r--r--src/libserver/protocol.c13
-rw-r--r--src/libserver/symbols_cache.c45
-rw-r--r--src/libserver/task.c16
-rw-r--r--src/libserver/task.h7
5 files changed, 19 insertions, 76 deletions
diff --git a/src/libmime/smtp_utils.c b/src/libmime/smtp_utils.c
index 5a8683d7b..c4f0a7b3e 100644
--- a/src/libmime/smtp_utils.c
+++ b/src/libmime/smtp_utils.c
@@ -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
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 67f7567a9..b5975929f 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -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;
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 4f37de867..b5684efac 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -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);
}
diff --git a/src/libserver/task.c b/src/libserver/task.c
index 033149804..26de6a69f 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -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 ());
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 204ea4cad..606e4dcea 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -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 */