Interface IProfile

All Known Implementing Classes:
Profile

public interface IProfile
  • Method Details

    • root

      static IProfile root(String jmxName, INanoTime nanoTime)
      Starts a profiling tree. Almost always you will want to register this as an MBean. This hasn't been done automatically incase you want to do something else with it. This will almost always be a 'final static' field, and is often defined in a class made by the user called 'Profile' or 'Profiler'

      Normally this profiling tree is 'global' and the profiler not actually used. Usually a child would be made for each class that is being profiled

      Example

      static final IProfile main = IProfile.root("one.xingyi.profile", INanoTime.testNanoTime()).registerMBean();
      Parameters:
      jmxName - is often a package name. Like 'org.example'. Just has to be unique. It is used to register MBeans
      nanoTime - is the clock to use. Often INanoTime.realNanoTime. For tests consider INanoTime.testNanoTime()
    • child

      IProfile child(String name)
      Create a child of this profile. There are three main reasons for doing this:
      • In a class, with the name of the class as the 'name'. This would often be registered as an mbean (call .registerMBean)
      • For a particular method, with the name of the method as the 'name'. Unless the class is a 'god class' with lots of 'entry level' methods in it this wouldn't normally be registered as a MBean
      • Sometimes methods are huge... 100s of lines. We can profile separate parts of this, and we can give those a name. Often this is a clue you should refactor the method!
    • profile

      <T, E extends Exception> T profile(SupplierWithExceptionE<T,E> fn) throws E
      Time how longs it takes to run the supplier. The result of the supplier is returned.
      Throws:
      E extends Exception
    • profile

      default <T, E extends Exception> T profile(String name, SupplierWithExceptionE<T,E> fn) throws E
      Time how longs it takes to run the supplier. This is identically to child(name).profile(supplier). The result of the supplier is returned.
      Throws:
      E extends Exception
    • run

      <E extends Exception> void run(RunnableWithExceptionE<E> fn) throws E
      Time how longs it takes to run the runnable.
      Throws:
      E extends Exception
    • run

      default <E extends Exception> void run(String name, RunnableWithExceptionE<E> fn) throws E
      Time how longs it takes to run the runnable. This is identically to child(name).run(runnable).
      Throws:
      E extends Exception
    • registerMBean

      IProfile registerMBean()
      The profiler is registered as a MBean. If you call it twice it will throw exceptions, so usually this is done to 'static final' profile
    • jsonFor

      static String jsonFor(IProfile profile)
      Useful when debugging or manually you want to dump the results of the profiler