X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_dump.c;h=5d76896845f83bcae02d57c06d1aa1fcec912860;hb=818549a636c390fb4a8390a7e2195a52293cd56b;hp=a22aa02dab192da9d0cb6c3b51407fd513ff89d9;hpb=3882bb0c2d15f97298aaa7602d6353a1888f5547;p=rrdtool.git diff --git a/src/rrd_dump.c b/src/rrd_dump.c index a22aa02..5d76896 100644 --- a/src/rrd_dump.c +++ b/src/rrd_dump.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.2.16 Copyright by Tobi Oetiker, 1997-2006 + * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007 ***************************************************************************** * rrd_dump Display a RRD ***************************************************************************** @@ -77,13 +77,14 @@ rrd_dump_r(const char *filename, char *outname) time_t now; char somestring[255]; rrd_value_t my_cdp; - long rra_base, rra_start, rra_next; - FILE *in_file; + off_t rra_base, rra_start, rra_next; + rrd_file_t *rrd_file; FILE *out_file; rrd_t rrd; rrd_value_t value; struct tm tm; - if(rrd_open(filename, &in_file,&rrd, RRD_READONLY)==-1){ + rrd_file = rrd_open(filename, &rrd, RRD_READONLY); + if (rrd_file == NULL) { rrd_free(&rrd); return(-1); } @@ -115,43 +116,43 @@ rrd_dump_r(const char *filename, char *outname) fprintf(out_file, "\t %ld \n\n", rrd.live_head->last_up,somestring); for(i=0;ids_cnt;i++){ - fprintf(out_file, "\t\n"); - fprintf(out_file, "\t\t %s \n",rrd.ds_def[i].ds_nam); - fprintf(out_file, "\t\t %s \n",rrd.ds_def[i].dst); - if (dst_conv(rrd.ds_def[i].dst) != DST_CDEF) { - fprintf(out_file, "\t\t %lu \n",rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt); - if (isnan(rrd.ds_def[i].par[DS_min_val].u_val)){ - fprintf(out_file, "\t\t NaN \n"); - } else { - fprintf(out_file, "\t\t %0.10e \n",rrd.ds_def[i].par[DS_min_val].u_val); - } - if (isnan(rrd.ds_def[i].par[DS_max_val].u_val)){ - fprintf(out_file, "\t\t NaN \n"); - } else { - fprintf(out_file, "\t\t %0.10e \n",rrd.ds_def[i].par[DS_max_val].u_val); - } - } else { /* DST_CDEF */ - char *str; - rpn_compact2str((rpn_cdefds_t *) &(rrd.ds_def[i].par[DS_cdef]),rrd.ds_def,&str); - fprintf(out_file, "\t\t %s \n", str); - free(str); - } - fprintf(out_file, "\n\t\t\n"); - fprintf(out_file, "\t\t %s \n",rrd.pdp_prep[i].last_ds); - if (isnan(rrd.pdp_prep[i].scratch[PDP_val].u_val)){ - fprintf(out_file, "\t\t NaN \n"); - } else { - fprintf(out_file, "\t\t %0.10e \n",rrd.pdp_prep[i].scratch[PDP_val].u_val); - } - fprintf(out_file, "\t\t %lu \n", - rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt); + fprintf(out_file, "\t\n"); + fprintf(out_file, "\t\t %s \n",rrd.ds_def[i].ds_nam); + fprintf(out_file, "\t\t %s \n",rrd.ds_def[i].dst); + if (dst_conv(rrd.ds_def[i].dst) != DST_CDEF) { + fprintf(out_file, "\t\t %lu \n",rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt); + if (isnan(rrd.ds_def[i].par[DS_min_val].u_val)){ + fprintf(out_file, "\t\t NaN \n"); + } else { + fprintf(out_file, "\t\t %0.10e \n",rrd.ds_def[i].par[DS_min_val].u_val); + } + if (isnan(rrd.ds_def[i].par[DS_max_val].u_val)){ + fprintf(out_file, "\t\t NaN \n"); + } else { + fprintf(out_file, "\t\t %0.10e \n",rrd.ds_def[i].par[DS_max_val].u_val); + } + } else { /* DST_CDEF */ + char *str=NULL; + rpn_compact2str((rpn_cdefds_t *) &(rrd.ds_def[i].par[DS_cdef]),rrd.ds_def,&str); + fprintf(out_file, "\t\t %s \n", str); + free(str); + } + fprintf(out_file, "\n\t\t\n"); + fprintf(out_file, "\t\t %s \n",rrd.pdp_prep[i].last_ds); + if (isnan(rrd.pdp_prep[i].scratch[PDP_val].u_val)){ + fprintf(out_file, "\t\t NaN \n"); + } else { + fprintf(out_file, "\t\t %0.10e \n",rrd.pdp_prep[i].scratch[PDP_val].u_val); + } + fprintf(out_file, "\t\t %lu \n", + rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt); - fprintf(out_file, "\t\n\n"); - } + fprintf(out_file, "\t\n\n"); + } fputs("", out_file); - rra_base=ftell(in_file); + rra_base = rrd_file->header_len; rra_next = rra_base; for(i=0;irra_cnt;i++){ @@ -314,7 +315,7 @@ rrd_dump_r(const char *filename, char *outname) fprintf(out_file, "\t\t\n"); fprintf(out_file, "\t\t\n"); - fseek(in_file,(rra_start + rrd_seek(rrd_file,(rra_start +(rrd.rra_ptr[i].cur_row+1) * rrd.stat_head->ds_cnt * sizeof(rrd_value_t)),SEEK_SET); @@ -323,7 +324,7 @@ rrd_dump_r(const char *filename, char *outname) for(ix=0;ix=rrd.rra_def[i].row_cnt) { - fseek(in_file,rra_start,SEEK_SET); + rrd_seek(rrd_file,rra_start,SEEK_SET); ii=0; /* wrap if max row cnt is reached */ } now = (rrd.live_head->last_up @@ -339,8 +340,8 @@ rrd_dump_r(const char *filename, char *outname) # error "Need strftime" #endif fprintf(out_file, "\t\t\t ",somestring,(int)now); - for(iii=0;iiids_cnt;iii++){ - fread(&my_cdp,sizeof(rrd_value_t),1,in_file); + for(iii=0;iiids_cnt;iii++){ + rrd_read(rrd_file, &my_cdp,sizeof(rrd_value_t)*1); if (isnan(my_cdp)){ fprintf(out_file, " NaN "); } else { @@ -350,11 +351,11 @@ rrd_dump_r(const char *filename, char *outname) fprintf(out_file, "\n"); } fprintf(out_file, "\t\t\n\t\n"); - + } fprintf(out_file, "\n"); rrd_free(&rrd); - fclose(in_file); + close(rrd_file->fd); if (out_file != stdout) { fclose(out_file); @@ -362,6 +363,3 @@ rrd_dump_r(const char *filename, char *outname) return(0); } - - -