/** * Executes callable code (e.g. a Java 8 Lambda) and observes a duration of how long it took to run. * * @param timeable Code that is being timed * @return Result returned by callable. */ public <E> E setToTime(Callable<E> timeable){ Timer timer = startTimer(); try { return timeable.call(); } catch (Exception e) { throw new RuntimeException(e); } finally { timer.setDuration(); } }
/** * Executes runnable code (e.g. a Java 8 Lambda) and observes a duration of how long it took to run. * * @param timeable Code that is being timed * @return Measured duration in seconds for timeable to complete. */ public double setToTime(Runnable timeable){ Timer timer = startTimer(); double elapsed; try { timeable.run(); } finally { elapsed = timer.setDuration(); } return elapsed; }
/** * Executes callable code (e.g. a Java 8 Lambda) and observes a duration of how long it took to run. * * @param timeable Code that is being timed * @return Result returned by callable. */ public <E> E setToTime(Callable<E> timeable){ Timer timer = startTimer(); try { return timeable.call(); } catch (Exception e) { throw new RuntimeException(e); } finally { timer.setDuration(); } }
/** * Executes runnable code (e.g. a Java 8 Lambda) and observes a duration of how long it took to run. * * @param timeable Code that is being timed * @return Measured duration in seconds for timeable to complete. */ public double setToTime(Runnable timeable){ Timer timer = startTimer(); double elapsed; try { timeable.run(); } finally { elapsed = timer.setDuration(); } return elapsed; }
/** * Start a timer to track a duration, for the gauge with no labels. * <p> * This is primarily useful for tracking the durations of major steps of batch jobs, * which are then pushed to a PushGateway. * For tracking other durations/latencies you should usually use a {@link Summary}. * <p> * Call {@link Timer#setDuration} at the end of what you want to measure the duration of. */ public Timer startTimer() { return noLabelsChild.startTimer(); }
/** * Start a timer to track a duration, for the gauge with no labels. * <p> * This is primarily useful for tracking the durations of major steps of batch jobs, * which are then pushed to a PushGateway. * For tracking other durations/latencies you should usually use a {@link Summary}. * <p> * Call {@link Timer#setDuration} at the end of what you want to measure the duration of. */ public Timer startTimer() { return noLabelsChild.startTimer(); }