summaryrefslogtreecommitdiffstats
path: root/runtime/datetime.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-11-12 17:12:10 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2009-11-12 17:12:10 +0100
commit8b246de2a587454f9260ff91192d27a2e168ea2d (patch)
treeeaf442ec207ba1f626119be4f983c69c9c2b5ba3 /runtime/datetime.c
parent6b722a09d419ad2a552710260bb8e220858f17c2 (diff)
downloadrsyslog-8b246de2a587454f9260ff91192d27a2e168ea2d.tar.gz
rsyslog-8b246de2a587454f9260ff91192d27a2e168ea2d.tar.xz
rsyslog-8b246de2a587454f9260ff91192d27a2e168ea2d.zip
some light performance enhancement
...by replacing time() call with much faster (at least under linux) gettimeofday() calls.
Diffstat (limited to 'runtime/datetime.c')
-rw-r--r--runtime/datetime.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/runtime/datetime.c b/runtime/datetime.c
index 6160bd7c..4ab4318d 100644
--- a/runtime/datetime.c
+++ b/runtime/datetime.c
@@ -127,6 +127,24 @@ static void getCurrTime(struct syslogTime *t, time_t *ttSeconds)
}
+/* A fast alternative to getCurrTime() and time() that only obtains
+ * a timestamp like time() does. I was told that gettimeofday(), at
+ * least under Linux, is much faster than time() and I could confirm
+ * this testing. So I created that function as a replacement.
+ * rgerhards, 2009-11-12
+ */
+static time_t
+getTime(time_t *ttSeconds)
+{
+ struct timeval tp;
+
+ if(gettimeofday(&tp, NULL) == -1)
+ return -1;
+
+ if(ttSeconds != NULL)
+ *ttSeconds = tp.tv_sec;
+ return tp.tv_sec;
+}
/*******************************************************************
@@ -831,6 +849,7 @@ CODESTARTobjQueryInterface(datetime)
* of course, also affects the "if" above).
*/
pIf->getCurrTime = getCurrTime;
+ pIf->GetTime = getTime;
pIf->ParseTIMESTAMP3339 = ParseTIMESTAMP3339;
pIf->ParseTIMESTAMP3164 = ParseTIMESTAMP3164;
pIf->formatTimestampToMySQL = formatTimestampToMySQL;