projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
bb65913
)
rrdtool plugin: Use cdrand_range() for the random variation.
author
Florian Forster
<octo@collectd.org>
Sun, 24 Mar 2013 13:21:27 +0000
(14:21 +0100)
committer
Florian Forster
<octo@collectd.org>
Sun, 24 Mar 2013 13:21:27 +0000
(14:21 +0100)
src/rrdtool.c
patch
|
blob
|
history
diff --git
a/src/rrdtool.c
b/src/rrdtool.c
index
e7c48c0
..
2c80762
100644
(file)
--- a/
src/rrdtool.c
+++ b/
src/rrdtool.c
@@
-1,6
+1,6
@@
/**
* collectd - src/rrdtool.c
/**
* collectd - src/rrdtool.c
- * Copyright (C) 2006-20
08
Florian octo Forster
+ * Copyright (C) 2006-20
13
Florian octo Forster
* Copyright (C) 2008-2008 Sebastian Harl
* Copyright (C) 2009 Mariusz Gronczewski
*
* Copyright (C) 2008-2008 Sebastian Harl
* Copyright (C) 2009 Mariusz Gronczewski
*
@@
-18,7
+18,7
@@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * Florian octo Forster <octo at
verplant
.org>
+ * Florian octo Forster <octo at
collectd
.org>
* Sebastian Harl <sh at tokkee.org>
* Mariusz Gronczewski <xani666 at gmail.com>
**/
* Sebastian Harl <sh at tokkee.org>
* Mariusz Gronczewski <xani666 at gmail.com>
**/
@@
-27,6
+27,7
@@
#include "plugin.h"
#include "common.h"
#include "utils_avltree.h"
#include "plugin.h"
#include "common.h"
#include "utils_avltree.h"
+#include "utils_random.h"
#include "utils_rrdcreate.h"
#include <rrd.h>
#include "utils_rrdcreate.h"
#include <rrd.h>
@@
-655,11
+656,8
@@
static int rrd_cache_flush_identifier (cdtime_t timeout,
static int64_t rrd_get_random_variation (void)
{
static int64_t rrd_get_random_variation (void)
{
- double dbl_timeout;
- cdtime_t ctm_timeout;
- double rand_fact;
- _Bool negative;
- int64_t ret;
+ long min;
+ long max;
if (random_timeout <= 0)
return (0);
if (random_timeout <= 0)
return (0);
@@
-672,20
+670,10
@@
static int64_t rrd_get_random_variation (void)
random_timeout = cache_timeout;
}
random_timeout = cache_timeout;
}
- /* This seems a bit complicated, but "random_timeout" is likely larger than
- * RAND_MAX, so we can't simply use modulo here. */
- dbl_timeout = CDTIME_T_TO_DOUBLE (random_timeout);
- rand_fact = ((double) random ())
- / ((double) RAND_MAX);
- negative = (_Bool) (random () % 2);
+ max = (long) (random_timeout / 2);
+ min = max - ((long) random_timeout);
- ctm_timeout = DOUBLE_TO_CDTIME_T (dbl_timeout * rand_fact);
-
- ret = (int64_t) ctm_timeout;
- if (negative)
- ret *= -1;
-
- return (ret);
+ return ((int64_t) cdrand_range (min, max));
} /* int64_t rrd_get_random_variation */
static int rrd_cache_insert (const char *filename,
} /* int64_t rrd_get_random_variation */
static int rrd_cache_insert (const char *filename,