Class Profile

java.lang.Object
one.xingyi.profile.Profile
All Implemented Interfaces:
IProfile, IProfileInfo, ProfileMBean

public class Profile extends Object implements IProfile, IProfileInfo, ProfileMBean
  • Constructor Details

    • Profile

      public Profile()
  • Method Details

    • profile

      public <T, E extends Exception> T profile(SupplierWithExceptionE<T,E> fn) throws E
      Description copied from interface: IProfile
      Time how longs it takes to run the supplier. The result of the supplier is returned.
      Specified by:
      profile in interface IProfile
      Throws:
      E extends Exception
    • run

      public <E extends Exception> void run(RunnableWithExceptionE<E> fn) throws E
      Description copied from interface: IProfile
      Time how longs it takes to run the runnable.
      Specified by:
      run in interface IProfile
      Throws:
      E extends Exception
    • child

      public IProfile child(String name)
      Description copied from interface: IProfile
      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!
      Specified by:
      child in interface IProfile
    • registerMBean

      public IProfile registerMBean()
      Description copied from interface: IProfile
      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
      Specified by:
      registerMBean in interface IProfile
    • withErrorHandler

      public IProfile withErrorHandler(Consumer<Exception> errorHandler)
      Specified by:
      withErrorHandler in interface IProfile
    • getCount

      public int getCount()
      Specified by:
      getCount in interface IProfileInfo
    • getTotalMs

      public long getTotalMs()
      Specified by:
      getTotalMs in interface IProfileInfo
    • getPath

      public String getPath()
      Specified by:
      getPath in interface IProfileInfo
    • getSnapshotMs

      public long getSnapshotMs()
      Specified by:
      getSnapshotMs in interface IProfileInfo
    • info

      public IProfileInfo info()
    • json

      public String json()
      Specified by:
      json in interface ProfileMBean
    • clear

      public void clear()
      Specified by:
      clear in interface ProfileMBean