}
/* set some defaults */
- strcpy(rrd.stat_head->cookie, RRD_COOKIE);
- strcpy(rrd.stat_head->version, RRD_VERSION3); /* by default we are still version 3 */
+ strcpy(rrd.stat_head->cookie, RRD_COOKIE);
+ strcpy(rrd.stat_head->version, RRD_VERSION3); /* by default we are still version 3 */
rrd.stat_head->float_cookie = FLOAT_COOKIE;
rrd.stat_head->ds_cnt = 0; /* this will be adjusted later */
rrd.stat_head->rra_cnt = 0; /* ditto */
switch (cf_conv
(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam)) {
case CF_MHWPREDICT:
- strcpy(rrd.stat_head->version, RRD_VERSION); /* MHWPREDICT causes Version 4 */
+ strcpy(rrd.stat_head->version, RRD_VERSION); /* MHWPREDICT causes Version 4 */
case CF_HWPREDICT:
/* initialize some parameters */
rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_alpha].
int ds_idx)
{
char minstr[DS_NAM_SIZE], maxstr[DS_NAM_SIZE];
- char *old_locale;
+ char *old_locale;
+
/*
int temp;
&(rrd -> ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt),
minstr,maxstr);
*/
- old_locale = setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
if (sscanf(def, "%lu:%18[^:]:%18[^:]",
&(rrd->ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt),
minstr, maxstr) == 3) {
rrd->ds_def[ds_idx].par[DS_min_val].u_val
>= rrd->ds_def[ds_idx].par[DS_max_val].u_val) {
rrd_set_error("min must be less than max in DS definition");
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
return;
}
} else {
rrd_set_error("failed to parse data source %s", def);
}
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
}
/* Create the CF_DEVPREDICT, CF_DEVSEASONAL, CF_SEASONAL, and CF_FAILURES RRAs
rrd_t *rrd)
{
unsigned long i, ii;
- int rrd_file;
+ int rrd_file;
rrd_value_t *unknown;
int unkn_cnt;
rrd_file_t *rrd_file_dn;
- rrd_t rrd_dn;
+ rrd_t rrd_dn;
- if ((rrd_file = open(file_name, O_WRONLY|O_CREAT|O_TRUNC,0666)) == NULL) {
+ if ((rrd_file =
+ open(file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == NULL) {
rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno));
rrd_free(rrd);
return (-1);
}
- write(rrd_file,rrd->stat_head, sizeof(stat_head_t));
+ write(rrd_file, rrd->stat_head, sizeof(stat_head_t));
- write(rrd_file,rrd->ds_def, sizeof(ds_def_t)*rrd->stat_head->ds_cnt);
+ write(rrd_file, rrd->ds_def, sizeof(ds_def_t) * rrd->stat_head->ds_cnt);
- write(rrd_file,rrd->rra_def,
- sizeof(rra_def_t)* rrd->stat_head->rra_cnt);
+ write(rrd_file, rrd->rra_def,
+ sizeof(rra_def_t) * rrd->stat_head->rra_cnt);
- write(rrd_file,rrd->live_head, sizeof(live_head_t));
+ write(rrd_file, rrd->live_head, sizeof(live_head_t));
if ((rrd->pdp_prep = calloc(1, sizeof(pdp_prep_t))) == NULL) {
rrd_set_error("allocating pdp_prep");
rrd->live_head->last_up % rrd->stat_head->pdp_step;
for (i = 0; i < rrd->stat_head->ds_cnt; i++)
- write(rrd_file,rrd->pdp_prep, sizeof(pdp_prep_t));
+ write(rrd_file, rrd->pdp_prep, sizeof(pdp_prep_t));
if ((rrd->cdp_prep = calloc(1, sizeof(cdp_prep_t))) == NULL) {
rrd_set_error("allocating cdp_prep");
}
for (ii = 0; ii < rrd->stat_head->ds_cnt; ii++) {
- write(rrd_file,rrd->cdp_prep, sizeof(cdp_prep_t));
+ write(rrd_file, rrd->cdp_prep, sizeof(cdp_prep_t));
}
}
* 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;
- write(rrd_file,rrd->rra_ptr, sizeof(rra_ptr_t));
+ write(rrd_file, rrd->rra_ptr, sizeof(rra_ptr_t));
}
/* write the empty data area */
unkn_cnt += rrd->stat_head->ds_cnt * rrd->rra_def[i].row_cnt;
while (unkn_cnt > 0) {
- write(rrd_file,unknown, sizeof(rrd_value_t) * min(unkn_cnt, 512));
+ write(rrd_file, unknown, sizeof(rrd_value_t) * min(unkn_cnt, 512));
unkn_cnt -= 512;
}
free(unknown);
fdatasync(rrd_file);
rrd_free(rrd);
- if ( close(rrd_file) == -1 ) {
+ if (close(rrd_file) == -1) {
rrd_set_error("creating rrd: %s", rrd_strerror(errno));
return -1;
}
/* flush all we don't need out of the cache */
rrd_file_dn = rrd_open(file_name, &rrd_dn, RRD_READONLY);
- rrd_dontneed(rrd_file_dn,&rrd_dn);
+ rrd_dontneed(rrd_file_dn, &rrd_dn);
rrd_close(rrd_file_dn);
return (0);
}
fputs("<!-- Round Robin Database Dump -->", out_file);
fputs("<rrd>", out_file);
- if ( atoi(rrd.stat_head->version) <= 3) {
+ if (atoi(rrd.stat_head->version) <= 3) {
fprintf(out_file, "\t<version> %s </version>\n", RRD_VERSION3);
} else {
fprintf(out_file, "\t<version> %s </version>\n", RRD_VERSION);
rrd_set_error("fetching cdp from rra");
goto err_free_data;
}
-
#ifdef DEBUG
fprintf(stderr, "post fetch %li -- ", i);
for (ii = 0; ii < *ds_cnt; ii++)
CF_FAILURES,
/* HWPREDICT that follows a moving baseline */
CF_MHWPREDICT
- /* new entries must come last !!! */
+ /* new entries must come last !!! */
};
/* A binary array of failure indicators: 1 indicates
long long_tmp;
struct rrd_time_value start_tv, end_tv;
long unsigned int color;
- char *old_locale = "";
+ char *old_locale = "";
/* defines for long options without a short equivalent. should be bytes,
and may not collide with (the ASCII value of) short options */
int option_index = 0;
int opt;
int col_start, col_end;
+
opt = getopt_long(argc, argv,
"s:e:x:y:v:w:h:D:iu:l:rb:oc:n:m:t:f:a:I:zgjFYAMEX:L:S:T:NR:B:W:",
long_options, &option_index);
case LONGOPT_UNITS_SI:
if (im->extra_flags & FORCE_UNITS) {
rrd_set_error("--units can only be used once!");
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
return;
}
if (strcmp(optarg, "si") == 0)
im->forceleftspace = 1;
break;
case 'T':
- old_locale = setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
im->tabwidth = atof(optarg);
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
break;
case 'S':
- old_locale = setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
im->step = atoi(optarg);
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
break;
case 'N':
im->gridfit = 0;
im->draw_y_grid = 0;
break;
};
- old_locale=setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
if (sscanf(optarg, "%lf:%d", &im->ygridstep, &im->ylabfact) == 2) {
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
if (im->ygridstep <= 0) {
rrd_set_error("grid step must be > 0");
return;
return;
}
} else {
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
rrd_set_error("invalid y-grid format");
return;
}
im->ylegend[150] = '\0';
break;
case 'u':
- old_locale=setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
im->maxval = atof(optarg);
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
break;
case 'l':
- old_locale=setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
im->minval = atof(optarg);
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
break;
case 'b':
im->base = atol(optarg);
char prop[15];
double size = 1;
char font[1024] = "";
- old_locale = setlocale(LC_NUMERIC,"C");
+
+ old_locale = setlocale(LC_NUMERIC, "C");
if (sscanf(optarg, "%10[A-Z]:%lf:%1000s", prop, &size, font) >= 2) {
int sindex, propidx;
-
- setlocale(LC_NUMERIC,old_locale);
+
+ setlocale(LC_NUMERIC, old_locale);
if ((sindex = text_prop_conv(prop)) != -1) {
for (propidx = sindex; propidx < TEXT_PROP_LAST;
propidx++) {
rrd_set_error("invalid fonttag '%s'", prop);
return;
}
- } else {
- setlocale(LC_NUMERIC,old_locale);
+ } else {
+ setlocale(LC_NUMERIC, old_locale);
rrd_set_error("invalid text property format");
return;
}
break;
}
case 'm':
- old_locale=setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
im->zoom = atof(optarg);
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
if (im->zoom <= 0.0) {
rrd_set_error("zoom factor must be > 0");
return;
double param;
char func[30];
int n;
- char *old_locale;
+ char *old_locale;
n = 0;
- old_locale = setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
sscanf(str, "%le,%29[A-Z]%n", ¶m, func, &n);
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
if (n == (int) strlen(str)) { /* matched */
;
} else {
return 1;
}
} else {
- long time_tmp = 0;
+ long time_tmp = 0;
+
rrd_clear_error();
i = 0;
sscanf(&line[*eaten], "%li%n", &time_tmp, &i);
default:;
}
} else {
- long time_tmp = 0;
+ long time_tmp = 0;
+
dprintf("- it is not an existing vname\n");
switch (gdp->gf) {
case GF_VRULE:
k = 0;
- sscanf(tmpstr, "%li%n",&time_tmp , &k);
+ sscanf(tmpstr, "%li%n", &time_tmp, &k);
gdp->xrule = time_tmp;
if (((j != 0) && (k == j)) || ((j == 0) && (k == i))) {
dprintf("- found time: %li\n", gdp->xrule);
#if defined USE_MADVISE
/* the ds_def will be needed soonish, so hint accordingly */
madvise(data + PAGE_START(offset),
- sizeof(ds_def_t) * rrd->stat_head->ds_cnt,
- MADV_WILLNEED);
+ sizeof(ds_def_t) * rrd->stat_head->ds_cnt, MADV_WILLNEED);
#endif
__rrd_read(rrd->ds_def, ds_def_t,
rrd->stat_head->ds_cnt);
#if defined USE_MADVISE
/* the rra_def will be needed soonish, so hint accordingly */
madvise(data + PAGE_START(offset),
- sizeof(rra_def_t) * rrd->stat_head->rra_cnt,
- MADV_WILLNEED);
+ sizeof(rra_def_t) * rrd->stat_head->rra_cnt, MADV_WILLNEED);
#endif
__rrd_read(rrd->rra_def, rra_def_t,
rrd->stat_head->rra_cnt);
#if defined USE_MADVISE
/* the live_head will be needed soonish, so hint accordingly */
madvise(data + PAGE_START(offset),
- sizeof(live_head_t), MADV_WILLNEED);
+ sizeof(live_head_t), MADV_WILLNEED);
#endif
__rrd_read(rrd->live_head, live_head_t,
1);
/* Close a reference to an rrd_file. */
static
-void mincore_print(rrd_file_t *rrd_file,char * mark){
+void mincore_print(
+ rrd_file_t *rrd_file,
+ char *mark)
+{
#ifdef HAVE_MMAP
/* pretty print blocks in core */
off_t off;
if (off == 0)
was_in = is_in;
if (was_in != is_in) {
- fprintf(stderr, "%s: %sin core: %p len %ld\n",mark,
+ fprintf(stderr, "%s: %sin core: %p len %ld\n", mark,
was_in ? "" : "not ", vec + prev, off - prev);
was_in = is_in;
prev = off;
fprintf(stderr, "mincore: %s", rrd_strerror(errno));
}
#else
- fprintf(stderr, "sorry mincore only works with mmap");
+ fprintf(stderr, "sorry mincore only works with mmap");
#endif
}
/* drop cache except for the header and the active pages */
-void
-rrd_dontneed (
+void rrd_dontneed(
rrd_file_t *rrd_file,
- rrd_t *rrd){
- unsigned long dontneed_start;
- unsigned long rra_start;
- unsigned long active_block;
- unsigned long i;
+ rrd_t *rrd)
+{
+ unsigned long dontneed_start;
+ unsigned long rra_start;
+ unsigned long active_block;
+ unsigned long i;
ssize_t _page_size = sysconf(_SC_PAGESIZE);
#if defined DEBUG && DEBUG > 1
- mincore_print(rrd_file,"before");
+ mincore_print(rrd_file, "before");
#endif
/* ignoring errors from RRDs that are smaller then the file_len+rounding */
rra_start = rrd_file->header_len;
- dontneed_start = PAGE_START(rra_start)+_page_size;
- for (i = 0; i < rrd->stat_head->rra_cnt; ++i) {
- active_block =
- PAGE_START(rra_start
- + rrd->rra_ptr[i].cur_row
- * rrd->stat_head->ds_cnt
- * sizeof(rrd_value_t));
- if (active_block > dontneed_start) {
+ dontneed_start = PAGE_START(rra_start) + _page_size;
+ for (i = 0; i < rrd->stat_head->rra_cnt; ++i) {
+ active_block =
+ PAGE_START(rra_start
+ + rrd->rra_ptr[i].cur_row
+ * rrd->stat_head->ds_cnt * sizeof(rrd_value_t));
+ if (active_block > dontneed_start) {
#ifdef USE_MADVISE
- madvise(rrd_file->file_start + dontneed_start,
- active_block-dontneed_start-1,
- MADV_DONTNEED);
+ madvise(rrd_file->file_start + dontneed_start,
+ active_block - dontneed_start - 1, MADV_DONTNEED);
#endif
/* in linux at least only fadvise DONTNEED seems to purge pages from cache */
#ifdef HAVE_POSIX_FADVISE
- posix_fadvise(rrd_file->fd, dontneed_start, active_block-dontneed_start-1, POSIX_FADV_DONTNEED);
+ posix_fadvise(rrd_file->fd, dontneed_start,
+ active_block - dontneed_start - 1,
+ POSIX_FADV_DONTNEED);
#endif
- }
- dontneed_start = active_block;
- /* do not relase 'hot' block if update for this RAA will occure within 10 minutes */
- if ( rrd->stat_head->pdp_step * rrd->rra_def[i].pdp_cnt -
- rrd->live_head->last_up % (rrd->stat_head->pdp_step * rrd->rra_def[i].pdp_cnt) < 10*60 ){
+ }
+ dontneed_start = active_block;
+ /* do not relase 'hot' block if update for this RAA will occure within 10 minutes */
+ if (rrd->stat_head->pdp_step * rrd->rra_def[i].pdp_cnt -
+ rrd->live_head->last_up % (rrd->stat_head->pdp_step *
+ rrd->rra_def[i].pdp_cnt) < 10 * 60) {
dontneed_start += _page_size;
- }
- rra_start += rrd->rra_def[i].row_cnt * rrd->stat_head->ds_cnt * sizeof(rrd_value_t);
+ }
+ rra_start +=
+ rrd->rra_def[i].row_cnt * rrd->stat_head->ds_cnt *
+ sizeof(rrd_value_t);
}
#ifdef USE_MADVISE
madvise(rrd_file->file_start + dontneed_start,
- rrd_file->file_len - dontneed_start,
- MADV_DONTNEED);
+ rrd_file->file_len - dontneed_start, MADV_DONTNEED);
#endif
#ifdef HAVE_POSIX_FADVISE
- posix_fadvise(rrd_file->fd, dontneed_start, rrd_file->file_len-dontneed_start, POSIX_FADV_DONTNEED);
+ posix_fadvise(rrd_file->fd, dontneed_start,
+ rrd_file->file_len - dontneed_start, POSIX_FADV_DONTNEED);
#endif
#if defined DEBUG && DEBUG > 1
- mincore_print(rrd_file,"after");
+ mincore_print(rrd_file, "after");
#endif
}
rrd_file_t *rrd_file)
{
int ret;
+
#ifdef HAVE_MMAP
ret = munmap(rrd_file->file_start, rrd_file->file_len);
if (ret != 0)
return -1;
}
/* make sure we output the right version only go over 3 if input is over 3 too */
- if (input_version > 3 ){
+ if (input_version > 3) {
strcpy(rrd->stat_head->version, RRD_VERSION);
} else {
strcpy(rrd->stat_head->version, RRD_VERSION3);
long steps = -1;
rpnp_t *rpnp;
char vname[MAX_VNAME_LEN + 10];
- char *old_locale;
- old_locale = setlocale(LC_NUMERIC,"C");
+ char *old_locale;
+
+ old_locale = setlocale(LC_NUMERIC, "C");
rpnp = NULL;
expr = (char *) expr_const;
while (*expr) {
if ((rpnp = (rpnp_t *) rrd_realloc(rpnp, (++steps + 2) *
sizeof(rpnp_t))) == NULL) {
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
return NULL;
}
-
+
else if ((sscanf(expr, "%lf%n", &rpnp[steps].val, &pos) == 1)
&& (expr[pos] == ',')) {
rpnp[steps].op = OP_NUMBER;
}
else {
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
free(rpnp);
return NULL;
}
if (*expr == ',')
expr++;
else {
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
free(rpnp);
return NULL;
}
}
rpnp[steps + 1].op = OP_END;
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
return rpnp;
}
const char *const file_name,
rrd_t *rrd,
unsigned rdwr);
- void rrd_dontneed(
+ void rrd_dontneed(
rrd_file_t *rrd_file,
rrd_t *rrd);
int rrd_close(
while (1) {
int option_index = 0;
int opt;
- char *old_locale = "";
+ char *old_locale = "";
+
opt = getopt_long(argc, argv, "h:i:a:d:r:p:n:w:f:x:y:z:v:b:",
long_options, &option_index);
if (opt == EOF)
optcnt++;
switch (opt) {
case 'h':
- old_locale = setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
if ((matches =
sscanf(optarg, DS_NAM_FMT ":%ld", ds_nam,
&heartbeat)) != 2) {
rrd_set_error("invalid arguments for heartbeat");
rrd_free(&rrd);
rrd_close(rrd_file);
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
return -1;
}
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
if ((ds = ds_match(&rrd, ds_nam)) == -1) {
rrd_free(&rrd);
rrd_close(rrd_file);
break;
case 'i':
- old_locale = setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
if ((matches =
sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &min)) < 1) {
rrd_set_error("invalid arguments for minimum ds value");
rrd_free(&rrd);
rrd_close(rrd_file);
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
return -1;
}
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
if ((ds = ds_match(&rrd, ds_nam)) == -1) {
rrd_free(&rrd);
rrd_close(rrd_file);
break;
case 'a':
- old_locale = setlocale(LC_NUMERIC,"C");
+ old_locale = setlocale(LC_NUMERIC, "C");
if ((matches =
sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &max)) < 1) {
rrd_set_error("invalid arguments for maximum ds value");
rrd_free(&rrd);
rrd_close(rrd_file);
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
return -1;
}
- setlocale(LC_NUMERIC,old_locale);
+ setlocale(LC_NUMERIC, old_locale);
if ((ds = ds_match(&rrd, ds_nam)) == -1) {
rrd_free(&rrd);
rrd_close(rrd_file);