Class ObjectProfiler

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

@Internal public class ObjectProfiler extends Object
Author:
Scott Farquhar
  • Constructor Details

    • ObjectProfiler

      public ObjectProfiler()
  • Method Details

    • getProfiledObject

      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.

      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

      public static String getTrimmedClassName(Method method)
      Given a method, get the Method name, with no package information.
      Parameters:
      method - the method
      Returns:
      the trimmed class name
    • profile

      public 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.

      Parameters:
      caption - the name of the profiling stack
      profilable - the thing being profiled
      Returns:
      the return value of Profilable.profile()
      Throws:
      RuntimeException
    • profiledInvoke

      public static Object profiledInvoke(Method method, Object instance, Object[] args) throws Exception
      A profiled call Method.invoke(Object, Object...). If ProfilerConfiguration.isEnabled() () } returns false, then no profiling is performed.
      Parameters:
      method - the Method to invoke
      instance - the instance to invoke the method on
      args - an Object[] containing the method arguments
      Returns:
      the (optionally proxied) method return value
      Throws:
      Exception - if an Exception occurs during the call to the passed in method.
    • getAllInterfaces

      protected static Set getAllInterfaces(Class clazz)