Example usage for com.google.common.base Stopwatch stop

List of usage examples for com.google.common.base Stopwatch stop

Introduction

In this page you can find the example usage for com.google.common.base Stopwatch stop.

Prototype

public Stopwatch stop() 

Source Link

Document

Stops the stopwatch.

Usage

From source file:benchmarkio.consumer.kafka.BlockingKafkaMessageConsumer.java

@Override
public Histogram call() throws Exception {
    int messageCount = 0;

    try {/*from  w w w  .  j a va2  s .  co  m*/
        final ConsumerIterator<byte[], byte[]> it = stream.iterator();
        while (it.hasNext()) {
            try {
                // Start
                final Stopwatch stopwatch = Stopwatch.createStarted();

                final byte[] message = it.next().message();

                messageCount++;

                // End
                stopwatch.stop();
                histogram.recordValue(stopwatch.elapsed(Consts.TIME_UNIT_FOR_REPORTING));
            } catch (final Exception e) {
                logger.error("Error processing message", e);
            }
        }
    } catch (final ConsumerTimeoutException e) {
        // This is by purpose, hence no error logging.
        logger.info("Consumer was terminated through timeout");
    }

    logger.info("In total consumed {} messages", messageCount);

    return histogram;
}

From source file:com.facebook.buck.distributed.DistBuildClientStatsTracker.java

