ImmutableMap<Service, Long> startupTimes() { List<Entry<Service, Long>> loadTimes; monitor.enter(); try { loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) { Service service = entry.getKey(); Stopwatch stopWatch = entry.getValue(); if (!stopWatch.isRunning() && !(service instanceof NoOpService)) { loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS))); } } } finally { monitor.leave(); } Collections.sort( loadTimes, Ordering.natural() .onResultOf( new Function<Entry<Service, Long>, Long>() { @Override public Long apply(Entry<Service, Long> input) { return input.getValue(); } })); return ImmutableMap.copyOf(loadTimes); }
public void testCreateStarted() { Stopwatch startedStopwatch = Stopwatch.createStarted(); assertTrue(startedStopwatch.isRunning()); }
ImmutableMap<Service, Long> startupTimes() { List<Entry<Service, Long>> loadTimes; monitor.enter(); try { loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) { Service service = entry.getKey(); Stopwatch stopWatch = entry.getValue(); if (!stopWatch.isRunning() && !(service instanceof NoOpService)) { loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS))); } } } finally { monitor.leave(); } Collections.sort( loadTimes, Ordering.natural() .onResultOf( new Function<Entry<Service, Long>, Long>() { @Override public Long apply(Entry<Service, Long> input) { return input.getValue(); } })); return ImmutableMap.copyOf(loadTimes); }
public void testStop_alreadyStopped() { stopwatch.start(); stopwatch.stop(); try { stopwatch.stop(); fail(); } catch (IllegalStateException expected) { } assertFalse(stopwatch.isRunning()); }
public void testStop() { stopwatch.start(); assertSame(stopwatch, stopwatch.stop()); assertFalse(stopwatch.isRunning()); }
public void testStart_whileRunning() { stopwatch.start(); try { stopwatch.start(); fail(); } catch (IllegalStateException expected) { } assertTrue(stopwatch.isRunning()); }
public void testStop_new() { try { stopwatch.stop(); fail(); } catch (IllegalStateException expected) { } assertFalse(stopwatch.isRunning()); }
ImmutableMap<Service, Long> startupTimes() { List<Entry<Service, Long>> loadTimes; monitor.enter(); try { loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) { Service service = entry.getKey(); Stopwatch stopWatch = entry.getValue(); if (!stopWatch.isRunning() && !(service instanceof NoOpService)) { loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS))); } } } finally { monitor.leave(); } Collections.sort( loadTimes, Ordering.natural() .onResultOf( new Function<Entry<Service, Long>, Long>() { @Override public Long apply(Entry<Service, Long> input) { return input.getValue(); } })); return ImmutableMap.copyOf(loadTimes); }
public void testInitialState() { assertFalse(stopwatch.isRunning()); assertEquals(0, stopwatch.elapsed(NANOSECONDS)); }
public void testStart() { assertSame(stopwatch, stopwatch.start()); assertTrue(stopwatch.isRunning()); }
startupTimers.put(service, stopwatch); if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
public void testCreateUnstarted() { Stopwatch unstartedStopwatch = Stopwatch.createUnstarted(); assertFalse(unstartedStopwatch.isRunning()); assertEquals(0, unstartedStopwatch.elapsed(NANOSECONDS)); }
public void testReset_new() { ticker.advance(1); stopwatch.reset(); assertFalse(stopwatch.isRunning()); ticker.advance(2); assertEquals(0, stopwatch.elapsed(NANOSECONDS)); stopwatch.start(); ticker.advance(3); assertEquals(3, stopwatch.elapsed(NANOSECONDS)); }
public void testReset_whileRunning() { ticker.advance(1); stopwatch.start(); assertEquals(0, stopwatch.elapsed(NANOSECONDS)); ticker.advance(2); assertEquals(2, stopwatch.elapsed(NANOSECONDS)); stopwatch.reset(); assertFalse(stopwatch.isRunning()); ticker.advance(3); assertEquals(0, stopwatch.elapsed(NANOSECONDS)); }
startupTimers.put(service, stopwatch); if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
case KILL_REQUESTED: LOG.info("Killed task {}", requestId); if (killtimerWatch.isRunning()) { killtimerWatch.stop(); long elapsed = killtimerWatch.elapsed(TimeUnit.MILLISECONDS);
startupTimers.put(service, stopwatch); if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
@Override public void run() { synchronized(scheduleLock) { if (scheduleDelayStopwatch.isRunning()) { scheduleLatency.registerSuccessfulEvent(scheduleDelayStopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
if (lastLedgerCloseDetected.isRunning()) { if (lastLedgerCloseDetected.elapsed(TimeUnit.MILLISECONDS) > conf.getReaderIdleWarnThresholdMillis()) {
/** * Record that an item has been completed. */ public void advance() { Preconditions.checkState(timer.isRunning(), "progress logger not running"); int n = ndone.incrementAndGet(); if (logger.isTraceEnabled()) { logger.trace("finished {} of {} items", n, total); } if (n % period == 0) { logProgress(); } else { // log every 30 seconds long micros = timer.elapsed(TimeUnit.MICROSECONDS); if (micros - prevMicros > timePeriod) { logProgress(micros); } } }