summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 881d288)
raw | patch | inline | side by side (parent: 881d288)
author | Florian Forster <octo@collectd.org> | |
Fri, 3 Jul 2015 09:44:28 +0000 (11:44 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 3 Jul 2015 09:44:28 +0000 (11:44 +0200) |
This fix is likely incomplete: the printf() line is probably executed way
too often now.
too often now.
src/collectd-tg.c | patch | blob | history |
diff --git a/src/collectd-tg.c b/src/collectd-tg.c
index 45e788c22206c5c733d696bc6ab778ab732643ec..501567da6ed2db0f4df82c0c60bc1cd8105f4386 100644 (file)
--- a/src/collectd-tg.c
+++ b/src/collectd-tg.c
#include <time.h>
#include <signal.h>
#include <errno.h>
+#include <math.h>
#include "utils_heap.h"
loop = 0;
} /* }}} void signal_handler */
+static double dtime (void) /* {{{ */
+{
+ struct timespec ts = { 0 };
+
+ if (clock_gettime (CLOCK_MONOTONIC, &ts) != 0)
+ return NAN;
+
+ return ((double) ts.tv_sec) + (((double) ts.tv_nsec) / 1e9);
+} /* }}} double dtime */
+
static int compare_time (const void *v0, const void *v1) /* {{{ */
{
const lcc_value_list_t *vl0 = v0;
host_num = get_boundet_random (0, conf_num_hosts);
vl->interval = conf_interval;
- vl->time = 1.0 + time (NULL)
+ vl->time = 1.0 + dtime ()
+ (host_num % (1 + (int) vl->interval));
if (get_boundet_random (0, 2) == 0)
if (vl->values_types[0] == LCC_TYPE_GAUGE)
vl->values[0].gauge = 100.0 * ((gauge_t) random ()) / (((gauge_t) RAND_MAX) + 1.0);
else
- vl->values[0].derive += get_boundet_random (0, 100);
+ vl->values[0].derive += (derive_t) get_boundet_random (0, 100);
status = lcc_network_values_send (net, vl);
if (status != 0)
int main (int argc, char **argv) /* {{{ */
{
int i;
- time_t last_time;
+ double last_time;
int values_sent = 0;
read_options (argc, argv);
printf ("%i values have been sent.\n", values_sent);
/* Check if we need to sleep */
- time_t now = time (NULL);
+ double now = dtime ();
while (now < vl->time)
{
/* 1 / 100 second */
struct timespec ts = { 0, 10000000 };
+
+ ts.tv_sec = (time_t) now;
+ ts.tv_nsec = (long) ((now - ((double) ts.tv_sec)) * 1e9);
+
nanosleep (&ts, /* remaining = */ NULL);
- now = time (NULL);
+ now = dtime ();
if (!loop)
break;