Class ObjectProfiler
java.lang.Object
com.atlassian.util.profiling.object.ObjectProfiler
- Author:
- Scott Farquhar
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static SetgetAllInterfaces(Class clazz) static ObjectgetProfiledObject(Class interfaceClazz, Object o) Given a class, and an interface that it implements, return a proxied version of the class that implements the interface.static StringgetTrimmedClassName(Method method) Given a method, get the Method name, with no package information.static Objectprofile(String caption, Profilable profilable) A simple convenience wrapper for profiling a block of code, reduces repetition of captions used by the Timers#timer method.static ObjectprofiledInvoke(Method method, Object instance, Object[] args) A profiled callMethod.invoke(Object, Object...).
-
Constructor Details
-
ObjectProfiler
public ObjectProfiler()
-
-
Method Details
-
getProfiledObject
Given a class, and an interface that it implements, return a proxied version of the class that implements the interface.
The usual use of this is to profile methods from Factory objects:public PersistenceManager getPersistenceManager() { return new DefaultPersistenceManager(); }instead write:public PersistenceManager getPersistenceManager() { return ObjectProfiler.getProfiledObject(PersistenceManager.class, new DefaultPersistenceManager()); }A side effect of this is that you will no longer be able to downcast to DefaultPersistenceManager. This is probably a *good* thing.
- Parameters:
interfaceClazz- The interface to implement.o- The object to proxy- Returns:
- A proxied object, or the input object if the interfaceClazz wasn't an interface.
-
getTrimmedClassName
Given a method, get the Method name, with no package information.- Parameters:
method- the method- Returns:
- the trimmed class name
-
profile
A simple convenience wrapper for profiling a block of code, reduces repetition of captions used by the Timers#timer method.
Any exception that is thrown is wrapped as a RuntimeException so as to not adversely mess your source code up.
- Parameters:
caption- the name of the profiling stackprofilable- the thing being profiled- Returns:
- the return value of
Profilable.profile() - Throws:
RuntimeException
-
profiledInvoke
A profiled callMethod.invoke(Object, Object...). IfProfilerConfiguration.isEnabled()() } returns false, then no profiling is performed.- Parameters:
method- the Method to invokeinstance- the instance to invoke the method onargs- an Object[] containing the method arguments- Returns:
- the (optionally proxied) method return value
- Throws:
Exception- if anExceptionoccurs during the call to the passed inmethod.
-
getAllInterfaces
-