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

      • configuration

        public static Configuration configuration()
        Returns the current Configuration.
        Returns:
        the current configuration
        Since:
        2.5.3
      • setDefaultConversionMode

        @Deprecated(since="2.5.3",
                    forRemoval=true)
        public static void setDefaultConversionMode​(ConversionMode conversionMode)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use Performetrics.configuration().setConversionMode(ConversionMode) instead.
        Sets a conversion mode to be applied by supported operations if no specific mode is set.
        Parameters:
        conversionMode - the ConversionMode to set
      • setScale

        @Deprecated(since="2.5.3",
                    forRemoval=true)
        public static void setScale​(int scale)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use Performetrics.configuration().setScale(int) instead.
        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.

        Note: If the provided Runnable throws an exception during execution, the method will not be able to generate the monitored MonitoredRunnable. In this case, using the MonitoredRunnable class is recommended. Then, the exception can be handled as necessary.

        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