summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 085172d)
raw | patch | inline | side by side (parent: 085172d)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 19 Feb 2008 12:56:44 +0000 (12:56 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 19 Feb 2008 12:56:44 +0000 (12:56 +0000) |
create/restore operations. This effectively randomizes the block crossings
among RRDs created around the same time. Previously, RRDs that were
created/restored en masse would cross block boundaries simultaneously, which
is sub-optimal.
Also, this patch enables the user to see the RRA's cur_row pointer via
rrdinfo. This was useful during debugging.
-- kevin brintnall kbrint qwest.net
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@1290 a5681a0c-68f1-0310-ab6d-d61299d08faa
among RRDs created around the same time. Previously, RRDs that were
created/restored en masse would cross block boundaries simultaneously, which
is sub-optimal.
Also, this patch enables the user to see the RRA's cur_row pointer via
rrdinfo. This was useful during debugging.
-- kevin brintnall kbrint qwest.net
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@1290 a5681a0c-68f1-0310-ab6d-d61299d08faa
program/src/rrd_create.c | patch | blob | history | |
program/src/rrd_info.c | patch | blob | history | |
program/src/rrd_restore.c | patch | blob | history |
index 9e5b0557a8fa51d1a33fa33b4ca86e47ba3d2f40..d9ab8f484f63addba1209fbe2cadb06c4016af7e 100644 (file)
--- a/program/src/rrd_create.c
+++ b/program/src/rrd_create.c
* rrd_create.c creates new rrds
*****************************************************************************/
+#include <stdlib.h>
+#include <time.h>
+
#include "rrd_tool.h"
#include "rrd_rpncalc.h"
#include "rrd_hw.h"
unsigned long FnvHash(const char *str);
int create_hw_contingent_rras(rrd_t *rrd, unsigned short period, unsigned long hashed_name);
void parseGENERIC_DS(const char *def,rrd_t *rrd, int ds_idx);
+long int rra_random_row(rra_def_t *);
int
rrd_create(int argc, char **argv)
* the pointer a priori. */
for (i=0; i < rrd->stat_head->rra_cnt; i++)
{
- rrd->rra_ptr->cur_row = rrd->rra_def[i].row_cnt - 1;
+ rrd->rra_ptr->cur_row = rra_random_row(&rrd->rra_def[i]);
fwrite( rrd->rra_ptr, sizeof(rra_ptr_t),1,rrd_file);
}
rrd_free(rrd);
return (0);
}
+
+static int rand_init = 0;
+
+long int
+rra_random_row(rra_def_t *rra)
+{
+ if (!rand_init)
+ {
+ srandom((unsigned int)time(NULL) + (unsigned int)getpid());
+ rand_init++;
+ }
+
+ return random() % rra->row_cnt;
+}
diff --git a/program/src/rrd_info.c b/program/src/rrd_info.c
index b2a55d959c923e8697600c913d965b195074ad13..ebb1b8dd4be5fdec199b95e2b1e1b615f88af2ae 100644 (file)
--- a/program/src/rrd_info.c
+++ b/program/src/rrd_info.c
info.u_cnt=rrd.rra_def[i].row_cnt;
cd=info_push(cd,sprintf_alloc("rra[%d].rows",i), RD_I_CNT, info);
+ info.u_cnt=rrd.rra_ptr[i].cur_row;
+ cd=info_push(cd,sprintf_alloc("rra[%d].cur_row",i), RD_I_CNT, info);
+
info.u_cnt=rrd.rra_def[i].pdp_cnt;
cd=info_push(cd,sprintf_alloc("rra[%d].pdp_per_row",i), RD_I_CNT, info);
index 4fb1dab4a49c8ed14e0ed4ccd15cb706f5e69ba3..42c316c0f056d7b9d32e19b508dbec7c0d9e71b6 100644 (file)
void parse_patch1028_RRA_params(char **buf, rrd_t *rrd, int rra_index);
void parse_patch1028_CDP_params(char **buf, rrd_t *rrd, int rra_index, int ds_index);
void parse_FAILURES_history(char **buf, rrd_t *rrd, int rra_index, int ds_index);
+long int rra_random_row(rra_def_t *);
/* convert all occurrences of <BlaBlaBla> to <blablabla> */
return(-1);
}
- for(i=0; i < (int)rrd->stat_head->rra_cnt; i++) {
- /* last row in the xml file is the most recent; as
- * rrd_update increments the current row pointer, set cur_row
- * here to the last row. */
- rrd->rra_ptr[i].cur_row = rrd->rra_def[i].row_cnt-1;
- }
if (ptr==NULL)
return -1;
return 1;
int
rrd_write(char *file_name, rrd_t *rrd, char force_overwrite)
{
- unsigned long i,ii,val_cnt;
+ unsigned long i,ii,rra_offset;
FILE *rrd_file=NULL;
int fdflags;
int fd;
fwrite( rrd->cdp_prep, sizeof(cdp_prep_t),rrd->stat_head->rra_cnt*
rrd->stat_head->ds_cnt,rrd_file);
+
+ for(i=0; i < rrd->stat_head->rra_cnt; i++)
+ rrd->rra_ptr[i].cur_row = rra_random_row(&rrd->rra_def[i]);
+
fwrite( rrd->rra_ptr, sizeof(rra_ptr_t), rrd->stat_head->rra_cnt,rrd_file);
- /* calculate the number of rrd_values to dump */
- val_cnt=0;
+ /* Dump RRD values */
+ rra_offset=0;
for(i=0; i < rrd->stat_head->rra_cnt; i++)
- for(ii=0; ii < rrd->rra_def[i].row_cnt * rrd->stat_head->ds_cnt;ii++)
- val_cnt++;
- fwrite( rrd->rrd_value, sizeof(rrd_value_t),val_cnt,rrd_file);
+ {
+ unsigned long num_rows = rrd->rra_def[i].row_cnt;
+ unsigned long cur_row = rrd->rra_ptr[i].cur_row;
+ unsigned long ds_cnt = rrd->stat_head->ds_cnt;
+
+ fwrite(rrd->rrd_value + (rra_offset + num_rows-1 - cur_row) * ds_cnt,
+ sizeof(rrd_value_t), (cur_row+1)*ds_cnt, rrd_file);
+
+ fwrite(rrd->rrd_value + rra_offset * ds_cnt,
+ sizeof(rrd_value_t), (num_rows-1 - cur_row)*ds_cnt, rrd_file);
+
+ rra_offset += num_rows;
+ }
/* lets see if we had an error */
if(ferror(rrd_file)){