@Override public void update(long duration, TimeUnit unit) { super.update(duration, unit); if (this.parentTimer.isPresent()) { this.parentTimer.get().update(duration, unit); } }
/** * End the previous stage and record the time spent in that stage. */ public void endStage() { if (this.currentStage != null) { long time = System.currentTimeMillis() - this.currentStageStart; this.timings.add(new Stage(this.currentStage, time)); if (reportAsMetrics && submitter.getMetricContext().isPresent()) { String timerName = submitter.getNamespace() + "." + name + "." + this.currentStage; submitter.getMetricContext().get().timer(timerName).update(time, TimeUnit.MILLISECONDS); } } this.currentStage = null; }
@Test public void testContextAwareTimer() { ContextAwareTimer jobTotalDuration = this.context.contextAwareTimer(TOTAL_DURATION); Assert.assertEquals(this.context.getTimers().get(jobTotalDuration.getName()), jobTotalDuration.getInnerMetric()); Assert.assertEquals(jobTotalDuration.getContext(), this.context); Assert.assertEquals(jobTotalDuration.getName(), TOTAL_DURATION); jobTotalDuration.update(50, TimeUnit.SECONDS); jobTotalDuration.update(100, TimeUnit.SECONDS); jobTotalDuration.update(150, TimeUnit.SECONDS); Assert.assertEquals(jobTotalDuration.getCount(), 3l); Assert.assertEquals(jobTotalDuration.getSnapshot().getMin(), TimeUnit.SECONDS.toNanos(50l)); Assert.assertEquals(jobTotalDuration.getSnapshot().getMax(), TimeUnit.SECONDS.toNanos(150l)); Assert.assertTrue(jobTotalDuration.time().stop() >= 0l); }
@Override public void update(long duration, TimeUnit unit) { super.update(duration, unit); if (this.parentTimer.isPresent()) { this.parentTimer.get().update(duration, unit); } }
/** * End the previous stage and record the time spent in that stage. */ public void endStage() { if (this.currentStage != null) { long time = System.currentTimeMillis() - this.currentStageStart; this.timings.add(new Stage(this.currentStage, time)); if (reportAsMetrics && submitter.getMetricContext().isPresent()) { String timerName = submitter.getNamespace() + "." + name + "." + this.currentStage; submitter.getMetricContext().get().timer(timerName).update(time, TimeUnit.MILLISECONDS); } } this.currentStage = null; }