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

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

Introduction

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

Prototype

@CheckReturnValue
public static Stopwatch createStarted() 

Source Link

Document

Creates (and starts) a new stopwatch using System#nanoTime as its time source.

Usage

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);//from  w  ww . j  a  v a  2s  .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();
    }
}

From source file:appeng.services.export.ExportProcess.java

/**
 * Will check and export if various config settings will lead to exporting the CSV file.
 *//*from  w  w  w . j  a v  a  2  s  .  co  m*/
@Override
public void run() {
    // no priority to this thread
    Thread.yield();

    // logic when to cancel the export process
    if (this.config.isForceRefreshEnabled()) {
        AELog.info(FORCE_REFRESH_MESSAGE);
    } else {
        if (this.config.isCacheEnabled()) {
            AELog.info(CACHE_ENABLED_MESSAGE);

            final Loader loader = Loader.instance();
            final List<ModContainer> mods = loader.getActiveModList();

            if (this.modChecker.isEqual(mods) == CheckType.EQUAL) {
                AELog.info(EQUAL_CONTENT_MESSAGE);

                return;
            } else {
                AELog.info(UNEQUAL_CONTENT_MESSAGE);
            }
        } else {
            AELog.info(CACHE_DISABLED_MESSAGE);
        }
    }

    AELog.info(EXPORT_START_MESSAGE);
    final Stopwatch watch = Stopwatch.createStarted();

    final FMLControlledNamespacedRegistry<Item> itemRegistry = GameData.getItemRegistry();

    final ExportMode mode = this.config.isAdditionalInformationEnabled() ? ExportMode.VERBOSE
            : ExportMode.MINIMAL;
    final Exporter exporter = new MinecraftItemCSVExporter(this.exportDirectory, itemRegistry, mode);

    exporter.export();

    AELog.info(EXPORT_END_MESSAGE, watch.elapsed(TimeUnit.MILLISECONDS));
}

From source file:com.squareup.wire.sample.CodegenSample.java

private Schema retainRoots(Schema schema) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    int oldSize = countTypes(schema);

    Schema prunedSchema = schema.prune(identifierSet);
    int newSize = countTypes(prunedSchema);

    log.info("Pruned schema from %s types to %s types in %s", oldSize, newSize, stopwatch);

    return prunedSchema;
}

From source file:org.apache.james.queue.api.DelayedMailQueueContract.java

@Test
default void delayShouldAtLeastBeTheOneSpecified() throws Exception {
    long delay = 1L;
    TimeUnit unit = TimeUnit.SECONDS;
    Stopwatch started = Stopwatch.createStarted();

    getMailQueue().enQueue(defaultMail().build(), delay, unit);

    getMailQueue().deQueue();/*from w w  w.  j av a  2  s .c  om*/
    assertThat(started.elapsed(TimeUnit.MILLISECONDS)).isGreaterThanOrEqualTo(unit.toMillis(delay));
}

From source file:brooklyn.entity.rebind.persister.BrooklynMementoPersisterToFile.java

@Override
public void checkpoint(BrooklynMemento newMemento, PersistenceExceptionHandler exceptionHandler) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    synchronized (mutex) {
        long timeObtainedMutex = stopwatch.elapsed(TimeUnit.MILLISECONDS);
        super.checkpoint(newMemento, exceptionHandler);
        long timeCheckpointed = stopwatch.elapsed(TimeUnit.MILLISECONDS);
        writeMemento();/*from  www . ja  v a  2s  . c o  m*/
        long timeWritten = stopwatch.elapsed(TimeUnit.MILLISECONDS);

        if (LOG.isDebugEnabled())
            LOG.debug(
                    "Checkpointed memento; total={}ms, obtainingMutex={}ms, "
                            + "checkpointing={}ms, writing={}ms",
                    new Object[] { timeWritten, timeObtainedMutex, (timeCheckpointed - timeObtainedMutex),
                            (timeWritten - timeCheckpointed) });
    }
}

From source file:org.litecoinj.crypto.MnemonicCode.java

/**
 * Convert mnemonic word list to seed./*from  w ww  . j  av a  2 s . c o m*/
 */
public static byte[] toSeed(List<String> words, String passphrase) {

    // To create binary seed from mnemonic, we use PBKDF2 function
    // with mnemonic sentence (in UTF-8) used as a password and
    // string "mnemonic" + passphrase (again in UTF-8) used as a
    // salt. Iteration count is set to 4096 and HMAC-SHA512 is
    // used as a pseudo-random function. Desired length of the
    // derived key is 512 bits (= 64 bytes).
    //
    String pass = Utils.join(words);
    String salt = "mnemonic" + passphrase;

    final Stopwatch watch = Stopwatch.createStarted();
    byte[] seed = PBKDF2SHA512.derive(pass, salt, PBKDF2_ROUNDS, 64);
    watch.stop();
    log.info("PBKDF2 took {}", watch);
    return seed;
}

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

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

    proxy.Init();//from  w  ww  .j  a  v a  2s  .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:org.bitcoinj.crypto.MnemonicCode.java

/**
 * Convert mnemonic word list to seed.//  w  ww. j a v  a  2 s  .c om
 */
