projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
serial plugin: Fix -Wshorten-64-to-32 warning.
[collectd.git]
/
src
/
collectd-tg.c
diff --git
a/src/collectd-tg.c
b/src/collectd-tg.c
index
45e788c
..
80473e0
100644
(file)
--- a/
src/collectd-tg.c
+++ b/
src/collectd-tg.c
@@
-28,18
+28,6
@@
# include "config.h"
#endif
# include "config.h"
#endif
-#ifndef _ISOC99_SOURCE
-# define _ISOC99_SOURCE
-#endif
-
-#ifndef _POSIX_C_SOURCE
-# define _POSIX_C_SOURCE 200809L
-#endif
-
-#ifndef _XOPEN_SOURCE
-# define _XOPEN_SOURCE 700
-#endif
-
#if !__GNUC__
# define __attribute__(x) /**/
#endif
#if !__GNUC__
# define __attribute__(x) /**/
#endif
@@
-51,6
+39,7
@@
#include <time.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <errno.h>
+#include <math.h>
#include "utils_heap.h"
#include "utils_heap.h"
@@
-111,6
+100,16
@@
static void signal_handler (int signal) /* {{{ */
loop = 0;
} /* }}} void signal_handler */
loop = 0;
} /* }}} void signal_handler */
+static double dtime (void) /* {{{ */
+{
+ struct timespec ts = { 0 };
+
+ if (clock_gettime (CLOCK_MONOTONIC, &ts) != 0)
+ perror ("clock_gettime");
+
+ 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;
static int compare_time (const void *v0, const void *v1) /* {{{ */
{
const lcc_value_list_t *vl0 = v0;
@@
-173,7
+172,7
@@
static lcc_value_list_t *create_value_list (void) /* {{{ */
host_num = get_boundet_random (0, conf_num_hosts);
vl->interval = conf_interval;
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)
+ (host_num % (1 + (int) vl->interval));
if (get_boundet_random (0, 2) == 0)
@@
-211,7
+210,7
@@
static int send_value (lcc_value_list_t *vl) /* {{{ */
if (vl->values_types[0] == LCC_TYPE_GAUGE)
vl->values[0].gauge = 100.0 * ((gauge_t) random ()) / (((gauge_t) RAND_MAX) + 1.0);
else
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)
status = lcc_network_values_send (net, vl);
if (status != 0)
@@
-326,7
+325,7
@@
static int read_options (int argc, char **argv) /* {{{ */
int main (int argc, char **argv) /* {{{ */
{
int i;
int main (int argc, char **argv) /* {{{ */
{
int i;
-
time_t
last_time;
+
double
last_time;
int values_sent = 0;
read_options (argc, argv);
int values_sent = 0;
read_options (argc, argv);
@@
-399,14
+398,18
@@
int main (int argc, char **argv) /* {{{ */
printf ("%i values have been sent.\n", values_sent);
/* Check if we need to sleep */
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 };
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);
nanosleep (&ts, /* remaining = */ NULL);
- now =
time (NULL
);
+ now =
dtime (
);
if (!loop)
break;
if (!loop)
break;