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.obm.breakdownduration.BreakdownDurationFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    Stopwatch stopwatch = Stopwatch.createStarted();
    try {//from ww w. j av a 2s  .  c  o  m
        startRecordingRequest();
        chain.doFilter(request, response);
    } finally {
        endRecordingRequest(stopwatch);
    }
}

From source file:com.planet57.gshell.internal.CommandActionFunction.java

@Override
public Object execute(final CommandSession session, final List<Object> arguments) throws Exception {
    log.debug("Executing ({}): {}", action.getName(), arguments);

    Stopwatch watch = Stopwatch.createStarted();

    try {/*from w ww.ja v a  2s . c  om*/
        // adapt api to CommandSessionImpl for simplicity
        Object result = doExecute((CommandSessionImpl) session, arguments);
        log.debug("Result: {}; {}", result, watch);
        return result;
    } catch (Throwable failure) {
        log.debug("Failure: {}; {}", Throwables2.explain(failure), watch);
        throw failure;
    }
}

From source file:eu.amidst.dynamic.learning.dynamic.DynamicLearningEngine.java

/**
 * Learns both the structure and parameters of the dynamic model.
 * @param dataStream a given {@link DataStream} of {@link DynamicDataInstance}s.
 * @return a {@link DynamicBayesianNetwork} object.
 *///from w  w  w . j a v a  2s  . c o  m
public static DynamicBayesianNetwork learnDynamicModel(DataStream<DynamicDataInstance> dataStream) {
    Stopwatch watch = Stopwatch.createStarted();
    DynamicDAG dag = dynamicStructuralLearningAlgorithm.learn(dataStream);
    System.out.println("Structural Learning : " + watch.stop());

    watch = Stopwatch.createStarted();
    DynamicBayesianNetwork network = dynamicParameterLearningAlgorithm.learn(dag, dataStream);
    System.out.println("Parameter Learning: " + watch.stop());

    return network;
}

From source file:com.vmware.photon.controller.rootscheduler.service.SchedulerService.java

@Override
public PlaceResponse place(PlaceRequest request) throws TException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    PlaceResponse placeResponse = flatSchedulerService.place(request);
    stopwatch.stop();// ww  w  . j  ava  2s .com
    logger.info("elapsed-time place {} milliseconds", stopwatch.elapsed(TimeUnit.MILLISECONDS));

    return placeResponse;
}

From source file:org.grouplens.lenskit.cli.TrainModel.java

@Override
public void execute() throws IOException, RecommenderBuildException {
    LenskitConfiguration dataConfig = input.getConfiguration();
    LenskitRecommenderEngineBuilder builder = LenskitRecommenderEngine.newBuilder();
    for (LenskitConfiguration config : environment.loadConfigurations(getConfigFiles())) {
        builder.addConfiguration(config);
    }// w  w w. j a  va  2  s . c  o  m
    builder.addConfiguration(dataConfig, ModelDisposition.EXCLUDED);

    Stopwatch timer = Stopwatch.createStarted();
    LenskitRecommenderEngine engine = builder.build();
    timer.stop();
    logger.info("built model in {}", timer);
    File output = getOutputFile();
    logger.info("writing model to {}", output);
    Closer closer = Closer.create();
    try {
        OutputStream stream = closer.register(new FileOutputStream(output));
        if (LKFileUtils.isCompressed(output)) {
            stream = closer.register(new GZIPOutputStream(stream));
        }
        engine.write(stream);
    } catch (Throwable th) {
        throw closer.rethrow(th);
    } finally {
        closer.close();
    }
}

From source file:be.nbb.jackcess.JackcessStatement.java

