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:pt.ua.ri.behaviour.SearchBehaviour.java

@Override
public void action() {
    for (String query : queries) {
        Stopwatch sw = Stopwatch.createStarted();

        Iterable<Result> results = s.search(query);
        sw.stop();
        logger.info("Results for: {} ( {} )", query, sw);
        int i = 0;
        logger.info("%8s | %-30s | %10s\n", "#", "Score", "Document");
        for (Result r : results) {
            if (i >= 20) {
                break;
            }/*w  w w  . j a  v  a2 s .  co  m*/
            logger.info("%8d | %-30s | %9.5f%%\n", ++i, idx.getDocumentName(r.getDocId()),
                    r.getScore() * 100.0f);
        }
    }
}

From source file:qa.qcri.nadeef.core.utils.CSVTools.java

/**
 * Append CSV file content into a database table.
 * @param tableName target table name.//from w w  w  .j  av a2  s  .  c o  m
 * @param dbConfig DB connection config.
 * @param file CSV file.
 * @return new created table name.
 */
public static HashSet<Integer> append(DBConfig dbConfig, SQLDialectBase dialectManager, String tableName,
        File file) throws Exception {
    Preconditions.checkNotNull(dbConfig);
    Preconditions.checkNotNull(dialectManager);

    Stopwatch stopwatch = Stopwatch.createStarted();
    HashSet<Integer> result = Sets.newHashSet();
    try {
        boolean hasTableExist = DBMetaDataTool.isTableExist(dbConfig, tableName);

        // Create table
        if (!hasTableExist) {
            throw new IllegalArgumentException("Table " + tableName + " does not exist.");
        }

        // get the current max tid.
        int startTid = DBMetaDataTool.getMaxTid(dbConfig, tableName) + 1;

        // load the data
        int size = 0;

        if (dialectManager.supportBulkLoad()) {
            size = dialectManager.bulkLoad(dbConfig, tableName, file.toPath(), true);
        } else {
            size = dialectManager.fallbackLoad(dbConfig, tableName, file, true);
        }

        logger.info("Appended " + size + " bytes in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms.");
        stopwatch.stop();

        // build the tid set.
        int endTid = DBMetaDataTool.getMaxTid(dbConfig, tableName);
        for (int i = startTid; i <= endTid; i++) {
            result.add(i);
        }

    } catch (Exception ex) {
        logger.error("Cannot load file " + file.getName(), ex);
    }
    return result;
}

From source file:org.cinchapi.concourse.server.ManagedConcourseServer.java

/**
 * Install a Concourse Server in {@code directory} using {@code installer}.
 * /*from   ww w  .  j  a v  a  2  s.com*/
 * @param installer
 * @param directory
 * @return the server install directory
 */
private static String install(String installer, String directory) {
    try {
        Files.createDirectories(Paths.get(directory));
        Path binary = Paths.get(directory + File.separator + TARGET_BINARY_NAME);
        Files.deleteIfExists(binary);
        Files.copy(Paths.get(installer), binary);
        ProcessBuilder builder = new ProcessBuilder(Lists.newArrayList("sh", binary.toString()));
        builder.directory(new File(directory));
        builder.redirectErrorStream();
        Process process = builder.start();
        // The concourse-server installer prompts for an admin password in
        // order to make optional system wide In order to get around this
        // prompt, we have to "kill" the process, otherwise the server
        // install will hang.
        Stopwatch watch = Stopwatch.createStarted();
        while (watch.elapsed(TimeUnit.SECONDS) < 1) {
            continue;
        }
        watch.stop();
        process.destroy();
        TerminalFactory.get().restore();
        String application = directory + File.separator + "concourse-server"; // the install directory for the
                                                                              // concourse-server application
        process = Runtime.getRuntime().exec("ls " + application);
        List<String> output = Processes.getStdOut(process);
        if (!output.isEmpty()) {
            configure(application);
            log.info("Successfully installed server in {}", application);
            return application;
        } else {
            throw new RuntimeException(MessageFormat.format(
                    "Unsuccesful attempt to " + "install server at {0} " + "using binary from {1}", directory,
                    installer));
        }

    } catch (Exception e) {
        throw Throwables.propagate(e);
    }

}

From source file:qa.qcri.nadeef.core.util.CSVTools.java

/**
 * Append CSV file content into a database table.
 * @param tableName target table name.//from  w  w w .j  a v a2  s  .c  om
 * @param dbConfig DB connection config.
 * @param file CSV file.
 * @return new created table name.
 */
