# dtrace - is it possible to perform basic mathematical operations on aggregate values?



## Stilez (Jan 14, 2019)

Problem #1

I have a dtrace script which counts 2 aggregates - one aggregates the number of read bytes (@rb), the other, the number of write bytes (@wb).

I want to print the output:  "`@rb`, `@wb`, `(100 * @rb) / @wb` (ratio as percentage)"

Simply outputting an aggregate by itself is easy, but I can't find any guide on printing the value of aggregate A / aggregate B, or placing the current value of the aggregates in variables, to allow integer arithmetic.

How can I calculate and output @rb / @wb in my script?

Problem #2
Similar issue - I want to show equivalent data per second. But data is sampled over the length of a call, which is typically << 1ms.

With integer arithmetic, I need to do the equivalent of `normalize(@value * 1000000,self->microsecs)` and not `normalize(@value,self->microsecs/1000000)` which won't work with integer maths (the latter value will be set to zero seconds). But how do I do this?


----------

