Package one.xingyi.profile
Interface IProfile
- All Known Implementing Classes:
Profile
public interface IProfile
-
Method Summary
Modifier and TypeMethodDescriptionCreate a child of this profile.static StringUseful when debugging or manually you want to dump the results of the profilerdefault <T,E extends Exception>
Tprofile(String name, SupplierWithExceptionE<T, E> fn) Time how longs it takes to run the supplier.<T,E extends Exception>
Tprofile(SupplierWithExceptionE<T, E> fn) Time how longs it takes to run the supplier.voidrecord(long duration) The profiler is registered as a MBean.static IProfileStarts a profiling tree.default <E extends Exception>
voidrun(String name, RunnableWithExceptionE<E> fn) Time how longs it takes to run the runnable.<E extends Exception>
voidrun(RunnableWithExceptionE<E> fn) Time how longs it takes to run the runnable.timer()withErrorHandler(Consumer<Exception> errorHandler)
-
Method Details
-
timer
INanoTime timer() -
root
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 MBeansnanoTime- is the clock to use. Often INanoTime.realNanoTime. For tests consider INanoTime.testNanoTime()
-
child
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
Time how longs it takes to run the supplier. The result of the supplier is returned.- Throws:
E extends Exception
-
profile
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
Time how longs it takes to run the runnable.- Throws:
E extends Exception
-
run
Time how longs it takes to run the runnable. This is identically to child(name).run(runnable).- Throws:
E extends Exception
-
record
void record(long duration) -
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 -
withErrorHandler
-
jsonFor
Useful when debugging or manually you want to dump the results of the profiler
-