index fb1929eee8c835c0899b1f373cd0a618ad433fe6..1206644c78f683aa6e67d2586bae267cf68d1185 100644 (file)
--- a/program/src/rrd_fetch.c
+++ b/program/src/rrd_fetch.c
/*****************************************************************************
/*****************************************************************************
- * RRDtool 1.0.33 Copyright Tobias Oetiker, 1997 - 2000
+ * RRDtool 1.1.x Copyright Tobias Oetiker, 1997 - 2002
*****************************************************************************
* rrd_fetch.c read date from an rrd to use for further processing
*****************************************************************************
* $Id$
* $Log$
*****************************************************************************
* rrd_fetch.c read date from an rrd to use for further processing
*****************************************************************************
* $Id$
* $Log$
+ * 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 <ssinyagin@yahoo.com>
+ *
+ * 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
+ *
+ * Revision 1.4 2002/02/01 20:34:49 oetiker
+ * fixed version number and date/time
+ *
* Revision 1.3 2001/12/24 06:51:49 alex
* A patch of size 44Kbytes... in short:
*
* Revision 1.3 2001/12/24 06:51:49 alex
* A patch of size 44Kbytes... in short:
*
time_t start_tmp=0, end_tmp=0;
enum cf_en cf_idx;
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;
/* init start and end time */
char *parsetime_error = NULL;
/* init start and end time */
return -1;
}
return -1;
}
- if ((cf_idx=cf_conv(argv[optind+1])) == -1 ){
+ if ((int)(cf_idx=cf_conv(argv[optind+1])) == -1 ){
return -1;
}
return -1;
}
return(-1);
}
return(-1);
}
- for(i=0;i<rrd.stat_head->ds_cnt;i++){
+ for(i=0;(unsigned long)i<rrd.stat_head->ds_cnt;i++){
if ((((*ds_namv)[i]) = malloc(sizeof(char) * DS_NAM_SIZE))==NULL){
rrd_set_error("malloc fetch ds_namv entry");
rrd_free(&rrd);
if ((((*ds_namv)[i]) = malloc(sizeof(char) * DS_NAM_SIZE))==NULL){
rrd_set_error("malloc fetch ds_namv entry");
rrd_free(&rrd);
}
/* find the rra which best matches the requirements */
}
/* find the rra which best matches the requirements */
- for(i=0;i<rrd.stat_head->rra_cnt;i++){
+ for(i=0;(unsigned)i<rrd.stat_head->rra_cnt;i++){
if(cf_conv(rrd.rra_def[i].cf_nam) == cf_idx){
cal_end = (rrd.live_head->last_up - (rrd.live_head->last_up
if(cf_conv(rrd.rra_def[i].cf_nam) == cf_idx){
cal_end = (rrd.live_head->last_up - (rrd.live_head->last_up
cal_start,cal_end,
rrd.stat_head->pdp_step * rrd.rra_def[i].pdp_cnt);
#endif
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){
/* 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;
if (first_full || (tmp_step_diff < best_step_diff)){
first_full=0;
best_step_diff = tmp_step_diff;
tmp_match -= (cal_start-*start);
if (cal_end<*end)
tmp_match -= (*end-cal_end);
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;
#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
best_part_rra =i;
} else {
#ifdef DEBUG
*ds_cnt = rrd.stat_head->ds_cnt;
if (((*data) = malloc(*ds_cnt * rows * sizeof(rrd_value_t)))==NULL){
rrd_set_error("malloc fetch data area");
*ds_cnt = rrd.stat_head->ds_cnt;
if (((*data) = malloc(*ds_cnt * rows * sizeof(rrd_value_t)))==NULL){
rrd_set_error("malloc fetch data area");
- for (i=0;i<*ds_cnt;i++)
+ for (i=0;(unsigned long)i<*ds_cnt;i++)
free((*ds_namv)[i]);
free(*ds_namv);
rrd_free(&rrd);
free((*ds_namv)[i]);
free(*ds_namv);
rrd_free(&rrd);
* *ds_cnt
* sizeof(rrd_value_t))),SEEK_SET) != 0){
rrd_set_error("seek error in RRA");
* *ds_cnt
* sizeof(rrd_value_t))),SEEK_SET) != 0){
rrd_set_error("seek error in RRA");
- for (i=0;i<*ds_cnt;i++)
+ for (i=0;(unsigned)i<*ds_cnt;i++)
free((*ds_namv)[i]);
free(*ds_namv);
rrd_free(&rrd);
free((*ds_namv)[i]);
free(*ds_namv);
rrd_free(&rrd);
/* step trough the array */
for (i=start_offset;
/* step trough the array */
for (i=start_offset;
- i<(long)(rrd.rra_def[chosen_rra].row_cnt-end_offset);
+ i< (signed)rrd.rra_def[chosen_rra].row_cnt - end_offset;
i++){
/* no valid data yet */
if (i<0) {
#ifdef DEBUG
fprintf(stderr,"pre fetch %li -- ",i);
#endif
i++){
/* no valid data yet */
if (i<0) {
#ifdef DEBUG
fprintf(stderr,"pre fetch %li -- ",i);
#endif
- for(ii=0;ii<*ds_cnt;ii++){
+ for(ii=0;(unsigned)ii<*ds_cnt;ii++){
*(data_ptr++) = DNAN;
#ifdef DEBUG
fprintf(stderr,"%10.2f ",*(data_ptr-1));
*(data_ptr++) = DNAN;
#ifdef DEBUG
fprintf(stderr,"%10.2f ",*(data_ptr-1));
}
}
/* past the valid data area */
}
}
/* past the valid data area */
- else if (i>=rrd.rra_def[chosen_rra].row_cnt) {
+ else if (i >= (signed)rrd.rra_def[chosen_rra].row_cnt) {
#ifdef DEBUG
fprintf(stderr,"post fetch %li -- ",i);
#endif
#ifdef DEBUG
fprintf(stderr,"post fetch %li -- ",i);
#endif
- for(ii=0;ii<*ds_cnt;ii++){
+ for(ii=0;(unsigned)ii<*ds_cnt;ii++){
*(data_ptr++) = DNAN;
#ifdef DEBUG
fprintf(stderr,"%10.2f ",*(data_ptr-1));
*(data_ptr++) = DNAN;
#ifdef DEBUG
fprintf(stderr,"%10.2f ",*(data_ptr-1));
} else {
/* OK we are inside the valid area but the pointer has to
* be wrapped*/
} else {
/* OK we are inside the valid area but the pointer has to
* be wrapped*/
- if (rra_pointer >= rrd.rra_def[chosen_rra].row_cnt) {
+ if (rra_pointer >= (signed)rrd.rra_def[chosen_rra].row_cnt) {
rra_pointer -= rrd.rra_def[chosen_rra].row_cnt;
if(fseek(in_file,(rra_base+rra_pointer
* *ds_cnt
* sizeof(rrd_value_t)),SEEK_SET) != 0){
rrd_set_error("wrap seek in RRA did fail");
rra_pointer -= rrd.rra_def[chosen_rra].row_cnt;
if(fseek(in_file,(rra_base+rra_pointer
* *ds_cnt
* sizeof(rrd_value_t)),SEEK_SET) != 0){
rrd_set_error("wrap seek in RRA did fail");
- for (ii=0;ii<*ds_cnt;ii++)
+ for (ii=0;(unsigned)ii<*ds_cnt;ii++)
free((*ds_namv)[ii]);
free(*ds_namv);
rrd_free(&rrd);
free((*ds_namv)[ii]);
free(*ds_namv);
rrd_free(&rrd);
sizeof(rrd_value_t),
*ds_cnt,in_file) != rrd.stat_head->ds_cnt){
rrd_set_error("fetching cdp from rra");
sizeof(rrd_value_t),
*ds_cnt,in_file) != rrd.stat_head->ds_cnt){
rrd_set_error("fetching cdp from rra");
- for (ii=0;ii<*ds_cnt;ii++)
+ for (ii=0;(unsigned)ii<*ds_cnt;ii++)
free((*ds_namv)[ii]);
free(*ds_namv);
rrd_free(&rrd);
free((*ds_namv)[ii]);
free(*ds_namv);
rrd_free(&rrd);