Top Description Fields Constructors Methods
groovy.lang

public Class BenchmarkInterceptor

extends Object
implements Interceptor
Class Inheritance
All Implemented Interfaces
groovy.lang.Interceptor
Imports
java.util.HashMap, .Iterator, .LinkedHashMap, .LinkedList, .List, .Map

Interceptor that registers the timestamp of each method call before and after invocation. The timestamps are stored internally and can be retrieved through the with the
getCalls()
and
statistic()
API.

Example usage:

def proxy = ProxyMetaClass.getInstance(ArrayList.class)
proxy.interceptor = new BenchmarkInterceptor()
proxy.use {
    def list = (0..10000).collect{ it }
    4.times { list.size() }
    4000.times { list.set(it, it+1) }
}
proxy.interceptor.statistic()
Which produces the following output:
[[size, 4, 0], [set, 4000, 21]]

Field Summary

Modifier and TypeField and Description
protected Map<K, V>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

result
afterInvoke
(Object
receiver object for the called method
object
,
String
name of the called method
methodName
,
Object[]
arguments to the called method
arguments
,
Object
result of the executed method call or result of beforeInvoke if method was not called
result
)

Implements groovy.lang.Interceptor.afterInvoke.

This code is executed after the method is called.
public Object

Returns:

null relays this result.
beforeInvoke
(Object
receiver object for the method call
object
,
String
name of the method to call
methodName
,
Object[]
arguments to the method call
arguments
)

Implements groovy.lang.Interceptor.beforeInvoke.

This code is executed before the method is called.
public boolean

Returns:

true
doInvoke
()

Implements groovy.lang.Interceptor.doInvoke.

The call should be invoked separately
public Map<K, V>
getCalls()

Returns the raw data associated with the current benchmark run.

public void
reset()

Resets all the benchmark data on this object.

public List<E>

Returns:

a list of lines, each item is [methodname, numberOfCalls, accumulatedTime]
statistic
()

Returns benchmark statistics as a List<Object[]>.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callsback to summary
protected Map<K, V> calls

Constructor Detail

BenchmarkInterceptorback to summary
public BenchmarkInterceptor()

Method Detail

afterInvokeback to summary
public Object afterInvoke(Object object, String methodName, Object[] arguments, Object result)

Implements groovy.lang.Interceptor.afterInvoke.

This code is executed after the method is called.

Parameters
object:Object

receiver object for the called method

methodName:String

name of the called method

arguments:Object[]

arguments to the called method

result:Object

result of the executed method call or result of beforeInvoke if method was not called

Returns:Object

result

beforeInvokeback to summary
public Object beforeInvoke(Object object, String methodName, Object[] arguments)

Implements groovy.lang.Interceptor.beforeInvoke.

This code is executed before the method is called.

Parameters
object:Object

receiver object for the method call

methodName:String

name of the method to call

arguments:Object[]

arguments to the method call

Returns:Object

null relays this result.

doInvokeback to summary
public boolean doInvoke()

Implements groovy.lang.Interceptor.doInvoke.

The call should be invoked separately

Returns:boolean

true

getCallsback to summary
public Map<K, V> getCalls()

Returns the raw data associated with the current benchmark run.

resetback to summary
public void reset()

Resets all the benchmark data on this object.

statisticback to summary
public List<E> statistic()

Returns benchmark statistics as a List<Object[]>. AccumulateTime is measured in milliseconds and is as accurate as System.currentTimeMillis() allows it to be.

Returns:List<E>

a list of lines, each item is [methodname, numberOfCalls, accumulatedTime]