ru.fix.aggregating.profiler.Profiler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aggregating-profiler Show documentation
Show all versions of aggregating-profiler Show documentation
https://github.com/ru-fix/aggregating-profiler
package ru.fix.aggregating.profiler;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
/**
* @author Kamil Asfandiyarov
*/
public interface Profiler {
/**
* @param name Name of profiling call (e.g name of method about to be profiled)
* Method name could be separated by dot '.'
*/
ProfiledCall profiledCall(String name);
ProfiledCall profiledCall(Identity identity);
/**
* Creates and starts profiled call
* shortcut of {@code profiledCall().start()}
*/
default ProfiledCall start(String name) {
return profiledCall(name).start();
}
/**
* Creates and starts profiler which measures provided block of code
*
* @see ProfiledCall#profile(java.util.function.Supplier)
*/
default R profile(String name, Supplier block) {
return profiledCall(name).profile(block);
}
/**
* Creates and starts profiler which measures provided block of code
*
* @see ProfiledCall#profile(java.util.function.Supplier)
*/
default R profileThrowable(String name, ThrowableSupplier block) throws T {
return profiledCall(name).profileThrowable(block);
}
default void profileThrowable(String name, ThrowableRunnable block) throws T {
profiledCall(name).profileThrowable(block);
}
/**
* Creates and starts profiler which measures provided block of code
*
* @see ProfiledCall#profile(java.lang.Runnable)
*/
default void profile(String name, Runnable block) {
profiledCall(name).profile(block);
}
/**
* Measure provided feature execution
*
* @param name name of profiling call
* @param asyncInvocation CompletableFuture provider
*/
default CompletableFuture profileFuture(String name, Supplier> asyncInvocation) {
return profiledCall(name).profileFuture(asyncInvocation);
}
default CompletableFuture profileFutureThrowable(
String name,
ThrowableSupplier, T> asyncInvocation) throws T {
return profiledCall(name).profileFutureThrowable(asyncInvocation);
}
/**
* Creates and calls profiled call,
* shortcut of {@code profiledCall().call()}
*/
default void call(String name) {
profiledCall(name).call();
}
/**
* Add named indicator to profiler.
*
* @param name Name of indicator
* Indicator name could be separated by dot '.'
* @param indicationProvider Indicator value provider. Must be thread-safe.
*/
void attachIndicator(String name, IndicationProvider indicationProvider);
void attachIndicator(Identity identity, IndicationProvider indicationProvider);
/**
* Remove indicator
*
* @param name Name of indicator
*/
void detachIndicator(String name);
void detachIndicator(Identity identity);
/**
* Create new instance of reporter.
* Reporter is closable resource
*/
ProfilerReporter createReporter();
}