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

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

Introduction

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

Prototype

@CheckReturnValue
public long elapsed(TimeUnit desiredUnit) 

Source Link

Document

Returns the current elapsed time shown on this stopwatch, expressed in the desired time unit, with any fraction rounded down.

Usage

From source file:com.spotify.missinglink.maven.CheckMojo.java

private static long asMillis(Stopwatch stopwatch) {
    return stopwatch.elapsed(TimeUnit.MILLISECONDS);
}

From source file:org.glowroot.central.util.Session.java

private static void updateSchemaWithRetry(com.datastax.driver.core.Session wrappedSession, String query)
        throws InterruptedException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (stopwatch.elapsed(SECONDS) < 60) {
        try {/*from w  w w  . j a  v a 2  s.  co  m*/
            wrappedSession.execute(query);
            return;
        } catch (NoHostAvailableException e) {
            logger.debug(e.getMessage(), e);
        }
        SECONDS.sleep(1);
    }
    // try one last time and let exception bubble up
    wrappedSession.execute(query);
}

From source file:org.apache.jackrabbit.oak.run.DataStoreCheckCommand.java

private static void retrieveBlobIds(GarbageCollectableBlobStore blobStore, File blob) throws Exception {

    System.out.println("Starting dump of blob ids");
    Stopwatch watch = createStarted();

    Iterator<String> blobIter = blobStore.getAllChunkIds(0);
    int count = writeStrings(blobIter, blob, true);

    sort(blob);//from ww w.j  a  va  2  s .co  m
    System.out.println(count + " blob ids found");
    System.out.println("Finished in " + watch.elapsed(TimeUnit.SECONDS) + " seconds");
}

From source file:com.palantir.atlasdb.keyvalue.impl.ProfilingKeyValueService.java

private static void logTimeAndTable(String method, String tableName, Stopwatch stopwatch) {
    log.trace("Call to KVS.{} on table {} took {} ms.", method, tableName,
            stopwatch.elapsed(TimeUnit.MILLISECONDS));
}

From source file:com.palantir.atlasdb.keyvalue.impl.ProfilingKeyValueService.java

private static void logTimeAndTableCount(String method, int tableCount, Stopwatch stopwatch) {
    log.trace("Call to KVS.{} for {} tables took {} ms.", method, tableCount,
            stopwatch.elapsed(TimeUnit.MILLISECONDS));
}

From source file:itemrecommendations.CFResourceCalculator.java

private static List<Map<Integer, Double>> startBM25CreationForResourcesPrediction(BookmarkReader reader,
        int sampleSize, boolean userBased, boolean resBased, boolean allResources, boolean bll,
        Features features) {/*from   ww w .j  av a2  s  .  c  om*/
    int size = reader.getBookmarks().size();
    int trainSize = size - sampleSize;

    Stopwatch timer = new Stopwatch();
    timer.start();
    CFResourceCalculator calculator = new CFResourceCalculator(reader, trainSize, false, userBased, resBased, 5,
            Similarity.COSINE, features);
    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);

    timer.reset();
    timer.start();
    List<Map<Integer, Double>> results = new ArrayList<Map<Integer, Double>>();
    for (Integer userID : reader.getUniqueUserListFromTestSet(trainSize)) {
        Map<Integer, Double> map = null;
        map = calculator.getRankedResourcesList(userID, -1, true, allResources, bll, true, false); // TODO
        results.add(map);
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);

    timeString = PerformanceMeasurement.addTimeMeasurement(timeString, true, trainingTime, testTime,
            sampleSize);
    return results;
}

From source file:org.apache.drill.exec.physical.impl.ImplCreator.java

/**
 * Create and return fragment RootExec for given FragmentRoot. RootExec has one or more RecordBatches as children
 * (which may contain child RecordBatches and so on).
 *
 * @param context/*from   w w w .  ja v a 2 s .  c  om*/
 *          FragmentContext.
 * @param root
 *          FragmentRoot.
 * @return RootExec of fragment.
 * @throws ExecutionSetupException
 */
public static RootExec getExec(FragmentContext context, FragmentRoot root) throws ExecutionSetupException {
    Preconditions.checkNotNull(root);
    Preconditions.checkNotNull(context);

    if (AssertionUtil.isAssertionsEnabled()) {
        root = IteratorValidatorInjector.rewritePlanWithIteratorValidator(context, root);
    }
    final ImplCreator creator = new ImplCreator();
    Stopwatch watch = new Stopwatch();
    watch.start();

    try {
        final RootExec rootExec = creator.getRootExec(root, context);
        // skip over this for SimpleRootExec (testing)
        if (rootExec instanceof BaseRootExec) {
            ((BaseRootExec) rootExec).setOperators(creator.getOperators());
        }

        logger.debug("Took {} ms to create RecordBatch tree", watch.elapsed(TimeUnit.MILLISECONDS));
        if (rootExec == null) {
            throw new ExecutionSetupException(
                    "The provided fragment did not have a root node that correctly created a RootExec value.");
        }

        return rootExec;
    } catch (Exception e) {
        context.fail(e);
        for (final CloseableRecordBatch crb : creator.getOperators()) {
            AutoCloseables.close(crb, logger);
        }
    }

    return null;
}

From source file:brooklyn.util.time.Time.java

public static String makeTimeStringRounded(Stopwatch timer) {
    return makeTimeStringRounded(timer.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS);
}

From source file:org.apache.bookkeeper.stream.server.service.BookieWatchService.java

private static void waitingForNumBookies(RegistrationClient client, int minNumBookies) throws Exception {
    Stopwatch stopwatch = Stopwatch.createStarted();
    Set<BookieSocketAddress> bookies = FutureUtils.result(client.getWritableBookies()).getValue();
    while (bookies.size() < minNumBookies) {
        TimeUnit.SECONDS.sleep(1);
        bookies = FutureUtils.result(client.getWritableBookies()).getValue();
        log.info(/*from w ww. jav  a  2 s .  com*/
                "Only {} bookies are live since {} seconds elapsed, "
                        + "wait for another {} bookies for another 1 second",
                bookies.size(), stopwatch.elapsed(TimeUnit.SECONDS), minNumBookies - bookies.size());
    }
}

From source file:com.spotify.heroic.metric.BackendKeySet.java

public static Collector<BackendKeySet, BackendKeySet> collect(final QueryTrace.Identifier what) {
    final Stopwatch w = Stopwatch.createStarted();

    return results -> {
        final List<BackendKey> result = new ArrayList<>();
        final List<QueryTrace> children = new ArrayList<>();

        for (final BackendKeySet r : results) {
            result.addAll(r.getKeys());/* w w w  .  ja  va  2 s .co  m*/
            r.trace.ifPresent(children::add);
        }

        final Optional<QueryTrace> trace;

        if (!children.isEmpty()) {
            trace = Optional
                    .of(new QueryTrace(what, w.elapsed(TimeUnit.NANOSECONDS), ImmutableList.copyOf(children)));
        } else {
            trace = Optional.empty();
        }

        return new BackendKeySet(result, trace);
    };
}