private void endInterval(ActiveIntervalInfo activeInterval) {
        boolean wasRemoved;
        synchronized (monitor) {
            pushEndOfPeriodToNow();
            wasRemoved = activeIntervals.remove(activeInterval);
            Duration latency = Duration.ofNanos(endOfPeriodNanos - activeInterval.startOfIntervalNanos());
            cumulativeLatency = cumulativeLatency.plus(latency);
            if (latency.compareTo(maxLatency) > 0) {
                maxLatency = latency;
            }
            ++numIntervalsEnded;
        }

        if (!wasRemoved) {
            // Exception made to dump stack trace.
            logger.log(Level.WARNING, "Interval of latency stats was closed twice", new IllegalStateException());
        }
    }
Returns the metrics for the current time period up to now, and starts a new period.
zkfacade/src/main/java/com/yahoo/vespa/curator/stats/LatencyStats.java