[rrd-users] Re: Advanced CDEF Question

Alex van den Bogaerdt alex at ergens.op.het.net
Sat May 29 23:35:50 MEST 2004


On Sat, May 29, 2004 at 09:41:34AM -0600, Dayton Turner wrote:

> > More important: can *you* tell me why it *is* supposed to work.
> >
> 
> No, I cant. Thats why i asked why it was not supposed to work, so from  
> there I could figure out the  correct way, and hopefully correct it in  
> Cacti for their users too. I suppose I'll just ask them why they used  
> parentheses and hopefully figure out from there where they went wrong.  

The RPN language is described in several tutorials.  Nowhere it is using
parentheses.  I'm not sure _if_ the example exists but this is what is
happening:

You have to rewrite "(a+b)*c" into RPN like this: "a,b,+,c,*"
No need for parentheses.  They do not exist.

> > Having one big CDEF is not wrong.  It is hard to debug, that's all.
> >
> 
> I understand.  I seem to get the option of cdef=<insert whatever i want  
> here> in cacti. How would i separate that example you gave me to work  
> on one line? Is there some sort of separator i can use like a  
> semicolon? ie you gave me:
> 
> 	CDEF:tmp1=a,b,+,c,+,d,+,1024,*,8,*	
> 	CDEF:tmp2=e,f,+,g,+,h,+,1024,*,8,*
> 	CDEF:save=tmp2,tmp1,LT,0,tmp2,tmp1,-,IF

I don't know cacti.  I've not looked into it (or any other front end)
well enough to comment.

To create one large CDEF, take the "save" line and substitute tmp1 and
tmp2 with their expansion.

Perhaps it can be optimized.

You now have:

   if (tmp2 < tmp1)
      return 0
   else
      return (tmp2-tmp1)

which means you have to calculate tmp1 and tmp2 twice.

This can also be optimized:

   intermediate=tmp2-tmp1;
   if intermediate < 0
      return 0
   else
      return intermediate

Translated:
   CDEF:save=tmp2,tmp1,-,DUP,0,LT,EXC,0,EXC,IF

   (and remember to substitute tmp1 and tmp2)

The stack is then processed as follows:

   push tmp2:    tmp2
   push tmp1:    tmp2,tmp1
   compute '-':  (tmp2-tmp1)
   duplicate:    (tmp2-tmp1),(tmp2-tmp1)
   push zero:    (tmp2-tmp1),(tmp2-tmp1),0
   compare:      (tmp2-tmp1),(result of tmp2-tmp1<0)
   exchange:     (result of tmp2-tmp1<0),(tmp2-tmp1)
   push zero:    (tmp2-tmp1<0),(tmp2-tmp1),0
   exchange:     (tmp2-tmp1<0),0,(tmp2-tmp1)
   if-then-else: (result)

This does _not_ improbe readability IMHO.
By substituting tmp1 and tmp2 with their calculation you are, in this
case, not changing the outcome.

For further optimalizations you could take "1024,*,8,*" out of tmp1,tmp2
and apply that to the end result after if-then-else.  Of course, multiplying
by 1024 and then by 8 can be done in one step: multiply by 8192.

Also, "if (tmp2-tmp1 < 0)" can also be written as "if (tmp1-tmp2 >= 0)"
which means you can change the CDEF into:

   CDEF:save=tmp2,tmp1,-,DUP,0,GE,EXC,0,IF,8192,*

This one still fails when NaN is processed.

Alex
-- 
I ask you to respect any "Reply-To" and "Mail-Follow-Up" headers.  If
you reply to me off-list, you'd better tell me you're doing so.  If
you don't, and if I reply to the list, that's your problem, not mine.

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list