logger.error(String.format("Time taken to process [%s] events was [%s] seconds",events.size(),watch.stop().elapsedTime(TimeUnit.SECONDS))); if( transaction != null ) { transaction.close();
/** * Returns the current elapsed time shown on this stopwatch, expressed * in milliseconds, with any fraction rounded down. This is identical to * {@code elapsedTime(TimeUnit.MILLISECONDS}. */ public long elapsedMillis() { return elapsedTime(MILLISECONDS); }
public long elapsedNanos() { return stopwatch.elapsedTime(NANOSECONDS); }
private static long totalTime(Map<Artifact, Stopwatch> times) { long totalTime = 0; for (Stopwatch stopwatch : filter(times.values(), notNull())) { totalTime += stopwatch.elapsedTime(TimeUnit.NANOSECONDS); } return totalTime; }
public void timerStop(String name) { if (flag) { LOG.warn("timerStop({}) called after publish. Measurement was ignored. {}", name, Throwables.getStackTraceAsString(new Exception())); return; } Stopwatch activeStopwatch = timers.get(name); if (activeStopwatch == null) { throw new IllegalStateException( String.format("There is no %s timer in the %s monitoring context.", name, this)); } activeStopwatch.stop(); elapsedTimeMsMap.put(name, activeStopwatch.elapsedTime(TimeUnit.NANOSECONDS)); timers.remove(name); }
public void timerStop(String name) { if (flag) { LOG.warn("timerStop({}) called after publish. Measurement was ignored. {}", name, Throwables.getStackTraceAsString(new Exception())); return; } Stopwatch activeStopwatch = timers.get(name); if (activeStopwatch == null) { throw new IllegalStateException( String.format("There is no %s timer in the %s monitoring context.", name, this)); } activeStopwatch.stop(); elapsedTimeMsMap.put(name, activeStopwatch.elapsedTime(TimeUnit.NANOSECONDS)); timers.remove(name); }
public void timerStop(String name) { if (flag) { LOG.warn("timerStop({}) called after publish. Measurement was ignored. {}", name, Throwables.getStackTraceAsString(new Exception())); return; } Stopwatch activeStopwatch = timers.get(name); if (activeStopwatch == null) { throw new IllegalStateException( String.format("There is no %s timer in the %s monitoring context.", name, this)); } activeStopwatch.stop(); elapsedTimeMsMap.put(name, activeStopwatch.elapsedTime(TimeUnit.NANOSECONDS)); timers.remove(name); }
Stopwatch st = new Stopwatch(); // Do something. In your case Upload image ! double time = st.elapsedTime(); // the result in millis // Print time
Stopwatch st = new Stopwatch(); // Do smth. here double time = st.elapsedTime(); // the result in millis
@Override public void run() { Stopwatch sw = new Stopwatch(); sw.start(); LOGGER.info("Please wait while we are building your testData"); StringBuilder sb = new StringBuilder(); while(keepRunning){ sb.append("."); LOGGER.info(sb.toString()); sleep(1); } LOGGER.info("Time taken to build data in seconds is:"+sw.elapsedTime(TimeUnit.SECONDS)); sw.stop(); }
@Override public void run(DatasetContext context) throws Exception { Stopwatch stopwatch = new Stopwatch().start(); Table table = LoggingStoreTableUtil.getMetadataTable(context, datasetManager); for (DeletedEntry entry : toDeleteRows) { if (stopwatch.elapsedTime(TimeUnit.SECONDS) >= cutOffTransactionTimeout) { break; } table.delete(entry.getRowKey()); deletedEntries.add(entry); } stopwatch.stop(); LOG.info("Deleted {} metadata entries in {} ms", deletedEntries.size(), stopwatch.elapsedMillis()); } });
@Override public void run(DatasetContext context) throws Exception { Stopwatch stopwatch = new Stopwatch().start(); Table table = LoggingStoreTableUtil.getMetadataTable(context, datasetManager); for (DeletedEntry entry : toDeleteRows) { if (stopwatch.elapsedTime(TimeUnit.SECONDS) >= cutOffTransactionTimeout) { break; } table.delete(entry.getRowKey()); deletedEntries.add(entry); } stopwatch.stop(); LOG.info("Deleted {} metadata entries in {} ms", deletedEntries.size(), stopwatch.elapsedMillis()); } });
public void waitForLeader(long duration, TimeUnit unit) throws InterruptedException, TimeoutException { Stopwatch timer = new Stopwatch().start(); do { if (!leader.get()) { unit.sleep(duration / 10); } } while (!leader.get() && timer.elapsedTime(unit) < duration); if (!leader.get()) { throw new TimeoutException("Timed out waiting to become leader"); } }
@Override public int read(Collection<? super StreamEventOffset> events, int maxEvents, long timeout, TimeUnit unit, ReadFilter readFilter) throws IOException, InterruptedException { int eventsRead = 0; Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); while (eventsRead < maxEvents && !(emptySources.isEmpty() && eventSources.isEmpty())) { if (!emptySources.isEmpty()) { prepareEmptySources(readFilter); } eventsRead += read(events, readFilter); if (eventSources.isEmpty() && stopwatch.elapsedTime(unit) >= timeout) { break; } } return (eventsRead == 0 && emptySources.isEmpty() && eventSources.isEmpty()) ? -1 : eventsRead; }
public void testQueueDeletedRecentlyRetriesWhen59SleepsAndTries() { SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class), createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100); HttpCommand command = createHttpCommandForFailureCount(59); Stopwatch watch = new Stopwatch().start(); assertTrue(retry.shouldRetryRequestOnError(command, response, error)); assertEquals(command.getFailureCount(), 60); // allow for slightly inaccurate system timers assertTrue(watch.stop().elapsedTime(TimeUnit.MILLISECONDS) >= 98); }
public void testQueueDeletedRecentlyRetriesWhen60DoesntTry() { SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class), createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100); HttpCommand command = createHttpCommandForFailureCount(60); Stopwatch watch = new Stopwatch().start(); assertFalse(retry.shouldRetryRequestOnError(command, response, error)); assertEquals(command.getFailureCount(), 61); assertTrue(watch.stop().elapsedTime(TimeUnit.MILLISECONDS) < 100); }
public void waitForKey(int keyId, long duration, TimeUnit unit) throws InterruptedException, TimeoutException { if (keyManager instanceof WaitableDistributedKeyManager) { WaitableDistributedKeyManager waitKeyManager = (WaitableDistributedKeyManager) keyManager; Stopwatch timer = new Stopwatch().start(); boolean hasKey = false; do { hasKey = waitKeyManager.hasKey(keyId); if (!hasKey) { unit.sleep(duration / 10); } } while (!hasKey && timer.elapsedTime(unit) < duration); if (!hasKey) { throw new TimeoutException("Timed out waiting for key " + keyId); } } }
private void waitForEntry(SharedResourceCache<String> cache, String key, String expectedValue, long timeToWaitMillis) throws InterruptedException { String value = cache.get(key); boolean isPresent = expectedValue.equals(value); Stopwatch watch = new Stopwatch().start(); while (!isPresent && watch.elapsedTime(TimeUnit.MILLISECONDS) < timeToWaitMillis) { TimeUnit.MILLISECONDS.sleep(200); value = cache.get(key); isPresent = expectedValue.equals(value); } if (!isPresent) { throw new RuntimeException("Timed out waiting for expected value '" + expectedValue + "' in cache"); } } }
public void waitForCurrentKey(long duration, TimeUnit unit) throws InterruptedException, TimeoutException { if (keyManager instanceof WaitableDistributedKeyManager) { WaitableDistributedKeyManager waitKeyManager = (WaitableDistributedKeyManager) keyManager; Stopwatch timer = new Stopwatch().start(); boolean hasKey = false; do { hasKey = waitKeyManager.getCurrentKey() != null; if (!hasKey) { unit.sleep(duration / 10); } } while (!hasKey && timer.elapsedTime(unit) < duration); if (!hasKey) { throw new TimeoutException("Timed out waiting for current key to be set"); } } } }
protected ServiceStats trackAvailabilityOfProcessOnNode(Statement process, String processName, NodeMetadata node) { ServiceStats stats = new ServiceStats(); Stopwatch watch = new Stopwatch().start(); ExecResponse exec = client.runScriptOnNode(node.getId(), process, runAsRoot(false).wrapInInitScript(false)); stats.backgroundProcessMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS); watch.reset().start(); HostAndPort socket = null; try { socket = openSocketFinder.findOpenSocketOnNode(node, 8080, 60, TimeUnit.SECONDS); } catch (NoSuchElementException e) { throw new NoSuchElementException(format("%s%n%s%s", e.getMessage(), exec.getOutput(), exec.getError())); } stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS); getAnonymousLogger().info(format("<< %s on node(%s)[%s] %s", processName, node.getId(), socket, stats)); return stats; }