X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_graph.c;h=7d1a0760c1265a712c7a34e1fd62b32ed8078e0e;hb=9e6db622e8756105c1322481b34650ecbe15da1a;hp=938132ac442fbb48e720a76d22d3ca97ac5a6b0e;hpb=adb714c5fb12cc758216388e086d16e5225b4141;p=rrdtool.git diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 938132a..7d1a076 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -1,5 +1,5 @@ /**************************************************************************** - * RRDtool 1.2.13 Copyright by Tobi Oetiker, 1997-2006 + * RRDtool 1.2.14 Copyright by Tobi Oetiker, 1997-2006 **************************************************************************** * rrd__graph.c produce graphs from data in rrdfiles ****************************************************************************/ @@ -48,13 +48,14 @@ xlab_t xlab[] = { {10, 0, TMT_MINUTE,5, TMT_MINUTE,20, TMT_MINUTE,20, 0,"%H:%M"}, {30, 0, TMT_MINUTE,10, TMT_HOUR,1, TMT_HOUR,1, 0,"%H:%M"}, {60, 0, TMT_MINUTE,30, TMT_HOUR,2, TMT_HOUR,2, 0,"%H:%M"}, + {60, 24*3600, TMT_MINUTE,30, TMT_HOUR,2, TMT_HOUR,4, 0,"%a %H:%M"}, {180, 0, TMT_HOUR,1, TMT_HOUR,6, TMT_HOUR,6, 0,"%H:%M"}, - {180, 1*24*3600, TMT_HOUR,1, TMT_HOUR,6, TMT_HOUR,6, 0,"%a %H:%M"}, + {180, 24*3600, TMT_HOUR,1, TMT_HOUR,6, TMT_HOUR,12, 0,"%a %H:%M"}, /*{300, 0, TMT_HOUR,3, TMT_HOUR,12, TMT_HOUR,12, 12*3600,"%a %p"}, this looks silly*/ {600, 0, TMT_HOUR,6, TMT_DAY,1, TMT_DAY,1, 24*3600,"%a"}, - {600, 1*24*3600, TMT_HOUR,6, TMT_DAY,1, TMT_DAY,1, 24*3600,"%a %d"}, - {1800, 0, TMT_HOUR,12, TMT_DAY,1, TMT_DAY,2, 24*3600,"%a"}, - {1800, 1*24*3600, TMT_HOUR,12, TMT_DAY,1, TMT_DAY,2, 24*3600,"%a %d"}, + {1200, 0, TMT_HOUR,6, TMT_DAY,1, TMT_DAY,1, 24*3600,"%d"}, + {1800, 0, TMT_HOUR,12, TMT_DAY,1, TMT_DAY,2, 24*3600,"%a %d"}, + {2400, 0, TMT_HOUR,12, TMT_DAY,1, TMT_DAY,2, 24*3600,"%a"}, {3600, 0, TMT_DAY,1, TMT_WEEK,1, TMT_WEEK,1, 7*24*3600,"Week %V"}, {3*3600, 0, TMT_WEEK,1, TMT_MONTH,1, TMT_WEEK,2, 7*24*3600,"Week %V"}, {6*3600, 0, TMT_MONTH,1, TMT_MONTH,1, TMT_MONTH,1, 30*24*3600,"%b"}, @@ -713,7 +714,7 @@ data_fetch(image_desc_t *im ) break; } if (! skip) { - unsigned long ft_step = im->gdes[i].step ; + unsigned long ft_step = im->gdes[i].step ; /* ft_step will record what we got from fetch */ if((rrd_fetch_fn(im->gdes[i].rrd, im->gdes[i].cf, @@ -726,7 +727,6 @@ data_fetch(image_desc_t *im ) return -1; } im->gdes[i].data_first = 1; - im->gdes[i].step = im->step; if (ft_step < im->gdes[i].step) { reduce_data(im->gdes[i].cf_reduce, @@ -1227,7 +1227,7 @@ print_calc(image_desc_t *im, char ***prdata) { long i,ii,validsteps; double printval; - time_t printtime; + struct tm tmvdef; int graphelement = 0; long vidx; int max_ii; @@ -1235,6 +1235,9 @@ print_calc(image_desc_t *im, char ***prdata) char *si_symb = ""; char *percent_s; int prlines = 1; + /* wow initializing tmvdef is quite a task :-) */ + time_t now = time(NULL); + localtime_r(&now,&tmvdef); if (im->imginfo) prlines++; for(i=0;igdes_c;i++){ switch(im->gdes[i].gf){ @@ -1252,7 +1255,7 @@ print_calc(image_desc_t *im, char ***prdata) vidx = im->gdes[i].vidx; if (im->gdes[vidx].gf==GF_VDEF) { /* simply use vals */ printval = im->gdes[vidx].vf.val; - printtime = im->gdes[vidx].vf.when; + localtime_r(&im->gdes[vidx].vf.when,&tmvdef); } else { /* need to calculate max,min,avg etcetera */ max_ii =((im->gdes[vidx].end - im->gdes[vidx].start) @@ -1298,21 +1301,6 @@ print_calc(image_desc_t *im, char ***prdata) } } /* prepare printval */ - if (!strcmp(im->gdes[i].format,"%c")) { /* VDEF time print */ - char ctime_buf[128]; /* PS: for ctime_r, must be >= 26 chars */ - int iii=0; - ctime_r(&printtime,ctime_buf); - while(isprint(ctime_buf[iii])){iii++;} - ctime_buf[iii]='\0'; - if (im->gdes[i].gf == GF_PRINT){ - (*prdata)[prlines-2] = malloc((FMT_LEG_LEN+2)*sizeof(char)); - sprintf((*prdata)[prlines-2],"%s (%lu)",ctime_buf,printtime); - (*prdata)[prlines-1] = NULL; - } else { - sprintf(im->gdes[i].legend,"%s (%lu)",ctime_buf,printtime); - graphelement = 1; - } - } else { if ((percent_s = strstr(im->gdes[i].format,"%S")) != NULL) { /* Magfact is set to -1 upon entry to print_calc. If it * is still less than 0, then we need to run auto_scale. @@ -1331,39 +1319,57 @@ print_calc(image_desc_t *im, char ***prdata) auto_scale(im,&printval,&si_symb,&magfact); } - if (im->gdes[i].gf == GF_PRINT){ + if (im->gdes[i].gf == GF_PRINT){ (*prdata)[prlines-2] = malloc((FMT_LEG_LEN+2)*sizeof(char)); (*prdata)[prlines-1] = NULL; - if (bad_format(im->gdes[i].format)) { - rrd_set_error("bad format for PRINT in '%s'", im->gdes[i].format); + if (im->gdes[i].strftm){ + strftime((*prdata)[prlines-2],FMT_LEG_LEN,im->gdes[i].format,&tmvdef); + } else { + if (bad_format(im->gdes[i].format)) { + rrd_set_error("bad format for PRINT in '%s'", im->gdes[i].format); return -1; - } + } + #ifdef HAVE_SNPRINTF - snprintf((*prdata)[prlines-2],FMT_LEG_LEN,im->gdes[i].format,printval,si_symb); + snprintf((*prdata)[prlines-2],FMT_LEG_LEN,im->gdes[i].format,printval,si_symb); #else - sprintf((*prdata)[prlines-2],im->gdes[i].format,printval,si_symb); + sprintf((*prdata)[prlines-2],im->gdes[i].format,printval,si_symb); #endif - } else { + } + } else { /* GF_GPRINT */ - if (bad_format(im->gdes[i].format)) { + if (im->gdes[i].strftm){ + strftime(im->gdes[i].legend,FMT_LEG_LEN,im->gdes[i].format,&tmvdef); + } else { + if (bad_format(im->gdes[i].format)) { rrd_set_error("bad format for GPRINT in '%s'", im->gdes[i].format); return -1; - } + } #ifdef HAVE_SNPRINTF - snprintf(im->gdes[i].legend,FMT_LEG_LEN-2,im->gdes[i].format,printval,si_symb); + snprintf(im->gdes[i].legend,FMT_LEG_LEN-2,im->gdes[i].format,printval,si_symb); #else - sprintf(im->gdes[i].legend,im->gdes[i].format,printval,si_symb); + sprintf(im->gdes[i].legend,im->gdes[i].format,printval,si_symb); #endif - graphelement = 1; - } - } + } + graphelement = 1; + } break; case GF_LINE: case GF_AREA: case GF_TICK: + graphelement = 1; + break; case GF_HRULE: + if(isnan(im->gdes[i].yrule)) { /* we must set this here or the legend printer can not decide to print the legend */ + im->gdes[i].yrule=im->gdes[im->gdes[i].vidx].vf.val; + }; + graphelement = 1; + break; case GF_VRULE: + if(im->gdes[i].xrule == 0) { /* again ... the legend printer needs it*/ + im->gdes[i].xrule = im->gdes[im->gdes[i].vidx].vf.when; + }; graphelement = 1; break; case GF_COMMENT: @@ -2862,9 +2868,6 @@ graph_paint(image_desc_t *im, char ***calcpr) switch(im->gdes[i].gf){ case GF_HRULE: - if(isnan(im->gdes[i].yrule)) { /* fetch variable */ - im->gdes[i].yrule = im->gdes[im->gdes[i].vidx].vf.val; - }; if(im->gdes[i].yrule >= im->minval && im->gdes[i].yrule <= im->maxval) gfx_new_line(im->canvas, @@ -2873,9 +2876,6 @@ graph_paint(image_desc_t *im, char ***calcpr) 1.0,im->gdes[i].col); break; case GF_VRULE: - if(im->gdes[i].xrule == 0) { /* fetch variable */ - im->gdes[i].xrule = im->gdes[im->gdes[i].vidx].vf.when; - }; if(im->gdes[i].xrule >= im->start && im->gdes[i].xrule <= im->end) gfx_new_line(im->canvas, @@ -2943,6 +2943,7 @@ gdes_alloc(image_desc_t *im){ im->gdes[im->gdes_c-1].col = 0x0; im->gdes[im->gdes_c-1].legend[0]='\0'; im->gdes[im->gdes_c-1].format[0]='\0'; + im->gdes[im->gdes_c-1].strftm=0; im->gdes[im->gdes_c-1].rrd[0]='\0'; im->gdes[im->gdes_c-1].ds=-1; im->gdes[im->gdes_c-1].cf_reduce=CF_AVERAGE; @@ -3803,7 +3804,7 @@ printf("DEBUG: %3li:%10.2f %c\n",step,array[step],step==field?'*':' '); if (cnt) { if (dst->vf.op == VDEF_TOTAL) { dst->vf.val = sum*src->step; - dst->vf.when = cnt*src->step; /* not really "when" */ + dst->vf.when = 0; /* no time component */ } else { dst->vf.val = sum/cnt; dst->vf.when = 0; /* no time component */ @@ -3891,21 +3892,21 @@ printf("DEBUG: %3li:%10.2f %c\n",step,array[step],step==field?'*':' '); if (cnt) { if (dst->vf.op == VDEF_LSLSLOPE) { dst->vf.val = slope; - dst->vf.when = cnt*src->step; + dst->vf.when = 0; } else if (dst->vf.op == VDEF_LSLINT) { dst->vf.val = y_intercept; - dst->vf.when = cnt*src->step; + dst->vf.when = 0; } else if (dst->vf.op == VDEF_LSLCORREL) { dst->vf.val = correl; - dst->vf.when = cnt*src->step; + dst->vf.when = 0; }; } else { dst->vf.val = DNAN; dst->vf.when = 0; } - } - break; + } + break; } return 0; }