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:io.flutter.run.daemon.FlutterAppListener.java

private void reportElapsed(@NotNull Stopwatch watch, String verb, String analyticsName) {
    final long elapsed = watch.elapsed(TimeUnit.MILLISECONDS);
    FlutterInitializer.getAnalytics().sendTiming("run", analyticsName, elapsed);

    final ConsoleView console = app.getConsole();
    if (console == null)
        return;// w  ww.j a va  2 s. c  om
    console.print("\n" + verb + " in " + elapsed + " ms.\n", ConsoleViewContentType.NORMAL_OUTPUT);
}

From source file:org.apache.drill.jdbc.test.JdbcTestQueryBase.java

protected static void testQuery(String sql) throws Exception {
    boolean success = false;
    try (Connection conn = connect("jdbc:drill:zk=local")) {
        for (int x = 0; x < 1; x++) {
            Stopwatch watch = new Stopwatch().start();
            Statement s = conn.createStatement();
            ResultSet r = s.executeQuery(sql);
            System.out.println(String.format("QueryId: %s", r.unwrap(DrillResultSet.class).getQueryId()));
            boolean first = true;
            while (r.next()) {
                ResultSetMetaData md = r.getMetaData();
                if (first == true) {
                    for (int i = 1; i <= md.getColumnCount(); i++) {
                        System.out.print(md.getColumnName(i));
                        System.out.print('\t');
                    }//from  w  w  w  .j  av  a  2s. c  o  m
                    System.out.println();
                    first = false;
                }

                for (int i = 1; i <= md.getColumnCount(); i++) {
                    System.out.print(r.getObject(i));
                    System.out.print('\t');
                }
                System.out.println();
            }

            System.out.println(
                    String.format("Query completed in %d millis.", watch.elapsed(TimeUnit.MILLISECONDS)));
        }

        System.out.println("\n\n\n");
        success = true;
    } finally {
        if (!success) {
            Thread.sleep(2000);
        }
    }
}

From source file:com.facebook.buck.distributed.build_client.BuildSlaveLogsMaterializer.java

/** Fetches and materializes all logs directories. */
public void fetchAndMaterializeAllLogs(StampedeId stampedeId, List<BuildSlaveRunId> toMaterialize,
        long maxTimeoutForLogsToBeAvailableMillis) throws TimeoutException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (stopwatch.elapsed(TimeUnit.MILLISECONDS) <= maxTimeoutForLogsToBeAvailableMillis) {
        toMaterialize = fetchAndMaterializeAvailableLogs(stampedeId, toMaterialize);
        if (toMaterialize.isEmpty()) {
            return;
        }//  w  w w .  java  2  s .  com

        // Back off not to hammer the servers.
        try {
            Thread.sleep(POLLING_CADENCE_MILLIS);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    throw new TimeoutException(String.format(
            "Failed to fetch the logs for BuildSlaveRunIds=[%s] and StampedeId=[%s] " + "within [%d millis].",
            Joiner.on(", ").join(toMaterialize.stream().map(x -> x.getId()).collect(Collectors.toList())),
            stampedeId.getId(), maxTimeoutForLogsToBeAvailableMillis));
}

From source file:com.smithsmodding.smithscore.SmithsCore.java

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
    Stopwatch watch = Stopwatch.createStarted();

    proxy.Init();//from   ww w .ja va 2 s .c o m

    watch.stop();

    Long milliseconds = watch.elapsed(TimeUnit.MILLISECONDS);
    getLogger().info(CoreReferences.LogMarkers.INIT,
            "SmithsCore Init completed after: " + milliseconds + " ms.");
}

From source file:com.spotify.heroic.statistics.semantic.SemanticHeroicTimerGauge.java

@Override
public Context time() {
    final Stopwatch stopwatch = Stopwatch.createStarted();
    return new Context() {
        @Override//  w  ww. j a v  a2  s.co m
        public long stop() {
            final long elapsed = stopwatch.elapsed(TimeUnit.NANOSECONDS);
            value.set(elapsed);
            return elapsed;
        }

        @Override
        public void finished() throws Exception {
            stop();
        }
    };
}

From source file:com.facebook.buck.distributed.build_slave.BuildSlaveTimingStatsTracker.java

public synchronized long getElapsedTimeMs(SlaveEvents event) {
    Stopwatch watch = Objects.requireNonNull(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

Trace getCompletedTrace(@Nullable String transactionType, @Nullable String transactionName, int timeout,
        TimeUnit unit) throws InterruptedException {
    if (transactionName != null) {
        checkNotNull(transactionType);/*from  ww  w  . java 2 s  .  c  om*/
    }
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (stopwatch.elapsed(unit) < timeout) {
        for (Trace trace : traces) {
            if (!trace.getHeader().getPartial()
                    && (transactionType == null
                            || trace.getHeader().getTransactionType().equals(transactionType))
                    && (transactionName == null
                            || trace.getHeader().getTransactionName().equals(transactionName))) {
                return trace;
            }
        }
        MILLISECONDS.sleep(10);
    }
    if (transactionName != null) {
        throw new IllegalStateException("No trace was collected for transaction type \"" + transactionType
                + "\" and transaction name \"" + transactionName + "\"");
    } else if (transactionType != null) {
        throw new IllegalStateException("No trace was collected for transaction type: " + transactionType);
    } else {
        throw new IllegalStateException("No trace was collected");
    }
}

From source file:org.sonatype.sisu.bl.servlet.jetty.testsuite.JettyRunningITSupport.java

@Before
public void beforeTestIsRunning() {
    final Stopwatch stopwatch = startJetty(jetty());
    testIndex().recordInfo("startup time",
            stopwatch.elapsed(TimeUnit.MILLISECONDS) == 0 ? "already running" : stopwatch.toString());

    assertThat("Jetty is running before test starts", jetty().isRunning(), is(true));
}

From source file:org.sonatype.sisu.bl.testsupport.DropwizardRunningITSupport.java

@Before
public void beforeTestIsRunning() {
    final Stopwatch stopwatch = startBundle(bundle());
    testIndex().recordInfo("startup time",
            stopwatch.elapsed(TimeUnit.MILLISECONDS) == 0 ? "already running" : stopwatch.toString());

    assertThat("Dropwizard bundle was not in running state", bundle().isRunning(), is(true));
}

From source file:com.github.benmanes.caffeine.jcache.JCacheProfiler.java

private void scheduleStatusTask() {
    Stopwatch stopwatch = Stopwatch.createStarted();
    Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(() -> {
        long count = this.count.longValue();
        long rate = count / stopwatch.elapsed(TimeUnit.SECONDS);
        System.out.printf("%s - %,d [%,d / sec]%n", stopwatch, count, rate);
    }, 5, 5, TimeUnit.SECONDS);/*from www  .j av  a2 s  .  c  om*/
}