com.atlassian.util.profiling.object
Class ObjectProfiler

java.lang.Object
  extended by com.atlassian.util.profiling.object.ObjectProfiler

public class ObjectProfiler
extends java.lang.Object

Author:
Scott Farquhar

Constructor Summary
ObjectProfiler()
           
 
Method Summary
static java.lang.Object getProfiledObject(java.lang.Class interfaceClazz, java.lang.Object o)
          Given a class, and an interface that it implements, return a proxied version of the class that implements the interface.
static java.lang.String getTrimmedClassName(java.lang.reflect.Method method)
          Given a method, get the Method name, with no package information.
static java.lang.Object profile(java.lang.String caption, Profilable profilable)
          A simple convience wrapper for profiling a block of code, reduces repetition of captions used by the UtilTimerStack#push and UtilTimerStack#pop methods.
static java.lang.Object profiledInvoke(java.lang.reflect.Method target, java.lang.Object value, java.lang.Object[] args)
          A profiled call {@link Method#invoke(java.lang.Object, java.lang.Object[]).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectProfiler

public ObjectProfiler()
Method Detail

getProfiledObject

public static java.lang.Object getProfiledObject(java.lang.Class interfaceClazz,
                                                 java.lang.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.

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.

profiledInvoke

public static java.lang.Object profiledInvoke(java.lang.reflect.Method target,
                                              java.lang.Object value,
                                              java.lang.Object[] args)
                                       throws java.lang.Throwable
A profiled call Method#invoke(java.lang.Object, java.lang.Object[]). If {@link UtilTimerStack#isActive() } returns false, then no profiling is performed.

Throws:
java.lang.Throwable

getTrimmedClassName

public static java.lang.String getTrimmedClassName(java.lang.reflect.Method method)
Given a method, get the Method name, with no package information.


profile

public static java.lang.Object profile(java.lang.String caption,
                                       Profilable profilable)
                                throws java.lang.RuntimeException
A simple convience wrapper for profiling a block of code, reduces repetition of captions used by the UtilTimerStack#push and UtilTimerStack#pop methods.

Any exception that is thrown is wrapped as a RuntimeException so as to not adversely mess your source code up.

Parameters:
caption -
profilable -
Returns:
Throws:
java.lang.RuntimeException


Copyright © 2008 Atlassian Software Systems Pty Ltd. All Rights Reserved.