X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_fetch.c;h=404f30f1205b759b8d1e5babb65bec2c3505c3eb;hp=3260904ea30502e59856d627e5a214db4f7ec7a7;hb=0dc5d6d50c0d95ba4f04b656358b26518d4ce854;hpb=5d406a5f504148a9e494ea09b25d9b8d79543516 diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c index 3260904..404f30f 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.9 Copyright by Tobi Oetiker, 1997-2005 ***************************************************************************** * 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); @@ -182,7 +193,7 @@ fprintf(stderr,"Looking for: start %10lu end %10lu step %5lu rows %lu\n", 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,11 +233,12 @@ 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)){ first_full=0; best_step_diff = tmp_step_diff; @@ -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_step_diff)){ #ifdef DEBUG fprintf(stderr,"best partial so far\n"); #endif first_part=0; best_match = tmp_match; + best_step_diff = tmp_step_diff; best_part_rra =i; } else { #ifdef DEBUG