after adding the add-on to a project based on deltaspike the usage is simple, just annotate a method or the whole class with @InvocationMonitored and create a cdi-observer for MonitoredMethodInvocationsEvent. the add-on will collect information about the monitored method-invocations during a request and you can process the entries based on your requirements. the following example illustrates a sample usage. it's up to you which information you use and how you process it (e.g. logging it, storing it in a persistent store,...).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MonitoredMethodInvocationProcessor | |
{ | |
//... | |
public void onMonitoredMethodInvocations(@Observes MonitoredMethodInvocationsEvent methodInvocationsEvent) | |
{ | |
String userId = this.userHolder.getCurrentUserId(); | |
for (MethodInvocationDescriptor methodInvocation : methodInvocationsEvent.getMethodInvocationDescriptors()) | |
{ | |
if (methodInvocation.getException() != null) | |
{ | |
error(userId + "@" + methodInvocation + ":L" + methodInvocation.getException().getStackTrace()[0].getLineNumber()); | |
} | |
else | |
{ | |
trace(userId + "@" + methodInvocation); | |
} | |
if (methodInvocation.getExecutionTime() > this.maxThreshold) | |
{ | |
warn("slow method-invocation detected: " + methodInvocation.getMethodDetails()); | |
} | |
} | |
} | |
//... | |
} |
the optional jsf module allows to record the current view-id per entry and the processing after the rendering-phase.
the add-on is available here.