public class SimpleTimer extends Object
This is a helper class intended to measure latencies and encapsulate the conversion to seconds without losing precision.
Keep in mind that preferred approaches avoid using this mechanism if possible, since latency metrics broken out by
outcome should be minimized; Summary.startTimer()
and Histogram.startTimer()
are preferred.
Consider moving outcome labels to a separate metric like a counter.
Example usage:
class YourClass {
static final Summary requestLatency = Summary.build()
.name("requests_latency_seconds")
.help("Request latency in seconds.")
.labelNames("aLabel")
.register();
void processRequest(Request req) {
SimpleTimer requestTimer = new SimpleTimer();
try {
// Your code here.
} finally {
requestLatency.labels("aLabelValue").observe(requestTimer.elapsedSeconds());
}
}
}
Constructor and Description |
---|
SimpleTimer() |
Modifier and Type | Method and Description |
---|---|
double |
elapsedSeconds() |
static double |
elapsedSecondsFromNanos(long startNanos,
long endNanos) |
public SimpleTimer()
public double elapsedSeconds()
SimpleTimer
was constructed.public static double elapsedSecondsFromNanos(long startNanos, long endNanos)
Copyright © 2018. All Rights Reserved.