X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_fetch.c;h=3a794e9c9022a9f0a5fc88771963698127879867;hb=4414926d4c2ab02e84ffe1d55d26b27632cb18aa;hp=3260904ea30502e59856d627e5a214db4f7ec7a7;hpb=5d406a5f504148a9e494ea09b25d9b8d79543516;p=rrdtool.git diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c index 3260904..3a794e9 100644 --- a/src/rrd_fetch.c +++ b/src/rrd_fetch.c @@ -1,10 +1,20 @@ /***************************************************************************** - * RRDtool 1.1.x Copyright Tobias Oetiker, 1997 - 2002 + * RRDtool 1.2.19 Copyright by Tobi Oetiker, 1997-2007 ***************************************************************************** * rrd_fetch.c read date from an rrd to use for further processing ***************************************************************************** * $Id$ * $Log$ + * Revision 1.8 2004/05/18 18:53:03 oetiker + * big spell checking patch -- slif@bellsouth.net + * + * Revision 1.7 2003/11/11 19:46:21 oetiker + * replaced time_value with rrd_time_value as MacOS X introduced a struct of that name in their standard headers + * + * Revision 1.6 2003/01/16 23:27:54 oetiker + * fix border condition in rra selection of rrd_fetch + * -- Stanislav Sinyagin + * * Revision 1.5 2002/06/23 22:29:40 alex * Added "step=1800" and such to "DEF" * Cleaned some of the signed vs. unsigned problems @@ -63,8 +73,9 @@ rrd_fetch(int argc, time_t start_tmp=0, end_tmp=0; enum cf_en cf_idx; - struct time_value start_tv, end_tv; + struct rrd_time_value start_tv, end_tv; char *parsetime_error = NULL; + optind = 0; opterr = 0; /* initialize getopt */ /* init start and end time */ parsetime("end-24h", &start_tv); @@ -164,25 +175,25 @@ rrd_fetch_fn( FILE *in_file; time_t cal_start,cal_end, rra_start_time,rra_end_time; long best_full_rra=0, best_part_rra=0, chosen_rra=0, rra_pointer=0; - long best_step_diff=0, tmp_step_diff=0, tmp_match=0, best_match=0; + long best_full_step_diff=0, best_part_step_diff=0, tmp_step_diff=0, tmp_match=0, best_match=0; long full_match, rra_base; long start_offset, end_offset; int first_full = 1; int first_part = 1; rrd_t rrd; rrd_value_t *data_ptr; - unsigned long rows = (*end - *start) / *step; + unsigned long rows; #ifdef DEBUG fprintf(stderr,"Entered rrd_fetch_fn() searching for the best match\n"); -fprintf(stderr,"Looking for: start %10lu end %10lu step %5lu rows %lu\n", - *start,*end,*step,rows); +fprintf(stderr,"Looking for: start %10lu end %10lu step %5lu\n", + *start,*end,*step); #endif if(rrd_open(filename,&in_file,&rrd, RRD_READONLY)==-1) return(-1); - /* when was the realy last update of this file ? */ + /* when was the really last update of this file ? */ if (((*ds_namv) = (char **) malloc(rrd.stat_head->ds_cnt * sizeof(char*)))==NULL){ rrd_set_error("malloc fetch ds_namv array"); @@ -222,14 +233,15 @@ fprintf(stderr,"Considering: start %10lu end %10lu step %5lu ", cal_start,cal_end, rrd.stat_head->pdp_step * rrd.rra_def[i].pdp_cnt); #endif + /* we need step difference in either full or partial case */ + tmp_step_diff = labs(*step - (rrd.stat_head->pdp_step + * rrd.rra_def[i].pdp_cnt)); /* best full match */ if(cal_end >= *end && cal_start <= *start){ - tmp_step_diff = labs(*step - (rrd.stat_head->pdp_step - * rrd.rra_def[i].pdp_cnt)); - if (first_full || (tmp_step_diff < best_step_diff)){ + if (first_full || (tmp_step_diff < best_full_step_diff)){ first_full=0; - best_step_diff = tmp_step_diff; + best_full_step_diff = tmp_step_diff; best_full_rra=i; #ifdef DEBUG fprintf(stderr,"best full match so far\n"); @@ -247,12 +259,16 @@ fprintf(stderr,"full match, not best\n"); tmp_match -= (cal_start-*start); if (cal_end<*end) tmp_match -= (*end-cal_end); - if (first_part || best_match < tmp_match){ + if (first_part || + (best_match < tmp_match) || + (best_match == tmp_match && + tmp_step_diff < best_part_step_diff)){ #ifdef DEBUG fprintf(stderr,"best partial so far\n"); #endif first_part=0; best_match = tmp_match; + best_part_step_diff = tmp_step_diff; best_part_rra =i; } else { #ifdef DEBUG @@ -278,8 +294,8 @@ fprintf(stderr,"partial match, not best\n"); /* set the wish parameters to their real values */ *step = rrd.stat_head->pdp_step * rrd.rra_def[chosen_rra].pdp_cnt; *start -= (*start % *step); - if (*end % *step) *end += (*step - *end % *step); - rows = (*end - *start) / *step; + *end += (*step - *end % *step); + rows = (*end - *start) / *step + 1; #ifdef DEBUG fprintf(stderr,"We found: start %10lu end %10lu step %5lu rows %lu\n",