Package net.obvj.performetrics
Class Performetrics
- java.lang.Object
-
- net.obvj.performetrics.Performetrics
-
public class Performetrics extends Object
A Facade class meant to provide a simple interface for common parameters setup and other operations.- Since:
- 2.0.0
- Author:
- oswaldo.bapvic.jr
-
-
Field Summary
Fields Modifier and Type Field Description static List<Counter.Type>ALL_TYPESA list containing all the available counter types.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MonitoredRunnablemonitorOperation(Runnable runnable)Runs the specifiedRunnable, which can also be a lambda expression, and collects metrics for all available counter types.static MonitoredRunnablemonitorOperation(Runnable runnable, Counter.Type... types)Runs the specifiedRunnable, which can also be a lambda expression, and collects metrics for the specified counter type(s) only.static voidsetDefaultConversionMode(ConversionMode conversionMode)Sets a conversion mode to be applied by supported operations if no specific mode is set.static voidsetDefaultPrintStyle(PrintStyle printStyle)Defines the defaultPrintStyleto be applied when no style is specified.static voidsetDefaultPrintStyleForDetails(PrintStyle printStyle)Defines the defaultPrintStyleto be applied by the detailed stopwatch formatter.static voidsetDefaultPrintStyleForSummary(PrintStyle printStyle)Defines the defaultPrintStyleto be applied by the summarized stopwatch formatter.static voidsetScale(int scale)Sets a maximum number of decimal places to be applied if double-precision conversion mode is set.
-
-
-
Field Detail
-
ALL_TYPES
public static final List<Counter.Type> ALL_TYPES
A list containing all the available counter types.- Since:
- 2.5.0
-
-
Method Detail
-
setDefaultConversionMode
public static void setDefaultConversionMode(ConversionMode conversionMode)
Sets a conversion mode to be applied by supported operations if no specific mode is set.- Parameters:
conversionMode- theConversionModeto set
-
setScale
public static void setScale(int scale)
Sets a maximum number of decimal places to be applied if double-precision conversion mode is set.- Parameters:
scale- a number between 0 and 16 to be set- Throws:
IllegalArgumentException- if a number outside the allowed range is received
-
setDefaultPrintStyle
public static void setDefaultPrintStyle(PrintStyle printStyle)
Defines the defaultPrintStyleto be applied when no style is specified.The object will be used by the following operations:
- Parameters:
printStyle- thePrintStyleto be set; not null- Throws:
NullPointerException- if the specifiedPrintStyleis null- Since:
- 2.4.0
-
setDefaultPrintStyleForSummary
public static void setDefaultPrintStyleForSummary(PrintStyle printStyle)
Defines the defaultPrintStyleto be applied by the summarized stopwatch formatter.The object will be used by the following operation:
- Parameters:
printStyle- thePrintStyleto be set; not null- Throws:
NullPointerException- if the specifiedPrintStyleis null- Since:
- 2.2.1
-
setDefaultPrintStyleForDetails
public static void setDefaultPrintStyleForDetails(PrintStyle printStyle)
Defines the defaultPrintStyleto be applied by the detailed stopwatch formatter.The object will be used by the following operations:
- Parameters:
printStyle- thePrintStyleto be set; not null- Throws:
NullPointerException- if the specifiedPrintStyleis null- Since:
- 2.2.1
-
monitorOperation
public static MonitoredRunnable monitorOperation(Runnable runnable)
Runs the specifiedRunnable, which can also be a lambda expression, and collects metrics for all available counter types.For example:
MonitoredRunnable runnable =Performetrics.monitorOperation(() -> myObj.exec());Duration elapsedTime = runnable.elapsedTime(Type.WALL_CLOCK_TIME);- Parameters:
runnable- theRunnableto be run and monitored- Returns:
- the resulting
MonitoredRunnable, which can be used to retrieve the collected results. - Since:
- 2.2.0
-
monitorOperation
public static MonitoredRunnable monitorOperation(Runnable runnable, Counter.Type... types)
Runs the specifiedRunnable, which can also be a lambda expression, and collects metrics for the specified counter type(s) only.For example:
MonitoredRunnable runnable = Performetrics.monitorOperation(() -> myObj.exec(), Type.CPU_TIME);Duration elapsedTime = runnable.elapsedTime(Type.CPU_TIME);Note: If no type is specified, then all of the available types will be maintained.
- Parameters:
runnable- theRunnableto be run and monitoredtypes- the counter types to be measured in the operation- Returns:
- the resulting
MonitoredRunnable, which can be used to retrieve the collected results. - Since:
- 2.2.0
-
-