/** * Check if a stopwatch is currently running. * * @param timePhaseName the name of this stopwatch * * @return whether this stopwatch is started */ public static boolean isRunning(String timePhaseName) { RequestLog current = RLOG.get(); TimedPhase timePhase = current.times.get(timePhaseName); return timePhase != null && timePhase.isRunning(); }
/** * Start the phase. * * @return This phase after being started */ public TimedPhase start() { if (isRunning()) { LOG.warn("Tried to start timer that is already running: {}", name); } else { start = System.nanoTime(); } return this; }
/** * Stop the phase. * <p> * This method just stops the timer. It does not register the time with the {@link RequestLog}. To register * the timer, invoke {@link TimedPhase#registerTime()}. To do both with a single method call, see * {@link TimedPhase#close()} * * @see TimedPhase#registerTime() * @see TimedPhase#close() */ public void stop() { if (!isRunning()) { LOG.warn("Tried to stop timer that has not been started: {}", name); return; } duration += System.nanoTime() - start; start = 0; }
/** * Return the duration of the timer in nanoseconds. * * @return The duration of the timer in nanoseconds */ public long getDuration() { if (isRunning()) { LOG.warn("Timer '{}' is still running. Timings may be incorrect.", getName()); } return duration; }