public static byte[] toSeed(List<String> words, String passphrase) {

    // To create binary seed from mnemonic, we use PBKDF2 function
    // with mnemonic sentence (in UTF-8) used as a password and
    // string "mnemonic" + passphrase (again in UTF-8) used as a
    // salt. Iteration count is set to 4096 and HMAC-SHA512 is
    // used as a pseudo-random function. Desired length of the
    // derived key is 512 bits (= 64 bytes).
    //
    String pass = Utils.SPACE_JOINER.join(words);
    String salt = "mnemonic" + passphrase;

    final Stopwatch watch = Stopwatch.createStarted();
    byte[] seed = PBKDF2SHA512.derive(pass, salt, PBKDF2_ROUNDS, 64);
    watch.stop();
    log.info("PBKDF2 took {}", watch);
    return seed;
}

From source file:org.glowroot.central.RollupService.java

@Override
public void run() {
    Session.setInRollupThread(true);/*w w  w  . j  a  v a2  s .co m*/
    int counter = 0;
    int numWorkerThreads = INITIAL_WORKER_THREADS;
    ListeningExecutorService workerExecutor = newWorkerExecutor(numWorkerThreads);
    while (!closed) {
        try {
            MILLISECONDS.sleep(millisUntilNextRollup(clock.currentTimeMillis()));
            // perform larger sweep approx every 100 minutes
            long lastXMillis = counter++ % 100 == 0 ? DAYS.toMillis(7) : MINUTES.toMillis(30);
            Stopwatch stopwatch = Stopwatch.createStarted();
            List<AgentRollup> agentRollups = activeAgentDao.readRecentlyActiveAgentRollups(lastXMillis);
            runInternal(agentRollups, workerExecutor);
            long elapsedInSeconds = stopwatch.elapsed(SECONDS);
            int oldNumWorkerThreads = numWorkerThreads;
            if (elapsedInSeconds > 300) {
                if (numWorkerThreads < MAX_WORKER_THREADS) {
                    numWorkerThreads++;
                } else {
                    logger.warn(
                            "rolling up data across {} agent rollup took {} seconds (using" + " {} threads)",
                            count(agentRollups), elapsedInSeconds, numWorkerThreads);
                }
            } else if (elapsedInSeconds < 60 && numWorkerThreads > MIN_WORKER_THREADS) {
                numWorkerThreads--;
            }
            if (numWorkerThreads != oldNumWorkerThreads) {
                ExecutorService oldWorkerExecutor = workerExecutor;
                workerExecutor = newWorkerExecutor(numWorkerThreads);
                oldWorkerExecutor.shutdown();
                if (!oldWorkerExecutor.awaitTermination(10, SECONDS)) {
                    logger.error("timed out waiting for old worker rollup thread to terminate");
                }
            }
        } catch (InterruptedException e) {
            // probably shutdown requested (see close method below)
            logger.debug(e.getMessage(), e);
            continue;
        } catch (Throwable t) {
            // this probably should never happen since runInternal catches and logs exceptions
            logger.error(t.getMessage(), t);
        }
    }
    // shutdownNow() is needed here to send interrupt to worker rollup thread
    workerExecutor.shutdownNow();
    try {
        if (!workerExecutor.awaitTermination(10, SECONDS)) {
            throw new IllegalStateException("Timed out waiting for worker rollup thread to terminate");
        }
    } catch (InterruptedException e) {
        // this is unexpected (but not harmful since already closing)
        logger.error(e.getMessage(), e);
    }
}

From source file:org.eclipse.viatra.dse.genetic.debug.GeneticDebugger.java

public void debug(List<InstanceData> populationToDebug) {

    if (!debug) {
        return;/*from w  w  w .j a v a2  s  .c  om*/
    }

    stopwatch.stop();
    long elapsedTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);

    PrintWriter out = null;
    try {
        File f = new File(csvName);
        boolean isFileExists = f.exists();

        out = new PrintWriter(new BufferedWriter(new FileWriter(csvName, true)));

        if (!isFileExists) {
            printHeader(populationToDebug, out);
        }

        for (InstanceData instanceData : populationToDebug) {
            StringBuilder sb = new StringBuilder();

            sb.append(configId);
            sb.append(COMA);
            sb.append(runId);
            sb.append(COMA);
            sb.append(iteration);
            sb.append(COMA);
            sb.append(elapsedTime);
            sb.append(COMA);
            sb.append(instanceData.trajectory.size());
            sb.append(COMA);

            for (String key : orderedSoftConstraints) {
                sb.append(instanceData.violations.get(key));
                sb.append(COMA);
            }

            for (String key : orderedObjectives) {
                sb.append(instanceData.objectives.get(key));
                sb.append(COMA);
            }

            sb.append(instanceData.rank - 1);
            sb.append(COMA);
            sb.append(instanceData.survive);
            sb.append(COMA);

            appendCustomResults(sb, instanceData);

            out.println(sb.toString());
        }

    } catch (IOException e) {
        Logger.getLogger(getClass()).error("Couldn't write file " + csvName + ".", e);
    } finally {
        if (out != null) {
            out.close();
        }
    }

    iteration++;

    stopwatch = Stopwatch.createStarted();

}