Package cloud.opencode.base.log.perf
package cloud.opencode.base.log.perf
Performance Logging - Timing and Slow Operation Detection
性能日志 - 计时和慢操作检测
This package provides utilities for measuring and logging operation durations, detecting slow operations, and performance analysis.
本包提供用于测量和记录操作持续时间、检测慢操作和性能分析的工具。
Key Classes | 核心类
StopWatch- High-precision timerPerfLog- Performance logging utilitySlowOperationConfig- Slow operation configuration
StopWatch Usage | StopWatch 使用
// Basic timing
StopWatch watch = StopWatch.start("database-query");
executeQuery();
watch.stop();
log.info("Query took {}ms", watch.getElapsedMillis());
// AutoCloseable with automatic logging
try (StopWatch watch = StopWatch.start("processOrder")) {
processOrder();
} // Automatically logs duration on close
// Threshold-based logging
StopWatch watch = StopWatch.start("api-call");
callExternalApi();
watch.stopAndLog(500); // Only warn if > 500ms
PerfLog Convenience Methods | PerfLog 便捷方法
// Timed execution
PerfLog.timed("operation", () -> {
performOperation();
});
// Timed with return value
Result result = PerfLog.timed("computation", () -> {
return computeResult();
});
// With threshold
PerfLog.timedWithThreshold("slowOp", 1000, () -> {
performSlowOperation();
});
Slow Operation Detection | 慢操作检测
SlowOperationConfig config = SlowOperationConfig.builder()
.thresholdMillis(500)
.logLevel(LogLevel.WARN)
.includeStackTrace(true)
.build();
long elapsed = 750;
if (config.isSlow(elapsed)) {
log.warn("Slow operation detected: {}ms", elapsed);
}
- Since:
- JDK 25, opencode-base-log V1.0.0
- Author:
- OpenCode Cloud Group
- See Also:
-
ClassesClassDescriptionPerfLog - Performance Logging Utility PerfLog - 性能日志工具Slow Operation Config - Configuration for Slow Operation Detection 慢操作配置 - 慢操作检测配置Builder for SlowOperationConfig.StopWatch - High-precision Timer for Performance Measurement 计时器 - 用于性能测量的高精度计时器