public class ObjectProfiler extends Object
| Constructor and Description |
|---|
ObjectProfiler() |
| Modifier and Type | Method and Description |
|---|---|
protected static Set |
getAllInterfaces(Class clazz) |
static Object |
getProfiledObject(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 String |
getTrimmedClassName(Method method)
Given a method, get the Method name, with no package information.
|
static Object |
profile(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 Object |
profiledInvoke(Method method,
Object instance,
Object[] args)
A profiled call
Method.invoke(Object, Object...). |
public static Object getProfiledObject(Class interfaceClazz, Object o)
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.
interfaceClazz - The interface to implement.o - The object to proxypublic static String getTrimmedClassName(Method method)
method - the methodpublic static Object profile(String caption, Profilable profilable) throws RuntimeException
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.
caption - the name of the profiling stackprofilable - the thing being profiledProfilable.profile()RuntimeExceptionpublic static Object profiledInvoke(Method method, Object instance, Object[] args) throws Exception
Method.invoke(Object, Object...). If ProfilerConfiguration.isEnabled() () }
returns false, then no profiling is performed.method - the Method to invokeinstance - the instance to invoke the method onargs - an Object[] containing the method argumentsException - if an Exception occurs during the call to the passed in method.Copyright © 2019 Atlassian. All rights reserved.