summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/common.h3
-rw-r--r--src/libs/zbxcommon/Makefile.am1
-rw-r--r--src/libs/zbxcommon/time.c72
-rw-r--r--src/zabbix_server/dbsyncer/dbsyncer.c13
4 files changed, 82 insertions, 7 deletions
diff --git a/include/common.h b/include/common.h
index 2ed7607c..24416616 100644
--- a/include/common.h
+++ b/include/common.h
@@ -627,6 +627,9 @@ int int_in_list(char *list, int value);
int uint64_in_list(char *list, zbx_uint64_t value);
int ip_in_list(char *list, char *ip);
+/* Time related functions */
+double time_diff(struct timeval *from, struct timeval *to);
+
int MAIN_ZABBIX_ENTRY(void);
diff --git a/src/libs/zbxcommon/Makefile.am b/src/libs/zbxcommon/Makefile.am
index 65d2c90d..e64cb608 100644
--- a/src/libs/zbxcommon/Makefile.am
+++ b/src/libs/zbxcommon/Makefile.am
@@ -8,6 +8,7 @@ libzbxcommon_a_SOURCES = \
xml.c \
comms.c \
str.c \
+ time.c \
zbxgetopt.c \
alias.c
diff --git a/src/libs/zbxcommon/time.c b/src/libs/zbxcommon/time.c
new file mode 100644
index 00000000..cd8ade35
--- /dev/null
+++ b/src/libs/zbxcommon/time.c
@@ -0,0 +1,72 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+
+#include <sys/time.h>
+#include <time.h>
+
+/******************************************************************************
+ * *
+ * Function: time_diff *
+ * *
+ * Purpose: calculate time difference in seconds *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+double time_diff(struct timeval *from, struct timeval *to)
+{
+ double msec;
+ double diff;
+
+ /* from<=to */
+ if( (from->tv_sec < to->tv_sec) || (from->tv_sec == to->tv_sec && from->tv_usec <= to->tv_usec))
+ {
+ msec = (double)(to->tv_usec-from->tv_usec)/1000000;
+
+ if(msec >= 0)
+ {
+ diff = to->tv_sec - from->tv_sec + msec;
+ }
+ else
+ {
+ diff = to->tv_sec - from->tv_sec - (msec + 1);
+ }
+ }
+ /* from>to */
+ else
+ {
+ msec = (double)(from->tv_usec-to->tv_usec)/1000000;
+
+ if(msec >= 0)
+ {
+ diff = from->tv_sec - to->tv_sec + msec;
+ }
+ else
+ {
+ diff = from->tv_sec - to->tv_sec - (msec + 1);
+ }
+ diff = 0.0 - diff;
+ }
+
+ return diff;
+}
diff --git a/src/zabbix_server/dbsyncer/dbsyncer.c b/src/zabbix_server/dbsyncer/dbsyncer.c
index 4722fc35..644418da 100644
--- a/src/zabbix_server/dbsyncer/dbsyncer.c
+++ b/src/zabbix_server/dbsyncer/dbsyncer.c
@@ -44,8 +44,8 @@
int main_dbsyncer_loop()
{
int now;
- struct timeval tv;
- suseconds_t msec;
+ struct timeval from;
+ struct timeval to;
zbx_setproctitle("connecting to the database");
@@ -58,14 +58,13 @@ int main_dbsyncer_loop()
zabbix_log( LOG_LEVEL_WARNING, "Syncing ...");
- gettimeofday(&tv, NULL);
- msec = tv.tv_usec;
+ gettimeofday(&from, NULL);
DCsync();
- gettimeofday(&tv, NULL);
- zabbix_log( LOG_LEVEL_WARNING, "Spent " ZBX_FS_DBL " sec", (double)(tv.tv_usec-msec)/1000000);
-
+ gettimeofday(&to, NULL);
+ zabbix_log( LOG_LEVEL_WARNING, "Spent " ZBX_FS_DBL " sec",
+ time_diff(&from,&to));
zbx_setproctitle("sender [sleeping for %d seconds]",
CONFIG_DBSYNCER_FREQUENCY);