Class PerformanceMonitor

java.lang.Object
io.github.zhengzhengyiyi.util.PerformanceMonitor

public class PerformanceMonitor extends Object
A performance monitoring utility for tracking operation execution times, memory usage, and error rates. Provides detailed statistics for performance analysis and optimization.
  • Constructor Details

    • PerformanceMonitor

      public PerformanceMonitor()
  • Method Details

    • start

      public static PerformanceMonitor.Timer start(String operationName)
      Starts timing an operation.
      Parameters:
      operationName - the name of the operation to monitor
      Returns:
      a Timer instance that should be closed when the operation completes
    • getStats

      public static PerformanceMonitor.OperationStats getStats(String operationName)
      Gets statistics for a specific operation.
      Parameters:
      operationName - the name of the operation
      Returns:
      the OperationStats for the specified operation, or null if not found
    • getAllStats

      Gets all collected performance statistics.
      Returns:
      a copy of all operation statistics
    • reset

      public static void reset()
      Resets all collected statistics and counters.
    • setEnabled

      public static void setEnabled(boolean isEnabled)
      Enables or disables performance monitoring.
      Parameters:
      isEnabled - true to enable monitoring, false to disable
    • isEnabled

      public static boolean isEnabled()
      Checks if performance monitoring is currently enabled.
      Returns:
      true if monitoring is enabled
    • getTotalMemoryUsed

      public static long getTotalMemoryUsed()
      Gets the total memory used by all monitored operations.
      Returns:
      total memory usage in bytes
    • getActiveOperations

      public static int getActiveOperations()
      Gets the number of currently active operations being monitored.
      Returns:
      count of active operations
    • getSummary

      public static String getSummary()
      Generates a formatted summary of all performance statistics.
      Returns:
      a string containing formatted performance summary