private synchronized void stopTimer(DistBuildClientStat stat) {
    Preconditions.checkNotNull(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:org.grouplens.lenskit.cli.Predict.java

private LenskitRecommenderEngine loadEngine() throws RecommenderBuildException, IOException {
    File modelFile = options.get("model_file");
    if (modelFile == null) {
        logger.info("creating fresh recommender");
        LenskitRecommenderEngineBuilder builder = LenskitRecommenderEngine.newBuilder();
        for (LenskitConfiguration config : environment.loadConfigurations(getConfigFiles())) {
            builder.addConfiguration(config);
        }//w w  w .  j  a  v  a2 s .  co  m
        builder.addConfiguration(input.getConfiguration());
        Stopwatch timer = Stopwatch.createStarted();
        LenskitRecommenderEngine engine = builder.build();
        timer.stop();
        logger.info("built recommender in {}", timer);
        return engine;
    } else {
        logger.info("loading recommender from {}", modelFile);
        LenskitRecommenderEngineLoader loader = LenskitRecommenderEngine.newLoader();
        for (LenskitConfiguration config : environment.loadConfigurations(getConfigFiles())) {
            loader.addConfiguration(config);
        }
        loader.addConfiguration(input.getConfiguration());
        Stopwatch timer = Stopwatch.createStarted();
        LenskitRecommenderEngine engine;
        InputStream input = new FileInputStream(modelFile);
        try {
            if (LKFileUtils.isCompressed(modelFile)) {
                input = new GZIPInputStream(input);
            }
            engine = loader.load(input);
        } finally {
            input.close();
        }
        timer.stop();
        logger.info("loaded recommender in {}", timer);
        return engine;
    }
}

From source file:org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.OnDemandShardStateCache.java

private OnDemandShardState retrieveState() throws Exception {
    stateRetrievalTime = null;/*  w  w w.j a  v  a  2 s  . com*/
    Timeout timeout = new Timeout(10, TimeUnit.SECONDS);
    Stopwatch timer = Stopwatch.createStarted();

    OnDemandShardState state = (OnDemandShardState) Await
            .result(Patterns.ask(shardActor, GetOnDemandRaftState.INSTANCE, timeout), timeout.duration());

    stateRetrievalTime = timer.stop().toString();
    return state;
}

From source file:org.factcast.store.pgsql.internal.catchup.PgCatchUpFetchPage.java

public LinkedList<Fact> fetchFacts(@NonNull AtomicLong serial) {
    Stopwatch sw = Stopwatch.createStarted();
    final LinkedList<Fact> list = new LinkedList<>(jdbc.query(PgConstants.SELECT_FACT_FROM_CATCHUP,
            createSetter(serial, pageSize), new PgFactExtractor(serial)));
    sw.stop();
    log.debug("{}  fetched next page of Facts for cid={}, limit={}, ser>{} in {}ms", req, clientId, pageSize,
            serial.get(), sw.elapsed(TimeUnit.MILLISECONDS));
    return list;/*  w  w  w .  j  a v a2s.  co m*/
}

From source file:org.factcast.store.pgsql.internal.catchup.PgCatchUpFetchPage.java

public LinkedList<Fact> fetchIdFacts(@NonNull AtomicLong serial) {
    Stopwatch sw = Stopwatch.createStarted();
    final LinkedList<Fact> list = new LinkedList<>(jdbc.query(PgConstants.SELECT_ID_FROM_CATCHUP,
            createSetter(serial, pageSize), new PgIdFactExtractor(serial)));
    sw.stop();
    log.debug("{}  fetched next page of Ids for cid={}, limit={}, ser>{} in {}ms", req, clientId, pageSize,
            serial.get(), sw.elapsed(TimeUnit.MILLISECONDS));
    return list;/*from  ww  w.j av  a 2s  .c o  m*/
}

From source file:org.obm.breakdownduration.BreakdownDurationInterceptor.java

@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    Watch watch = getClassAnnotation(methodInvocation);
    if (watch == null) {
        return methodInvocation.proceed();
    }/*from w ww.  jav  a  2  s  . com*/

    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        breakdownLogger.startRecordingNode(watch.value());
        return methodInvocation.proceed();
    } finally {
        breakdownLogger.endRecordingNode(stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
    }
}

From source file:org.locationtech.geogig.plumbing.index.BuildIndexOp.java

@Override
protected RevTree _call() {
    checkState(index != null, "index to update was not provided");
    checkState(oldCanonicalTree != null, "old canonical version of the tree was not provided");
    checkState(newCanonicalTree != null, "new canonical version of the tree was not provided");
    checkState(revFeatureTypeId != null, "FeatureType id was not provided");

    final RevTreeBuilder builder = resolveTreeBuilder();
    final PreOrderDiffWalk.Consumer builderConsumer = resolveConsumer(builder);

    boolean preserveIterationOrder = true;
    final ObjectDatabase canonicalStore = objectDatabase();
    PreOrderDiffWalk walk = new PreOrderDiffWalk(oldCanonicalTree, newCanonicalTree, canonicalStore,
            canonicalStore, preserveIterationOrder);

    final ProgressListener progress = getProgressListener();
    final Stopwatch dagTime = Stopwatch.createStarted();
    walk.walk(builderConsumer);/*from  w ww.  j a  v  a 2s .co  m*/
    dagTime.stop();

    if (progress.isCanceled()) {
        return null;
    }

    progress.setDescription(String.format("Index updated in %s. Building final tree...", dagTime));

    final Stopwatch revTreeTime = Stopwatch.createStarted();
    RevTree indexTree;
    try {
        indexTree = builder.build();
    } catch (Exception e) {
        e.printStackTrace();
        throw Throwables.propagate(Throwables.getRootCause(e));
    }
    revTreeTime.stop();
    indexDatabase().addIndexedTree(index, newCanonicalTree.getId(), indexTree.getId());
    progress.setDescription(
            String.format("QuadTree created. Size: %,d, time: %s", indexTree.size(), revTreeTime));

    progress.complete();

    return indexTree;

}

From source file:io.mandrel.worker.Barrier.java

public void passOrWait(Long consumedSize) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    pagePageRateBucket.consume();/*from w  w  w  .  j a va2s  .c  o  m*/

    if (consumedSize != null) {
        bandwidthBucket.consume(consumedSize.longValue());
    }

    long elapsed = stopwatch.stop().elapsed(TimeUnit.SECONDS);

    if (politeness.getWait() > 0 && politeness.getWait() > elapsed) {
        Uninterruptibles.sleepUninterruptibly(politeness.getWait() - elapsed, TimeUnit.SECONDS);
    }
}

From source file:org.balloon_project.overflight.service.RelationService.java

@Transactional
public void save(List<Triple> triples) {
    Stopwatch watchComplete = Stopwatch.createStarted();
    logger.info(triples.size() + " triples to persist");

    for (Triple triple : triples) {
        save(triple);/* ww w .  j  ava  2s  .c om*/
    }
    long miliseconds = watchComplete.stop().elapsed(TimeUnit.MILLISECONDS);

    if (triples.size() != 0) {
        logger.info(triples.size() + " relations persisted. (Duration: " + miliseconds + "ms => "
                + (miliseconds / triples.size()) + " ms/triple)");
    }
}