index ab2bd36ca909797973d37ac864189a2b5b214e88..65748cc491cf1933ee48934aa2b7ebb9dc3463dc 100644 (file)
#include "rrd_tool.h"
#include "rrd_rpncalc.h"
#include "rrd_tool.h"
#include "rrd_rpncalc.h"
+#include "rrd_graph.h"
#include <limits.h>
short addop2str(enum op_en op, enum op_en op_type, char *op_str,
#include <limits.h>
short addop2str(enum op_en op, enum op_en op_type, char *op_str,
return -1;
}
(*rpnc)[i].val = (short) temp;
return -1;
}
(*rpnc)[i].val = (short) temp;
- } else if (rpnp[i].op == OP_VARIABLE) {
+ } else if (rpnp[i].op == OP_VARIABLE ||
+ rpnp[i].op == OP_PREV_OTHER) {
(*rpnc)[i].val = (short) rpnp[i].ptr;
}
}
(*rpnc)[i].val = (short) rpnp[i].ptr;
}
}
rpnp[i].op = (long) rpnc[i].op;
if (rpnp[i].op == OP_NUMBER) {
rpnp[i].val = (double) rpnc[i].val;
rpnp[i].op = (long) rpnc[i].op;
if (rpnp[i].op == OP_NUMBER) {
rpnp[i].val = (double) rpnc[i].val;
- } else if (rpnp[i].op == OP_VARIABLE) {
+ } else if (rpnp[i].op == OP_VARIABLE ||
+ rpnp[i].op == OP_PREV_OTHER) {
rpnp[i].ptr = (long) rpnc[i].val;
}
}
rpnp[i].ptr = (long) rpnc[i].val;
}
}
char *ds_name = ds_def[rpnc[i].val].ds_nam;
add_op(OP_VARIABLE, ds_name)
}
char *ds_name = ds_def[rpnc[i].val].ds_nam;
add_op(OP_VARIABLE, ds_name)
}
+
+ if (rpnc[i].op == OP_PREV_OTHER) {
+ char *ds_name = ds_def[rpnc[i].val].ds_nam;
+ add_op(OP_VARIABLE, ds_name)
+ }
+
#undef add_op
#define add_op(VV,VVV) \
#undef add_op
#define add_op(VV,VVV) \
* occur too often. */
for (i = 0; rpnp[i].op != OP_END; i++) {
if (rpnp[i].op == OP_TIME || rpnp[i].op == OP_LTIME ||
* occur too often. */
for (i = 0; rpnp[i].op != OP_END; i++) {
if (rpnp[i].op == OP_TIME || rpnp[i].op == OP_LTIME ||
- rpnp[i].op == OP_PREV)
+ rpnp[i].op == OP_PREV || rpnp[i].op == OP_COUNT)
{
rrd_set_error(
{
rrd_set_error(
- "operators time, ltime and prev not supported with DS COMPUTE");
+ "operators time, ltime, prev and count not supported with DS COMPUTE");
free(rpnp);
return;
}
free(rpnp);
return;
}
*/
long lookup_DS(void *rrd_vptr,char *ds_name)
{
*/
long lookup_DS(void *rrd_vptr,char *ds_name)
{
- int i;
+ unsigned int i;
rrd_t *rrd;
rrd = (rrd_t *) rrd_vptr;
rrd_t *rrd;
rrd = (rrd_t *) rrd_vptr;
expr+=strlen(#VVV); \
}
expr+=strlen(#VVV); \
}
+
+#define match_op_param(VV,VVV) \
+ else if (sscanf(expr, #VVV "(" DEF_NAM_FMT ")",vname) == 1) { \
+ int length = 0; \
+ if ((length = strlen(#VVV)+strlen(vname)+2, \
+ expr[length] == ',' || expr[length] == '\0') ) { \
+ rpnp[steps].op = VV; \
+ rpnp[steps].ptr = (*lookup)(key_hash,vname); \
+ if (rpnp[steps].ptr < 0) { \
+ free(rpnp); \
+ return NULL; \
+ } else expr+=length; \
+ } \
+ }
+
match_op(OP_ADD,+)
match_op(OP_SUB,-)
match_op(OP_MUL,*)
match_op(OP_ADD,+)
match_op(OP_SUB,-)
match_op(OP_MUL,*)
match_op(OP_UN,UN)
match_op(OP_NEGINF,NEGINF)
match_op(OP_NE,NE)
match_op(OP_UN,UN)
match_op(OP_NEGINF,NEGINF)
match_op(OP_NE,NE)
+ match_op(OP_COUNT,COUNT)
+ match_op_param(OP_PREV_OTHER,PREV)
match_op(OP_PREV,PREV)
match_op(OP_INF,INF)
match_op(OP_ISINF,ISINF)
match_op(OP_PREV,PREV)
match_op(OP_INF,INF)
match_op(OP_ISINF,ISINF)
#undef match_op
#undef match_op
- else if ((sscanf(expr,"%29[_A-Za-z0-9]%n",
+ else if ((sscanf(expr, DEF_NAM_FMT "%n",
vname,&pos) == 1)
&& ((rpnp[steps].ptr = (*lookup)(key_hash,vname)) != -1)){
rpnp[steps].op = OP_VARIABLE;
vname,&pos) == 1)
&& ((rpnp[steps].ptr = (*lookup)(key_hash,vname)) != -1)){
rpnp[steps].op = OP_VARIABLE;
}
}
break;
}
}
break;
+ case OP_COUNT:
+ rpnstack -> s[++stptr] = (output_idx+1); /* Note: Counter starts at 1 */
+ break;
case OP_PREV:
case OP_PREV:
- if ((output_idx-1) <= 0) {
+ if ((output_idx) <= 0) {
rpnstack -> s[++stptr] = DNAN;
} else {
rpnstack -> s[++stptr] = output[output_idx-1];
}
break;
rpnstack -> s[++stptr] = DNAN;
} else {
rpnstack -> s[++stptr] = output[output_idx-1];
}
break;
+ case OP_PREV_OTHER:
+ if ((output_idx) <= 0) {
+ rpnstack -> s[++stptr] = DNAN;
+ } else {
+ rpnstack -> s[++stptr] = rpnp[rpnp[rpi].ptr].data[output_idx-1];
+ }
+ break;
case OP_UNKN:
rpnstack -> s[++stptr] = DNAN;
break;
case OP_UNKN:
rpnstack -> s[++stptr] = DNAN;
break;
tzoffset( time_t now ){
int gm_sec, gm_min, gm_hour, gm_yday, gm_year,
l_sec, l_min, l_hour, l_yday, l_year;
tzoffset( time_t now ){
int gm_sec, gm_min, gm_hour, gm_yday, gm_year,
l_sec, l_min, l_hour, l_yday, l_year;
- struct tm *t;
+ struct tm t;
int off;
int off;
- t = gmtime(&now);
- gm_sec = t->tm_sec;
- gm_min = t->tm_min;
- gm_hour = t->tm_hour;
- gm_yday = t->tm_yday;
- gm_year = t->tm_year;
- t = localtime(&now);
- l_sec = t->tm_sec;
- l_min = t->tm_min;
- l_hour = t->tm_hour;
- l_yday = t->tm_yday;
- l_year = t->tm_year;
+ gmtime_r(&now, &t);
+ gm_sec = t.tm_sec;
+ gm_min = t.tm_min;
+ gm_hour = t.tm_hour;
+ gm_yday = t.tm_yday;
+ gm_year = t.tm_year;
+ localtime_r(&now, &t);
+ l_sec = t.tm_sec;
+ l_min = t.tm_min;
+ l_hour = t.tm_hour;
+ l_yday = t.tm_yday;
+ l_year = t.tm_year;
off = (l_sec-gm_sec)+(l_min-gm_min)*60+(l_hour-gm_hour)*3600;
if ( l_yday > gm_yday || l_year > gm_year){
off += 24*3600;
off = (l_sec-gm_sec)+(l_min-gm_min)*60+(l_hour-gm_hour)*3600;
if ( l_yday > gm_yday || l_year > gm_year){
off += 24*3600;