Package io.github.zhengzhengyiyi.util
Class PerformanceMonitor
java.lang.Object
io.github.zhengzhengyiyi.util.PerformanceMonitor
A performance monitoring utility for tracking operation execution times, memory usage, and error rates.
Provides detailed statistics for performance analysis and optimization.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStatistics container for tracking performance metrics of individual operations.static classAutoCloseable timer that automatically records performance metrics when closed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intGets the number of currently active operations being monitored.Gets all collected performance statistics.Gets statistics for a specific operation.static StringGenerates a formatted summary of all performance statistics.static longGets the total memory used by all monitored operations.static booleanChecks if performance monitoring is currently enabled.static voidreset()Resets all collected statistics and counters.static voidsetEnabled(boolean isEnabled) Enables or disables performance monitoring.static PerformanceMonitor.TimerStarts timing an operation.
-
Constructor Details
-
PerformanceMonitor
public PerformanceMonitor()
-
-
Method Details
-
start
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
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
Generates a formatted summary of all performance statistics.- Returns:
- a string containing formatted performance summary
-