Include timer metrics into trace
This allows us to see from a trace how long operations took that are captured by timer metrics. Example log entry on push: [2018-08-29 10:28:37,080] [ReceiveCommits-1] TRACE com.google.gerrit.metrics.Timer0.Context : http/server/rest_api/change_json/to_change_info_latency took 24ms [CONTEXT forced=true RECEIVE_ID="foo-1535531316769-7edf2a7b" TRACE_ID="1535531316773-7edf2a7b" ] Change-Id: Ib0024cce95693d99781aee8a2b78b777c7c4ce3b Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -16,6 +16,7 @@ package com.google.gerrit.metrics;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.registration.RegistrationHandle;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -31,6 +32,8 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public abstract class Timer0 implements RegistrationHandle {
|
||||
public static class Context extends TimerContext {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private final Timer0 timer;
|
||||
|
||||
Context(Timer0 timer) {
|
||||
@@ -39,10 +42,17 @@ public abstract class Timer0 implements RegistrationHandle {
|
||||
|
||||
@Override
|
||||
public void record(long elapsed) {
|
||||
logger.atFinest().log("%s took %dms", timer.name, TimeUnit.NANOSECONDS.toMillis(elapsed));
|
||||
timer.record(elapsed, NANOSECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
protected final String name;
|
||||
|
||||
public Timer0(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a timer for the current block, value will be recorded when closed.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user