Class 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 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 - the ConversionMode to 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
      • monitorOperation

        public static MonitoredRunnable monitorOperation​(Runnable runnable)
        Runs the specified Runnable, 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 - the Runnable to 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 specified Runnable, 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 - the Runnable to be run and monitored
        types - 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