LivePerf allows the user to create custom queries where performance counters can be processed through the use of functions. Below is a reference of the available functions:
The most powerful function is the Script which allows you to use Java language syntax to process counters and return a result.
<function op="script"> <param id=""/> <code>java function body</code> </function>
The contents of the <code> tag are the body of a complete Java function, which means all arithmetical operators, conditional statements, loops and local variables are allowed. Code must return a value of type Double, or null, by using the return statement. If more exit points are present, all must follow the same rule.
Note that returning null has the significance of rejecting the current set of values, without sending any data to screen controls, effectively performing a filter.
Example:
<query> <resource id="user" rid="-/-/root/Processor/[% User Time]"/> <resource id="priv" rid="-/-/root/Processor/[% Privileged Time]"/> <function id="total" op="script" name="Total Time" description="Total processor time (user + system)"> <param id="user"/> <param id="priv"/> <code>return user + priv;</code> </function> </query>
The example above sums up processor user time and system (privileged) time and returns it as a third counter which will be displayed as 'Total Time'.
Values for all resources specified through the <param> tag are available as local variables, named after their id. When id is not a valid Java identifier, names 'r0', 'r1' and so on will be used, with 'r0' identifying the first parameter. In the example above both 'user' and 'priv' were valid Java identifiers.
Accepts one parameter as input and accumulates its values over time. Returns the current accumulated value.
<function op="sum"> <param id=""/> </function>
Accepts one parameter as input and calculates an average of its values over time. Returns the current average value.
<function op="average"> <param id=""/> </function>
Accepts one parameter as input and returns the difference between its current value and the previous (differential).
f(x, t) = x(t1) - x(t0); where x = value, t = time <function op="diff"> <param id=""/> </function>
Accepts one parameter as input and returns the time relative difference between its current value and the previous.
f(x, t) = ( x(t1) - x(t0) ) / ( t1- t0 ); where x = value, t = time <function op="timediff"> <param id=""/> </function>
Accepts one parameter as input and returns its value unchanged. Mostly used internaly by the application itself.
<function op="identity"> <param id=""/> </function>
Accepts one parameter as input and returns its value unchanged but only if matches one of the predefined values. Multiple <value> tags are allowed.
<function op="filter"> <param id=""/> <value>value1</value> <value>value2</value> ... </function>
If no value is matched then this function rejects the current data and screen controls are not updated.