Timer0: Allow to suppress logging
Timer1, Timer2 and Timer3 allow to suppress logging. It's inconsistent
that Timer0 doesn't support this.
Release-Notes: skip
Change-Id: I928d5f5eeea7a7d4aeb839d76a4a6d6cd7759ffa
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/java/com/google/gerrit/metrics/Timer0.java b/java/com/google/gerrit/metrics/Timer0.java
index 2d91515..a18a6ed 100644
--- a/java/com/google/gerrit/metrics/Timer0.java
+++ b/java/com/google/gerrit/metrics/Timer0.java
@@ -49,6 +49,8 @@
}
}
+ private boolean suppressLogging;
+
protected final String name;
public Timer0(String name) {
@@ -74,14 +76,22 @@
public final void record(long value, TimeUnit unit) {
long durationNanos = unit.toNanos(value);
- LoggingContext.getInstance()
- .addPerformanceLogRecord(() -> PerformanceLogRecord.create(name, durationNanos));
- logger.atFinest().log("%s took %.2f ms", name, durationNanos / 1000000.0);
+ if (!suppressLogging) {
+ LoggingContext.getInstance()
+ .addPerformanceLogRecord(() -> PerformanceLogRecord.create(name, durationNanos));
+ logger.atFinest().log("%s took %.2f ms", name, durationNanos / 1000000.0);
+ }
doRecord(value, unit);
RequestStateContext.abortIfCancelled();
}
+ /** Suppress logging (debug log and performance log) when values are recorded. */
+ public final Timer0 suppressLogging() {
+ this.suppressLogging = true;
+ return this;
+ }
+
/**
* Record a value in the distribution.
*