Class PerformanceEvent
java.lang.Object
io.github.jspinak.brobot.logging.events.PerformanceEvent
Event representing performance metrics for Brobot operations.
Captures detailed timing and resource usage information for operations, including memory usage and timing breakdowns. This is essential for performance monitoring and optimization.
Example usage:
PerformanceEvent event = PerformanceEvent.builder()
.operation("findAndClick")
.duration(Duration.ofMillis(250))
.memoryUsed(1024 * 1024) // 1MB
.breakdown(Map.of(
"find", Duration.ofMillis(200),
"click", Duration.ofMillis(50)
))
.build();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
boolean
static PerformanceEvent
Create a PerformanceEvent for a failed operation.Detailed timing breakdown of sub-operationsGet a detailed breakdown description.Get the percentage of time spent in each sub-operation.Correlation ID for tracking related operationsCPU time used (if available)Current state when operation was performedGet a human-readable description of this performance event.Total duration of the operationgetError()
Get any error associated with this performance event.Error message if operation failedgetLevel()
Get the log level for this performance event.long
Memory usage after operation completedlong
Memory usage before operation startedlong
Get memory delta (difference between before and after).Get the memory usage for this performance event.long
Memory used by the operation in bytesdouble
Get memory usage in megabytes.Get a message describing this performance event.Additional performance metadataName/description of the operationGet the operation count for this performance event.double
Get operations per second rate.long
Peak memory usage during operationdouble
Get peak memory usage in megabytes.Thread name where operation was executedTimestamp when the operation was initiatedint
hashCode()
boolean
isMemoryIntensive
(long thresholdBytes) Check if this operation used excessive memory.boolean
isSlow
(long thresholdMs) Check if this operation was slow compared to a threshold.boolean
Whether this operation was considered successfulstatic PerformanceEvent
Create a PerformanceEvent for a successful operation.toString()
-
Method Details
-
success
Create a PerformanceEvent for a successful operation.- Parameters:
operation
- The operation nameduration
- The total duration- Returns:
- A new PerformanceEvent for a successful operation
-
failure
Create a PerformanceEvent for a failed operation.- Parameters:
operation
- The operation nameduration
- The duration before failureerrorMessage
- The error message- Returns:
- A new PerformanceEvent for a failed operation
-
getMemoryDelta
public long getMemoryDelta()Get memory delta (difference between before and after).- Returns:
- Memory delta in bytes (positive = memory increased)
-
getMemoryUsedMB
public double getMemoryUsedMB()Get memory usage in megabytes.- Returns:
- Memory used in MB
-
getPeakMemoryUsedMB
public double getPeakMemoryUsedMB()Get peak memory usage in megabytes.- Returns:
- Peak memory used in MB
-
getOperationsPerSecond
public double getOperationsPerSecond()Get operations per second rate.- Returns:
- Operations per second, or 0 if duration is zero
-
getBreakdownPercentages
Get the percentage of time spent in each sub-operation.- Returns:
- Map of operation names to percentage of total time
-
isSlow
public boolean isSlow(long thresholdMs) Check if this operation was slow compared to a threshold.- Parameters:
thresholdMs
- The threshold in milliseconds- Returns:
- true if the operation was slower than the threshold
-
isMemoryIntensive
public boolean isMemoryIntensive(long thresholdBytes) Check if this operation used excessive memory.- Parameters:
thresholdBytes
- The threshold in bytes- Returns:
- true if memory usage exceeded the threshold
-
getDescription
Get a human-readable description of this performance event.- Returns:
- A formatted description
-
getBreakdownDescription
Get a detailed breakdown description.- Returns:
- A formatted breakdown description
-
getLevel
Get the log level for this performance event. Successful operations log at INFO level, failures at ERROR level, slow operations log at WARN level.- Returns:
- The appropriate log level
-
getMessage
Get a message describing this performance event.- Returns:
- A formatted message
-
getMemoryUsage
Get the memory usage for this performance event.- Returns:
- Memory usage in bytes, or null if not measured
-
getOperationCount
Get the operation count for this performance event.- Returns:
- The number of operations performed
-
getError
Get any error associated with this performance event.- Returns:
- null since performance events only have error messages
-
builder
-
toBuilder
-
getTimestamp
Timestamp when the operation was initiated -
getOperation
Name/description of the operation -
getDuration
Total duration of the operation -
getMemoryUsed
public long getMemoryUsed()Memory used by the operation in bytes -
getBreakdown
Detailed timing breakdown of sub-operations -
getMetadata
Additional performance metadata -
getCorrelationId
Correlation ID for tracking related operations -
getCurrentState
Current state when operation was performed -
getThreadName
Thread name where operation was executed -
getCpuTime
CPU time used (if available) -
isSuccess
public boolean isSuccess()Whether this operation was considered successful -
getErrorMessage
Error message if operation failed -
getPeakMemoryUsed
public long getPeakMemoryUsed()Peak memory usage during operation -
getMemoryBefore
public long getMemoryBefore()Memory usage before operation started -
getMemoryAfter
public long getMemoryAfter()Memory usage after operation completed -
equals
-
hashCode
public int hashCode() -
toString
-