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.graylog2.indexer.retention.strategies.DeletionRetentionStrategy.java

@Override
public void retain(String indexName) {
    final Stopwatch sw = Stopwatch.createStarted();

    indices.delete(indexName);/*from w ww  . j av a  2 s . c o m*/

    LOG.info("Finished index retention strategy [delete] for index <{}> in {}ms.", indexName,
            sw.stop().elapsed(TimeUnit.MILLISECONDS));
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.data.KratuProcessor.java

public void processKratus(Date dateStart, Date dateEnd) throws InterruptedException {
    System.out.println("Processing Kratus for" + mccAccountId);

    // We use a Latch so the main thread knows when all the worker threads are complete.
    final CountDownLatch latch = new CountDownLatch(1);
    Stopwatch stopwatch = Stopwatch.createStarted();

    RunnableKratu runnableKratu = createRunnableKratu(storageHelper, dateStart, dateEnd);

    ExecutorService executorService = Executors.newFixedThreadPool(1);
    runnableKratu.setLatch(latch);/*from w  w  w .  j  a v a2  s.c om*/
    executorService.execute(runnableKratu);

    latch.await();
    stopwatch.stop();
}

From source file:de.metas.ui.web.window.descriptor.factory.standard.DefaultDocumentDescriptorLoader.java

public DocumentDescriptor load() {
    // Mark as executed
    if (_executed) {
        throw new IllegalStateException("Already executed");
    }//from  w ww . j a v  a2 s .c  o m
    _executed = true;

    if (AD_Window_ID <= 0) {
        throw new DocumentLayoutBuildException("No window found for AD_Window_ID=" + AD_Window_ID);
    }

    final Stopwatch stopwatch = Stopwatch.createStarted();
    final GridWindowVO gridWindowVO = GridWindowVO.builder().ctx(Env.getCtx()).windowNo(0) // TODO: get rid of WindowNo from GridWindowVO
            .adWindowId(AD_Window_ID).adMenuId(-1) // N/A
            .loadAllLanguages(true).applyRolePermissions(false).build();
    Check.assumeNotNull(gridWindowVO, "Parameter gridWindowVO is not null"); // shall never happen

    final DocumentDescriptor.Builder documentBuilder = DocumentDescriptor.builder();
    final DocumentLayoutDescriptor.Builder layoutBuilder = DocumentLayoutDescriptor.builder()
            .setWindowId(WindowId.of(gridWindowVO.getAD_Window_ID())).setStopwatch(stopwatch)
            .putDebugProperty("generator-name", toString());

    //
    // Layout: Create UI sections from main tab
    final GridTabVO mainTabVO = gridWindowVO.getTab(GridTabVO.MAIN_TabNo);
    final LayoutFactory rootLayoutFactory = LayoutFactory.ofMainTab(gridWindowVO, mainTabVO);
    {
        layoutBuilder.setCaption(rootLayoutFactory.getWindowCaption());
        layoutBuilder.setSingleRowLayout(rootLayoutFactory.layoutSingleRow());
        layoutBuilder.setGridView(rootLayoutFactory.layoutGridView());
        layoutBuilder.setSideListView(rootLayoutFactory.layoutSideListView());

        // Set special field names
        // IMPORTANT: do this after you created all layouts
        layoutBuilder.setDocumentSummaryElement(rootLayoutFactory.createSpecialElement_DocumentSummary())
                .setDocActionElement(rootLayoutFactory.createSpecialElement_DocStatusAndDocAction());
    }

    //
    // Layout: Create UI details from child tabs
    for (final GridTabVO detailTabVO : gridWindowVO.getChildTabs(mainTabVO.getTabNo())) {
        // Skip sort tabs because they are not supported
        if (detailTabVO.IsSortTab) {
            continue;
        }

        // Skip tabs which were already used/embedded in root layout
        if (rootLayoutFactory.isSkipAD_Tab_ID(detailTabVO.getAD_Tab_ID())) {
            continue;
        }

        final LayoutFactory detailLayoutFactory = LayoutFactory.ofIncludedTab(gridWindowVO, mainTabVO,
                detailTabVO);
        final DocumentLayoutDetailDescriptor.Builder layoutDetail = detailLayoutFactory.layoutDetail();
        layoutBuilder.addDetailIfValid(layoutDetail);

        final DocumentEntityDescriptor.Builder detailEntityBuilder = detailLayoutFactory.documentEntity();
        rootLayoutFactory.documentEntity().addIncludedEntity(detailEntityBuilder.build());
    }

    //
    // Build & return the final descriptor
    final DocumentDescriptor descriptor = documentBuilder.setLayout(layoutBuilder.build())
            .setEntityDescriptor(rootLayoutFactory.documentEntity().build()).build();
    logger.debug("Descriptor loaded in {}: {}", stopwatch, descriptor);
    return descriptor;
}

From source file:com.linagora.scheduling.FutureTestListener.java

State getNextState(int timeout, TimeUnit unit) throws Exception {
    Stopwatch start = Stopwatch.createStarted();
    try {/*from w w  w .j  a  v a  2s. c om*/
        State state = states.poll(timeout, unit);
        if (state == null) {
            throw new TimeoutException();
        }
        return state;
    } finally {
        System.out.println("next state in : " + start.elapsed(TimeUnit.MILLISECONDS));
    }
}

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

/**
 * Create a new watch.//from  w w  w . j a v a  2  s  .  com
 *
 * @return a {@link com.spotify.heroic.metric.QueryTrace.NamedWatch}
 */
public QueryTrace.NamedWatch watch(final QueryTrace.Identifier what, final Tracing query) {
    if (isEnabled(query)) {
        return new QueryTrace.ActiveNamedWatch(what, Stopwatch.createStarted());
    }

    return QueryTrace.PASSIVE_NAMED_WATCH;
}

From source file:org.terasology.polyworld.viewer.layers.MoistureModelFacetLayer.java

@Override
public void render(BufferedImage img, Region region) {
    MoistureModelFacet facet = region.getFacet(MoistureModelFacet.class);

    Stopwatch sw = Stopwatch.createStarted();

    Graphics2D g = img.createGraphics();
    int dx = region.getRegion().minX();
    int dy = region.getRegion().minZ();
    g.translate(-dx, -dy);/*from  ww w. ja  v  a 2s  . c  o m*/

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    for (Graph graph : facet.getKeys()) {
        MoistureModel model = facet.get(graph);
        draw(g, model, graph);
    }

    g.dispose();

    if (logger.isTraceEnabled()) {
        logger.debug("Rendered regions in {}ms.", sw.elapsed(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  w  w  .j  a va2  s .  c  om*/
                "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:org.apache.bookkeeper.proto.PacketProcessorBase.java

protected void sendResponse(final int rc, final OpStatsLogger statsLogger, Object response) {
    final Stopwatch writeStopwatch = Stopwatch.createStarted();
    channel.write(response).addListener(new ChannelFutureListener() {
        @Override// w w w .jav  a 2  s  .  co  m
        public void operationComplete(ChannelFuture channelFuture) throws Exception {

            long writeMicros = writeStopwatch.elapsed(TimeUnit.MICROSECONDS);
            if (!channelFuture.isSuccess()) {
                channelWriteOpStatsLogger.registerFailedEvent(writeMicros);
            } else {
                channelWriteOpStatsLogger.registerSuccessfulEvent(writeMicros);
            }

            long requestMicros = enqueueStopwatch.elapsed(TimeUnit.MICROSECONDS);
            if (BookieProtocol.EOK == rc) {
                statsLogger.registerSuccessfulEvent(requestMicros);
            } else {
                statsLogger.registerFailedEvent(requestMicros);
            }
        }
    });
}

From source file:nl.knaw.huygens.timbuctoo.storage.graph.tinkerpop.TinkerPopIterator.java

@Override
public StorageIterator<T> skip(int count) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    LOG.debug("Skip started");
    for (; count > 0 && delegate.hasNext(); count--) {
        delegate.next();/*from ww  w .ja va 2  s .c o  m*/
    }
    LOG.debug("Skip ended in [{}]", stopwatch.stop());
    return this;
}

From source file:org.haiku.haikudepotserver.pkg.job.AbstractPkgResourceExportArchiveJobRunner.java

@Override
public void run(JobService jobService, T specification) throws IOException {

    Preconditions.checkArgument(null != jobService);
    Preconditions.checkArgument(null != specification);

    Stopwatch stopwatch = Stopwatch.createStarted();
    final ObjectContext context = serverRuntime.newContext();
    int offset = 0;

    // this will register the outbound data against the job.
    JobDataWithByteSink jobDataWithByteSink = jobService.storeGeneratedData(specification.getGuid(), "download",
            MediaType.TAR.toString());//from www  .jav  a 2s. c o m

    try (final OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
            final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream); // tars assumed to be compressed
            final TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(gzipOutputStream)) {

        State state = new State();
        state.tarArchiveOutputStream = tarOutputStream;
        EJBQLQuery query = createEjbqlQuery(specification);
        query.setFetchLimit(getBatchSize());
        int countLastQuery;

        do {
            query.setFetchOffset(offset);
            List<Object[]> queryResults = context.performQuery(query);
            countLastQuery = queryResults.size();
            appendFromRawRows(state, queryResults);
            offset += countLastQuery;

            if (0 == offset % 100) {
                LOGGER.debug("processed {} entries", offset + 1);
            }

        } while (countLastQuery > 0);

        appendArchiveInfo(state);
    }

    LOGGER.info("did produce report for {} entries in {}ms", offset, stopwatch.elapsed(TimeUnit.MILLISECONDS));

}