Trying to write a btrace script for measuring Loader performance. Time and count calls to the Loader.get and Loader.batchUpdate methods. This is doable pretty easy but it points out some limitations.
@OnMethod(clazz = "purequery.loader.GenericPQLoader", method = "get", location = @Location(Kind.RETURN))
public static void onCallMapAgentReturn()
{
if (executingVerb != null) {
AggregationKey key = newAggregationKey(executingVerb);
int duration = (int) (timeNanos() - timeStampNanos) / 1000;
BTraceUtils.print("Duration of "); BTraceUtils.print(executingVerb); BTraceUtils.print(" "); BTraceUtils.println(duration);
addToAggregation(histogram, key, duration);
addToAggregation(average, key, duration);
addToAggregation(max, key, duration);
addToAggregation(min, key, duration);
addToAggregation(sum, key, duration);
addToAggregation(count, key, duration);
addToAggregation(globalCount, duration);
executingVerb = null;
}
}
This code basically adds measurements for the verb measurementVerb to the stats. You need this code called when we leave the Loader.get or Loader.batchUpdate methods. The executionVerb indicates whether it's a get or a batchupdate. My first attempt at this put most of that method in a seperate static method called by the onGetReturn and onBatchUpdateReturn methods. This was rejected by the btracec compiler because you can only call BTraceUtils methods in the script. This restriction will quickly make scripts very big and hard to maintain as you end up copy and pasting the same code in a bunch of places.
I'm glad you like the BTrace tool. I've been bothered by the inability to use utility methods in the scripts for some time. But since there had not been many active users it didn't seem justified to spend a lot of time to get this feature right (it *definitely* will require some clever ideas to achieve this and not to compromise the traced application).
You could file an RFE for BTrace summing up your expectations. And we will try to implement it :)
Also, if you feel like participating this would be more than welcome. The project is open and not funded by any big (or even small) company.
Posted by: Jaroslav Bachorik | June 08, 2009 at 02:39 PM