List of usage examples for com.google.common.base Stopwatch stop
public Stopwatch stop()
From source file:org.factcast.store.pgsql.internal.catchup.PgCatchUpPrepare.java
@SuppressWarnings("ConstantConditions") public long prepareCatchup(AtomicLong serial) { PgQueryBuilder b = new PgQueryBuilder(req); long clientId = jdbc.queryForObject(PgConstants.NEXT_FROM_CATCHUP_SEQ, Long.class); String catchupSQL = b.catchupSQL(clientId); // noinspection ConstantConditions return jdbc.execute(catchupSQL, (PreparedStatementCallback<Long>) ps -> { log.debug("{} preparing paging for matches after {}", req, serial.get()); try {/*from w ww. ja v a 2s.c o m*/ Stopwatch sw = Stopwatch.createStarted(); b.createStatementSetter(serial).setValues(ps); int numberOfFactsToCatchup = ps.executeUpdate(); sw.stop(); if (numberOfFactsToCatchup > 0) { log.debug("{} prepared {} facts for cid={} in {}ms", req, numberOfFactsToCatchup, clientId, sw.elapsed(TimeUnit.MILLISECONDS)); return clientId; } else { log.debug("{} nothing to catch up", req); return 0L; } } catch (SQLException ex) { log.error("While trying to prepare catchup", ex); throw ex; } }); }
From source file:org.apache.jackrabbit.oak.backup.FileStoreRestore.java
public static void restore(File source, File destination) throws IOException { if (!validFileStore(source)) { throw new IOException("Folder " + source + " is not a valid FileStore directory"); }// w ww . j a v a 2 s. c o m FileStore restore = fileStoreBuilder(source).buildReadOnly(); Stopwatch watch = Stopwatch.createStarted(); FileStore store = fileStoreBuilder(destination).build(); SegmentNodeState current = store.getHead(); try { SegmentNodeState head = restore.getHead(); int gen = head.getRecordId().getSegment().getGcGeneration(); SegmentBufferWriter bufferWriter = new SegmentBufferWriter(store, store.getTracker(), store.getReader(), "r", gen); SegmentWriter writer = new SegmentWriter(store, store.getReader(), store.getBlobStore(), new WriterCacheManager.Default(), bufferWriter); SegmentGCOptions gcOptions = defaultGCOptions().setOffline(); Compactor compactor = new Compactor(store.getReader(), writer, store.getBlobStore(), Suppliers.ofInstance(false), gcOptions); compactor.setContentEqualityCheck(true); SegmentNodeState after = compactor.compact(current, head, current); store.getRevisions().setHead(current.getRecordId(), after.getRecordId()); } finally { restore.close(); store.close(); } watch.stop(); log.info("Restore finished in {}.", watch); }
From source file:benchmarkio.producer.activemq.ActiveMQMessageProducer.java
private void produce(final String topic, final TextMessage message) { for (int i = 0; i < numberOfMessagesToProduce; i++) { try {//ww w .j a v a2 s. c o m log.debug("Publishing message to ActiveMQ topic {}\n{}", topic, message); // Start final Stopwatch stopwatch = Stopwatch.createStarted(); producer.send(message); // End stopwatch.stop(); histogram.recordValue(stopwatch.elapsed(Consts.TIME_UNIT_FOR_REPORTING)); } catch (final Exception e) { log.error("Error publishing message to ActiveMQ topic {}\n{}", topic, message.toString()); } } log.info("Finished production of {} messages", numberOfMessagesToProduce); }
From source file:com.facebook.buck.distributed.ClientStatsTracker.java
public synchronized void stopTimer(DistBuildClientStat stat) { Objects.requireNonNull(stopwatchesByType.get(stat), "Cannot stop timer for stat: [" + stat + "] as it was not started."); Stopwatch stopwatch = stopwatchesByType.get(stat); stopwatch.stop(); long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS); durationsMsByType.put(stat, elapsed); }
From source file:benchmarkio.producer.rabbitmq.RabbitMQMessageProducer.java
private void produce(final String topic, final String message) { for (int i = 0; i < numberOfMessagesToProduce; i++) { try {//from w w w. ja v a 2 s .c o m if (log.isDebugEnabled()) { log.debug("Publishing message to RabbitMQ topic {}\n{}", topic, message.toString()); } // Start final Stopwatch stopwatch = Stopwatch.createStarted(); channel.basicPublish(topic, "#", null, message.getBytes()); // End stopwatch.stop(); histogram.recordValue(stopwatch.elapsed(Consts.TIME_UNIT_FOR_REPORTING)); } catch (final Exception e) { log.error("Error publishing message to RabbitMQ topic {}\n{}", topic, message.toString()); } } log.info("Finished production of {} messages", numberOfMessagesToProduce); }
From source file:fi.helsinki.moodi.service.synchronize.SynchronizationService.java
private SynchronizationSummary complete(final SynchronizationType type, final long jobId, final Stopwatch stopwatch, final List<SynchronizationItem> items) { final SynchronizationSummary summary = new SynchronizationSummary(type, items, stopwatch.stop()); synchronizationJobRunService.complete(jobId, summary.getStatus(), summary.getMessage()); return summary; }
From source file:org.rustidea.parser.RsParser.java
@NotNull private ASTNode doParse(@NotNull IElementType root) { final Stopwatch stopwatch = Stopwatch.createStarted(); PsiBuilder.Marker marker = getBuilder().mark(); getModuleParser().file();//from w w w. j ava 2s . c om marker.done(root); stopwatch.stop(); final double size = getBuilder().getCurrentOffset() / 1000.0; LOG.info(String.format("Parsed %.1f kb file in %s.", size, stopwatch)); return getBuilder().getTreeBuilt(); }
From source file:org.lenskit.cli.commands.Simulate.java
@Override public void execute(Namespace opts) throws IOException, RecommenderBuildException { Context ctx = new Context(opts); SimulateSpec spec;/* w w w .j a v a2s . c o m*/ File specFile = opts.get("spec_file"); if (specFile != null) { spec = SpecUtils.load(SimulateSpec.class, specFile.toPath()); } else { spec = new SimulateSpec(); spec.setListSize(ctx.getListSize()); spec.setRebuildPeriod(ctx.getRebuildPeriod()); spec.setInputFile(ctx.getInputFile().toPath()); File out = ctx.getOutputFile(); if (out != null) { spec.setOutputFile(out.toPath()); } out = ctx.getExtendedOutputFile(); if (out != null) { spec.setExtendedOutputFile(out.toPath()); } AlgorithmSpec algo = new AlgorithmSpec(); File cfg = ctx.getConfigFile(); algo.setName(cfg.getName()); algo.setConfigFile(cfg.toPath()); } TemporalEvaluator eval = new TemporalEvaluator(spec); Stopwatch timer = Stopwatch.createStarted(); logger.info("beginning temporal evaluator"); eval.execute(); timer.stop(); logger.info("evaluator executed in {}", timer); }
From source file:org.smartdeveloperhub.curator.connector.LoggedConnectorFuture.java
@Override public Enrichment get() throws InterruptedException, ExecutionException { final Stopwatch waiting = Stopwatch.createStarted(); LOGGER.trace("Waiting for acknowledgment..."); final Enrichment reply = this.delegate.get(); waiting.stop(); logAcknowledgeReception(waiting);/* www .ja v a2 s. c om*/ return reply; }
From source file:org.graylog2.system.jobs.SystemJobManager.java
public String submitWithDelay(final SystemJob job, final long delay, TimeUnit timeUnit) throws SystemJobConcurrencyException { // for immediate jobs, check allowed concurrency right now if (delay == 0) { checkAllowedConcurrency(job);/* w w w. j a v a2 s .c om*/ } final String jobClass = job.getClass().getCanonicalName(); job.setId(new UUID().toString()); jobs.put(job.getId(), job); executor.schedule(new Runnable() { @Override public void run() { try { if (delay > 0) { checkAllowedConcurrency(job); } job.markStarted(); final Stopwatch x = Stopwatch.createStarted(); job.execute(); // ... blocks until it finishes. x.stop(); final String msg = "SystemJob <" + job.getId() + "> [" + jobClass + "] finished in " + x.elapsed(TimeUnit.MILLISECONDS) + "ms."; LOG.info(msg); activityWriter.write(new Activity(msg, SystemJobManager.class)); } catch (SystemJobConcurrencyException ignored) { } catch (Exception e) { LOG.error("Unhandled error while running SystemJob <" + job.getId() + "> [" + jobClass + "]", e); } finally { jobs.remove(job.getId()); } } }, delay, timeUnit); LOG.info("Submitted SystemJob <{}> [{}]", job.getId(), jobClass); return job.getId(); }