@Override public void stopAndLog() { DynamicTimer.record(config, stopwatch.getDuration()); }
private ServoTracer(String name) { config = MonitorConfig.builder(name).withTags(tags).build(); stopwatch = DynamicTimer.start(config, TimeUnit.MICROSECONDS); }
/** * Record result to the dynamic timer indicated by the provided config * with a TimeUnit of milliseconds. */ public static void record(MonitorConfig config, long duration) { INSTANCE.get(config, TimeUnit.MILLISECONDS).record(duration, TimeUnit.MILLISECONDS); }
private List<Monitor<?>> getTimers() throws Exception { return getInstance().getMonitors(); }
private ServoTracer(String name) { config = MonitorConfig.builder(name).withTags(tags).build(); stopwatch = DynamicTimer.start(config, TimeUnit.MICROSECONDS); }
private void recordRequestTiming(String name, long timeNs) { long timeMs = timeNs / 1000000; if(timeMs > -1) { DynamicTimer.record(MonitorConfig.builder(name).build(), timeMs); } } }
/** * Record a duration to the dynamic timer indicated by the provided config. * The units in which the timer is reported and the duration unit are the same. * * @deprecated Use {@link DynamicTimer#record(MonitorConfig, java.util.concurrent.TimeUnit, * long, java.util.concurrent.TimeUnit)} instead. * The new method allows you to be specific about the units used for reporting the timer and * the units in which the duration is measured. */ public static void record(MonitorConfig config, long duration, TimeUnit unit) { INSTANCE.get(config, unit).record(duration, unit); }
@Test public void testExpiration() throws Exception { clock.set(0L); DynamicTimer.start("test1", tagList); DynamicTimer.start("test2", tagList); clock.set(500L); DynamicTimer.start("test1", tagList); clock.set(1000L); Stopwatch s = DynamicTimer.start("test1", tagList); clock.set(1200L); s.stop(); Timer c1 = getByName("test1"); assert c1 != null; assertEquals(c1.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS)); Thread.sleep(200L); Timer c2 = getByName("test2"); assertNull(c2, "Timers not used in a while should expire"); }
@Override public void stopAndLog() { DynamicTimer.record(config, stopwatch.getDuration()); }
/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given config. The timer * will report the times in milliseconds to observers. * * @see #start(MonitorConfig, TimeUnit) */ public static Stopwatch start(MonitorConfig config) { return INSTANCE.get(config, TimeUnit.MILLISECONDS).start(); }
@Test public void testGetValue() throws Exception { Stopwatch s = DynamicTimer.start("test1", tagList); Timer c = getByName("test1"); s.stop(); // we don't call s.stop(), so we only have one recorded value assert c != null; assertEquals(c.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS)); c.record(13, TimeUnit.MILLISECONDS); long expected = (13 + s.getDuration(TimeUnit.MILLISECONDS)) / 2; assertEquals(c.getValue().longValue(), expected); }
private void recordRequestTiming(String name, long timeNs) { long timeMs = timeNs / 1000000; if(timeMs > -1) { DynamicTimer.record(MonitorConfig.builder(name).build(), timeMs); } } }
/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given config. * * @param config Config to identify a particular timer instance to update. * @param unit The unit to use when reporting values to observers. For example if sent to * a typical time series graphing system this would be the unit for the y-axis. * It is generally recommended to use base units for reporting, so * {@link TimeUnit#SECONDS} is the preferred value. */ public static Stopwatch start(MonitorConfig config, TimeUnit unit) { return INSTANCE.get(config, unit).start(); }
@Test public void testByStrings() throws Exception { Stopwatch s = DynamicTimer.start("byName"); Stopwatch s2 = DynamicTimer.start("byName2", "key", "value"); Thread.sleep(100L); s.stop(); s2.stop(); Timer c1 = getByName("byName"); assert c1 != null; assertEquals(c1.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS)); Timer c2 = getByName("byName2"); assert c2 != null; assertEquals(c2.getValue().longValue(), s2.getDuration(TimeUnit.MILLISECONDS)); } }
@Test public void testDynamicTimerRecordSeconds() { DynamicTimer.record(CONFIG, 42); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
/** * Record a duration to the dynamic timer indicated by the provided config/reportUnit. * * @param config Config to identify a particular timer instance to update. * @param reportUnit The unit to use when reporting values to observers. For example if sent to * a typical time series graphing system this would be the unit * for the y-axis. * It is generally recommended to use base units for reporting, so * {@link TimeUnit#SECONDS} is the preferred value. * @param duration Measured duration to record. * @param durationUnit Unit for the measured duration. This should typically be the unit used for * timing source. For example if using {@link System#nanoTime()} * the unit would be nanoseconds. */ public static void record(MonitorConfig config, TimeUnit reportUnit, long duration, TimeUnit durationUnit) { INSTANCE.get(config, reportUnit).record(duration, durationUnit); }
@SuppressWarnings("unchecked") @Test public void testHasUnitTag() throws Exception { DynamicTimer.start("test1", tagList); CompositeMonitor c = (CompositeMonitor<Long>) getByName("test1"); assert c != null; List<Monitor<?>> monitors = c.getMonitors(); for (Monitor<?> m : monitors) { Tag type = m.getConfig().getTags().getTag("unit"); assertEquals(type.getValue(), "MILLISECONDS"); } }
@Override public void stopAndLog() { DynamicTimer.record(config, stopwatch.getDuration()); }
/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given config. The timer * uses a TimeUnit of milliseconds. */ public static Stopwatch start(String name, TagList list) { final MonitorConfig config = new MonitorConfig.Builder(name).withTags(list).build(); return INSTANCE.get(config, TimeUnit.MILLISECONDS).start(); }
private ServoTracer(String name) { config = MonitorConfig.builder(name).withTags(tags).build(); stopwatch = DynamicTimer.start(config, TimeUnit.MICROSECONDS); }