@Nonnull
public JackcessResultSet executeQuery(@Nonnull DbBasicSelect query) throws IOException {
    Table table = database.getTable(query.getTableName());

    List<Column> selectColumns = getAllByName(table, query.getSelectColumns());
    List<Column> orderColumns = getAllByName(table, query.getOrderColumns());
    SortedSet<Column> dataColumns = mergeAndSortByInternalIndex(selectColumns, orderColumns);
    SortedMap<Column, String> filter = getFilter(table, query.getFilterItems());

    LOGGER.debug("Query : '{}'", query);

    Stopwatch sw = Stopwatch.createStarted();
    CheckedIterator<Object[], IOException> rows = new Adapter(
            CursorFacade.range(table, range).withFilter(filter), dataColumns);
    LOGGER.debug("Iterator done in {}ms", sw.stop().elapsed(TimeUnit.MILLISECONDS));

    ToIndex toIndex = new ToIndex(dataColumns);

    if (query.isDistinct()) {
        sw.start();//from w w  w. ja  v a2s .  co m
        rows = DbRawDataUtil.distinct(rows, selectColumns, toIndex, ToDataType.INSTANCE,
                new Aggregator(dataColumns.size() + 1));
        LOGGER.debug("Distinct done in {}ms", sw.stop().elapsed(TimeUnit.MILLISECONDS));
    }

    if (DbRawDataUtil.isSortRequired(query.isDistinct(), selectColumns, orderColumns)) {
        sw.start();
        rows = DbRawDataUtil.sort(rows, orderColumns, toIndex, ToDataType.INSTANCE);
        LOGGER.debug("Sort done in {}ms", sw.stop().elapsed(TimeUnit.MILLISECONDS));
    }

    return new JackcessResultSet(selectColumns, DbRawDataUtil.createIndexes(selectColumns, toIndex), rows);
}

From source file:org.graylog2.indexer.ranges.RebuildIndexRangesJob.java

@Override
public void execute() {
    info("Re-calculating index ranges.");

    String[] indices = deflector.getAllGraylogIndexNames();
    if (indices == null || indices.length == 0) {
        info("No indices, nothing to calculate.");
        return;/*from  ww  w  . j a va  2  s  . c om*/
    }
    indicesToCalculate = indices.length;

    Stopwatch sw = Stopwatch.createStarted();
    final String deflectorIndexName = deflector.getName();
    for (String index : indices) {
        if (deflectorIndexName.equals(index)) {
            continue;
        }
        if (cancelRequested) {
            info("Stop requested. Not calculating next index range, not updating ranges.");
            sw.stop();
            return;
        }

        try {
            final IndexRange indexRange = indexRangeService.calculateRange(index);
            indexRangeService.save(indexRange);
            LOG.debug("Created ranges for index {}: {}", index, indexRange);
        } catch (Exception e) {
            LOG.info("Could not calculate range of index [" + index + "]. Skipping.", e);
        } finally {
            indicesCalculated++;
        }
    }

    info("Done calculating index ranges for " + indices.length + " indices. Took "
            + sw.stop().elapsed(TimeUnit.MILLISECONDS) + "ms.");
}

From source file:com.altoukhov.svsync.engines.Syncer.java

private static void writeFile(IReadableFileSpace source, IWriteableFileSpace target, FileSnapshot file) {

    System.out.println(// w  w  w . ja  v a2  s . c  o  m
            "Writing file " + file.getRelativePath() + ", " + Utils.readableFileSize(file.getFileSize()));

    Stopwatch stopwatch = Stopwatch.createStarted();
    boolean success = target.writeFile(source.readFile(file.getRelativePath()), file);
    stopwatch.stop();

    if (success) {
        System.out.println("Write speed was "
                + Utils.readableTransferRate(file.getFileSize(), stopwatch.elapsed(TimeUnit.MILLISECONDS))
                + "/s");
    } else {
        System.out.println("Failed to write file " + file.getRelativePath());
    }
}

From source file:fr.ymanvieu.trading.rate.HistoricalService.java

private void addHistoricalRates(HistoricalRateProvider provider) throws IOException {
    Stopwatch startWatch = Stopwatch.createStarted();

    log.info("{}: Adding historical rates", provider);

    List<Quote> quotes = provider.getHistoricalRates();

    Stopwatch saveWatch = Stopwatch.createStarted();

    addHistoricalRates(quotes);//w  w w.  ja v a  2  s .  com

    log.debug("{}: Data saved in {}", provider, saveWatch);
    log.info("{}: Historical rates added in {}", provider, startWatch);
}

From source file:com.isotrol.impe3.pms.core.impl.AbstractStateLoaderComponent.java

public final T loadOffline(CacheKey key) {
    final Stopwatch w = Stopwatch.createStarted();
    T value = cache.getUnchecked(key);/*w w w.j a  v a  2s .  c  om*/
    offline.add(w.elapsed(TimeUnit.MILLISECONDS));
    return value;
}