summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2047b2b)
raw | patch | inline | side by side (parent: 2047b2b)
author | Florian Forster <octo@huhu.verplant.org> | |
Sat, 30 Oct 2010 11:56:52 +0000 (13:56 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Sat, 30 Oct 2010 11:56:52 +0000 (13:56 +0200) |
configure.in | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/utils_time.c | [new file with mode: 0644] | patch | blob |
src/utils_time.h | [new file with mode: 0644] | patch | blob |
diff --git a/configure.in b/configure.in
index d00ac98ed9b6e6e1bead6cf8caf95887f7ec84b0..48942b48a4ca54105f5e655a950394a6636baea8 100644 (file)
--- a/configure.in
+++ b/configure.in
AC_CHECK_FUNCS(socket, [], AC_CHECK_LIB(socket, socket, [socket_needs_socket="yes"], AC_MSG_ERROR(cannot find socket)))
AM_CONDITIONAL(BUILD_WITH_LIBSOCKET, test "x$socket_needs_socket" = "xyes")
+clock_gettime_needs_rt="no"
+clock_gettime_needs_posix4="no"
+AC_CHECK_FUNCS(clock_gettime,
+ [],
+ AC_CHECK_LIB(rt, clock_gettime,
+ [clock_gettime_needs_rt="yes"],
+ AC_CHECK_LIB(posix4, clock_gettime,
+ [clock_gettime_needs_posix4="yes"],
+ AC_MSG_ERROR(cannot find clock_gettime))))
+
nanosleep_needs_rt="no"
nanosleep_needs_posix4="no"
AC_CHECK_FUNCS(nanosleep,
AC_CHECK_LIB(posix4, nanosleep,
[nanosleep_needs_posix4="yes"],
AC_MSG_ERROR(cannot find nanosleep))))
-AM_CONDITIONAL(BUILD_WITH_LIBRT, test "x$nanosleep_needs_rt" = "xyes")
-AM_CONDITIONAL(BUILD_WITH_LIBPOSIX4, test "x$nanosleep_needs_posix4" = "xyes")
+
+AM_CONDITIONAL(BUILD_WITH_LIBRT, test "x$clock_gettime_needs_rt" = "xyes" || test "x$nanosleep_needs_rt" = "xyes")
+AM_CONDITIONAL(BUILD_WITH_LIBPOSIX4, test "x$clock_gettime_needs_posix4" = "xyes" || test "x$nanosleep_needs_posix4" = "xyes")
AC_CHECK_FUNCS(sysctl, [have_sysctl="yes"], [have_sysctl="no"])
AC_CHECK_FUNCS(sysctlbyname, [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
diff --git a/src/Makefile.am b/src/Makefile.am
index 4bcc5ab2ec76745d956711264a70b8adfb2ed447..69329bf2c3a19811f32fa2bc6e90d2f9d63d17d2 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
utils_subst.c utils_subst.h \
utils_tail.c utils_tail.h \
utils_threshold.c utils_threshold.h \
+ utils_time.c utils_time.h \
types_list.c types_list.h
collectd_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
diff --git a/src/utils_time.c b/src/utils_time.c
--- /dev/null
+++ b/src/utils_time.c
@@ -0,0 +1,44 @@
+/**
+ * collectd - src/utils_time.h
+ * Copyright (C) 2010 Florian octo Forster
+ *
+ * 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; only version 2 of the License is applicable.
+ *
+ * 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.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <ff at octo.it>
+ **/
+
+#include "collectd.h"
+#include "utils_time.h"
+#include "plugin.h"
+#include "common.h"
+
+cdtime_t cdtime (void) /* {{{ */
+{
+ int status;
+ struct timespec ts = { 0, 0 };
+
+ status = clock_gettime (CLOCK_REALTIME, &ts);
+ if (status != 0)
+ {
+ char errbuf[1024];
+ ERROR ("cdtime: clock_gettime failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (0);
+ }
+
+ return (TIMESPEC_TO_CDTIME_T (ts));
+} /* }}} cdtime_t cdtime */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/utils_time.h b/src/utils_time.h
--- /dev/null
+++ b/src/utils_time.h
@@ -0,0 +1,54 @@
+/**
+ * collectd - src/utils_time.h
+ * Copyright (C) 2010 Florian octo Forster
+ *
+ * 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; only version 2 of the License is applicable.
+ *
+ * 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.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <ff at octo.it>
+ **/
+
+#ifndef UTILS_TIME_H
+#define UTILS_TIME_H 1
+
+#include "collectd.h"
+
+/*
+ * "cdtime_t" is a 64bit unsigned integer. The time is stored at a 2^-30 second
+ * resolution, i.e. the most significant 34 bit are used to store the time in
+ * seconds, the least significant bits store the sub-second part in something
+ * very close to nanoseconds. *The* big advantage of storing time in this
+ * manner is that comparing times and calculating differences is as simple as
+ * it is with "time_t", i.e. a simple integer comparison / subtraction works.
+ */
+typedef uint64_t cdtime_t;
+
+/* 2^30 = 1073741824 */
+#define TIME_T_TO_CDTIME_T(t) (((cdtime_t) (t)) * 1073741824)
+#define CDTIME_T_TO_TIME_T(t) ((time_t) ((t) / 1073741824))
+
+#define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0)
+#define DOUBLE_TO_CDTIME_T(d) ((cdtime_t) ((d) * 1073741824.0))
+
+#define US_TO_CDTIME_T(us) ((cdtime_t) (((double) (us)) * 1073.741824))
+#define NS_TO_CDTIME_T(ns) ((cdtime_t) (((double) (ns)) * 1.073741824))
+
+#define TIMEVAL_TO_CDTIME_T(tv) (TIME_T_TO_CDTIME_T ((tv).tv_sec) \
+ + US_TO_CDTIME_T ((tv).tv_usec))
+#define TIMESPEC_TO_CDTIME_T(ts) (TIME_T_TO_CDTIME_T ((ts).tv_sec) \
+ + NS_TO_CDTIME_T ((ts).tv_nsec))
+
+cdtime_t cdtime (void);
+
+#endif /* UTILS_TIME_H */