List of usage examples for com.google.common.base Stopwatch elapsed
@CheckReturnValue public long elapsed(TimeUnit desiredUnit)
From source file:com.b2international.index.query.slowlog.QueryProfiler.java
public void log(Logger log) throws IOException { final Stopwatch queryWatch = this.phaseExecutionTimes.get(Phase.QUERY); final long queryExecTime = queryWatch.elapsed(TimeUnit.MILLISECONDS); if (config.getQueryWarnThreshold() <= queryExecTime) { log.warn(TEMPLATE, Phase.QUERY, query, queryWatch); } else if (config.getQueryInfoThreshold() <= queryExecTime) { log.info(TEMPLATE, Phase.QUERY, query, queryWatch); } else if (config.getQueryDebugThreshold() <= queryExecTime) { log.debug(TEMPLATE, Phase.QUERY, query, queryWatch); } else if (config.getQueryTraceThreshold() <= queryExecTime) { log.trace(TEMPLATE, Phase.QUERY, query, queryWatch); }/* w ww . java 2 s. c o m*/ final Stopwatch fetchWatch = this.phaseExecutionTimes.get(Phase.FETCH); final long fetchExecTime = fetchWatch.elapsed(TimeUnit.MILLISECONDS); if (config.getFetchWarnThreshold() <= fetchExecTime) { log.warn(TEMPLATE, Phase.FETCH, query, fetchWatch); } else if (config.getFetchInfoThreshold() <= fetchExecTime) { log.info(TEMPLATE, Phase.FETCH, query, fetchWatch); } else if (config.getFetchDebugThreshold() <= fetchExecTime) { log.debug(TEMPLATE, Phase.FETCH, query, fetchWatch); } else if (config.getFetchTraceThreshold() <= fetchExecTime) { log.trace(TEMPLATE, Phase.FETCH, query, fetchWatch); } }
From source file:org.arbeitspferde.friesian.FriesianWorkhorse.java
/** * Simluates a diurnal curve. Returns a number of milliseconds. d = * -cos(msec_since_epoch) + 1.5//from w ww . j a va 2 s .c om */ private double diurnalCurve(final Stopwatch timer) { return (-1.0 * Math .cos((timer.elapsed(TimeUnit.MILLISECONDS) / (settings.getDiurnalPeriod() * 60.0 * 60.0 * 1000.0)) * Math.PI * 2.0)) + 1.5; }
From source file:com.google.pubsub.clients.gcloud.CPSPublisherTask.java
@Override public void run() { try {//from w ww . j a v a 2 s .com List<Message> messages = new ArrayList<>(batchSize); String sendTime = String.valueOf(System.currentTimeMillis()); for (int i = 0; i < batchSize; i++) { messages.add(Message.builder(payload).addAttribute("sendTime", sendTime) .addAttribute("clientId", id.toString()) .addAttribute("sequenceNumber", Integer.toString(getAndIncrementNumberOfMessages())) .build()); } Stopwatch stopwatch = Stopwatch.createStarted(); pubSub.publish(topic, messages); stopwatch.stop(); metricsHandler.recordLatencyBatch(stopwatch.elapsed(TimeUnit.MILLISECONDS), batchSize); } catch (PubSubException e) { log.error("Publish request failed", e); } }
From source file:com.smithsmodding.smithscore.SmithsCore.java
@Mod.EventHandler public void postInit(FMLPostInitializationEvent event) { Stopwatch watch = Stopwatch.createStarted(); watch.stop();/*from w ww. j a v a 2 s . com*/ Long milliseconds = watch.elapsed(TimeUnit.MILLISECONDS); getLogger().info(CoreReferences.LogMarkers.POSTINIT, "SmithsCore Post-Init completed after: " + milliseconds + " ms."); }
From source file:com.facebook.buck.log.TimedLogger.java
private void timedLogCalled(Consumer<String> logFunction, String rawLogMessage) { int logRequestId = this.currentLogRequestId.incrementAndGet(); String logMessageWithId = String.format("%s [Log ID: %d]", rawLogMessage, logRequestId); Stopwatch stopwatch = Stopwatch.createStarted(); logFunction.accept(logMessageWithId); long logCallDurationMillis = stopwatch.elapsed(TimeUnit.MILLISECONDS); if (logCallDurationMillis > maxLogCallDurationMillis) { delegate.warn(String.format( ("Log request with ID [%d] took [%d] milliseconds, " + "which is longer than threshold of [%d] milliseconds."), logRequestId, logCallDurationMillis, maxLogCallDurationMillis)); }/*w w w .j av a2 s.c o m*/ }
From source file:com.isotrol.impe3.pms.core.impl.TimingAspect.java
@Around("@within(org.springframework.stereotype.Service)") public Object time(ProceedingJoinPoint pjp) throws Throwable { final Stopwatch w = Stopwatch.createStarted(); try {/*from www . ja va2 s .c o m*/ return pjp.proceed(); } finally { final long t = w.elapsed(TimeUnit.MILLISECONDS); final String key = pjp.getTarget().getClass().getName() + "." + pjp.getSignature().toShortString(); map.add(key, t); if (t > 500) { logger.warn(String.format("[%s] took [%d] ms", key, t)); } } }
From source file:org.arbeitspferde.friesian.WorkEngine.java
public void run() { long startMillis; init();//from ww w . j a v a 2 s . c o m while (workNotFinished()) { // TODO(mtp): This introduces non-determinism for testing; fix. final Stopwatch timer = new Stopwatch().start(); doWork(); timer.stop(); jtaWorkerWorkTime.addAndGet(timer.elapsed(TimeUnit.MILLISECONDS)); if (sleepProbability >= RandomNumber.generatePercentage(rng)) { try { Thread.sleep(workerSleepTime); jtaWorkerSleepTime.addAndGet(workerSleepTime); } catch (InterruptedException e) { log.log(Level.WARNING, "Worker is unable to sleep", e); } } } cache(); }
From source file:org.glowroot.agent.it.harness.impl.TraceCollector.java
Trace getPartialTrace(int timeout, TimeUnit unit) throws InterruptedException { Stopwatch stopwatch = Stopwatch.createStarted(); while (stopwatch.elapsed(unit) < timeout) { for (Trace trace : traces) { if (trace.getHeader().getPartial()) { return trace; }/*w w w . j ava 2s .co m*/ } MILLISECONDS.sleep(10); } if (traces.isEmpty()) { throw new IllegalStateException("No trace was collected"); } else { throw new IllegalStateException("Trace was collected but is not partial"); } }
From source file:com.facebook.buck.distributed.DistBuildSlaveTimingStatsTracker.java
public long getElapsedTimeMs(SlaveEvents event) { Stopwatch watch = Preconditions.checkNotNull(watches.get(event)); Preconditions.checkState(!watch.isRunning(), "Stopwatch for %s is still running.", event); return watch.elapsed(TimeUnit.MILLISECONDS); }
From source file:org.glowroot.agent.it.harness.impl.TraceCollector.java
public void checkAndResetLogMessages() throws InterruptedException { Stopwatch stopwatch = Stopwatch.createStarted(); while (stopwatch.elapsed(SECONDS) < 10 && !expectedMessages.isEmpty() && unexpectedMessages.isEmpty()) { MILLISECONDS.sleep(10);/* w w w . j a va2 s . c o m*/ } try { if (!unexpectedMessages.isEmpty()) { throw new AssertionError( "Unexpected messages were logged:\n\n" + Joiner.on("\n").join(unexpectedMessages)); } if (!expectedMessages.isEmpty()) { throw new AssertionError("One or more expected messages were not logged"); } } finally { expectedMessages.clear(); unexpectedMessages.clear(); } }