public static HashSet<Integer> append(DBConfig dbConfig, SQLDialectBase dialectManager, String tableName,
        File file) throws Exception {
    Preconditions.checkNotNull(dbConfig);
    Preconditions.checkNotNull(dialectManager);

    Tracer tracer = Tracer.getTracer(CSVTools.class);
    Stopwatch stopwatch = Stopwatch.createStarted();
    HashSet<Integer> result = Sets.newHashSet();
    try {
        boolean hasTableExist = DBMetaDataTool.isTableExist(dbConfig, tableName);

        // Create table
        if (!hasTableExist) {
            throw new IllegalArgumentException("Table " + tableName + " does not exist.");
        }

        // get the current max tid.
        int startTid = DBMetaDataTool.getMaxTid(dbConfig, tableName) + 1;

        // load the data
        int size = 0;

        if (dialectManager.supportBulkLoad()) {
            size = dialectManager.bulkLoad(dbConfig, tableName, file.toPath(), true);
        } else {
            size = dialectManager.fallbackLoad(dbConfig, tableName, file, true);
        }

        tracer.info("Appended " + size + " bytes in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms.");
        stopwatch.stop();

        // build the tid set.
        int endTid = DBMetaDataTool.getMaxTid(dbConfig, tableName);
        for (int i = startTid; i <= endTid; i++) {
            result.add(i);
        }

    } catch (Exception ex) {
        tracer.err("Cannot load file " + file.getName(), ex);
    }
    return result;
}

From source file:org.locationtech.geogig.spring.service.LegacySendObjectService.java

public SendObject sendObject(RepositoryProvider provider, String repoName, InputStream request) {
    final SendObject sendObject = new SendObject();
    final Repository repository = getRepository(provider, repoName);
    final BinaryPackedObjects unpacker = new BinaryPackedObjects(repository.objectDatabase());

    CountingInputStream countingStream = new CountingInputStream(request);

    Stopwatch sw = Stopwatch.createStarted();
    BinaryPackedObjects.IngestResults ingestResults = unpacker.ingest(countingStream);
    sw.stop();
    sendObject.setExisting(ingestResults.getExisting()).setInserted(ingestResults.getInserted());
    LOGGER.info(String.format(/*from w  w w  .j av  a  2s .  c  o m*/
            "SendObjectResource: Processed %,d objects.\nInserted: %,d.\nExisting: %,d.\nTime to process: %s.\nStream size: %,d bytes.\n",
            ingestResults.total(), ingestResults.getInserted(), ingestResults.getExisting(), sw,
            countingStream.getCount()));
    return sendObject;
}

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

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

    proxy.Init();//from w  w  w .  ja v a2 s.  co m

    watch.stop();

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

From source file:de.blizzy.documentr.access.BCryptPasswordEncoder.java

@Override
public String encodePassword(String rawPass, Object salt) {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();/*from   w w w .j av a  2 s .c o  m*/
    String encPass = encoder.encode(rawPass);
    stopwatch.stop();
    if (log.isTraceEnabled()) {
        log.trace("time taken to encode password: {} ms", stopwatch.elapsedMillis()); //$NON-NLS-1$
    }
    return encPass;
}

From source file:de.blizzy.documentr.access.BCryptPasswordEncoder.java

@Override
public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();/*from   www  .j a v  a  2  s  .c  o m*/
    boolean valid = encoder.matches(rawPass, encPass);
    stopwatch.stop();
    if (log.isTraceEnabled()) {
        log.trace("time taken to verify password: {} ms", stopwatch.elapsedMillis()); //$NON-NLS-1$
    }
    return valid;
}

From source file:com.couchbase.roadrunner.workloads.GetsCasWorkload.java

private void casWorkloadWithMeasurement(String key, long cas, SampleDocument doc) {
    Stopwatch watch = new Stopwatch().start();
    casWorkload(key, cas, doc);//from w ww  .j  a v a  2 s  .c o  m
    watch.stop();
    addMeasure("cas", watch);
}

From source file:org.openqa.selenium.internal.selenesedriver.ScriptExecutor.java

@SuppressWarnings({ "unchecked" })
private <T> T evaluateScript(String script) {
    Stopwatch stopWatch = new Stopwatch();
    stopWatch.start();/*from  ww  w  .  j a  v a2 s  .  c o m*/
    String result = selenium.getEval(script);
    stopWatch.stop();

    Response response = new JsonToBeanConverter().convert(Response.class, result);
    new ErrorHandler().throwIfResponseFailed(response, stopWatch.elapsed(MILLISECONDS));
    return (T) response.getValue();
}