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:com.isotrol.impe3.pms.core.impl.AbstractStateLoaderComponent.java

public final T loadOnline(UUID envId) {
    final Stopwatch w = Stopwatch.createStarted();
    T value = getLoader().load(getEdition(envId));
    online.add(w.elapsed(TimeUnit.MILLISECONDS));
    return value;
}

From source file:io.wcm.caravan.pipeline.impl.JsonPathSelector.java

@Override
public ArrayNode call(JsonNode inputData) throws PathNotFoundException {
    Stopwatch watch = Stopwatch.createStarted();

    ArrayNode arrayNode = JsonPath.using(config).parse(inputData).read(jsonPath, ArrayNode.class);

    log.debug("selected " + arrayNode.size() + " matches in " + watch.elapsed(MILLISECONDS)
            + " ms by applying jsonPath " + this.jsonPath);
    return arrayNode;
}

From source file:org.apache.drill.exec.physical.impl.xsort.SingleBatchSorterTemplate.java

@Override
public void sort(SelectionVector2 vector2) {
    QuickSort qs = new QuickSort();
    Stopwatch watch = new Stopwatch();
    watch.start();/*from www .j av  a2s.  c o m*/
    if (vector2.getCount() > 0) {
        qs.sort(this, 0, vector2.getCount());
    }
    logger.debug("Took {} us to sort {} records", watch.elapsed(TimeUnit.MICROSECONDS), vector2.getCount());
}

From source file:com.twitter.distributedlog.io.LZ4CompressionCodec.java

@Override
// length parameter is ignored here because of the way the fastDecompressor works.
public byte[] decompress(byte[] data, int offset, int length, int decompressedSize,
        OpStatsLogger decompressionStat) {
    Preconditions.checkNotNull(data);// ww w  .j  ava 2s .c  om
    Preconditions.checkArgument(offset >= 0 && offset < data.length);
    Preconditions.checkArgument(length >= 0);
    Preconditions.checkArgument(decompressedSize >= 0);
    Preconditions.checkNotNull(decompressionStat);

    Stopwatch watch = Stopwatch.createStarted();
    byte[] decompressed = fastDecompressor.decompress(data, offset, decompressedSize);
    decompressionStat.registerSuccessfulEvent(watch.elapsed(TimeUnit.MICROSECONDS));
    return decompressed;
}

From source file:com.rptools.name.NameGen.java

@Autowired
public NameGen(NameFileParser nameFileParser) {
    Stopwatch timer = Stopwatch.createStarted();
    first = nameFileParser.parseFile("names.txt");
    last = nameFileParser.parseFile("lastNames.txt");
    timer.stop();/*  w  w w . j a v a 2s .  com*/
    log.info(String.format(PARSED_TIME, timer.elapsed(TimeUnit.MILLISECONDS)));
}

From source file:org.apache.brooklyn.core.test.qa.longevity.EntityCleanupLongevityTestFixture.java

protected void doTestManyTimesAndAssertNoMemoryLeak(String testName, Runnable iterationBody) {
    int iterations = numIterations();
    Stopwatch timer = Stopwatch.createStarted();
    long last = timer.elapsed(TimeUnit.MILLISECONDS);

    long memUsedNearStart = -1;

    for (int i = 0; i < iterations; i++) {
        if (i % 100 == 0 || i < 5) {
            long now = timer.elapsed(TimeUnit.MILLISECONDS);
            System.gc();//from w ww  . ja  v a2s.c  o  m
            System.gc();
            String msg = testName + " iteration " + i + " at " + Time.makeTimeStringRounded(now) + " (delta "
                    + Time.makeTimeStringRounded(now - last) + "), using "
                    + ((AbstractManagementContext) managementContext).getGarbageCollector().getUsageString();
            LOG.info(msg);
            if (i >= 100 && memUsedNearStart < 0) {
                // set this the first time we've run 100 times (let that create a baseline with classes loaded etc)
                memUsedNearStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
            }
            last = timer.elapsed(TimeUnit.MILLISECONDS);
        }
        iterationBody.run();
    }

    BrooklynStorage storage = ((ManagementContextInternal) managementContext).getStorage();
    Assert.assertTrue(storage.isMostlyEmpty(), "Not empty storage: " + storage);

    DataGrid dg = ((BrooklynStorageImpl) storage).getDataGrid();
    Set<String> keys = dg.getKeys();
    for (String key : keys) {
        ConcurrentMap<Object, Object> v = dg.getMap(key);
        if (v.isEmpty())
            continue;
        // TODO currently we remember ApplicationUsage
        if (key.contains("usage-application")) {
            Assert.assertTrue(v.size() <= iterations, "Too many usage-application entries: " + v.size());
            continue;
        }

        Assert.fail("Non-empty key in datagrid: " + key + " (" + v + ")");
    }

    ConcurrentMap<Object, TaskScheduler> schedulers = ((BasicExecutionManager) managementContext
            .getExecutionManager()).getSchedulerByTag();
    // TODO would like to assert this
    //        Assert.assertTrue( schedulers.isEmpty(), "Not empty schedulers: "+schedulers);
    // but weaker form for now
    Assert.assertTrue(schedulers.size() <= 3 * iterations,
            "Not empty schedulers: " + schedulers.size() + " after " + iterations + ", " + schedulers);

    // memory leak detection only applies to subclasses who run lots of iterations
    if (checkMemoryLeaks())
        assertNoMemoryLeak(memUsedNearStart);
}

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();//from   w w w . jav  a 2s. co  m
    logger.info("elapsed-time place {} milliseconds", stopwatch.elapsed(TimeUnit.MILLISECONDS));

    return placeResponse;
}

From source file:benchmarkio.producer.kafka.KafkaMessageProducer.java

private void produce(final String topic, final String message) {
    for (int i = 0; i < numberOfMessagesToProduce; i++) {
        try {/*from   w  w  w. jav a  2 s.c om*/
            if (log.isDebugEnabled()) {
                log.debug("Publishing message to Kafka topic {}\n{}", topic, message.toString());
            }

            final KeyedMessage<String, String> data = new KeyedMessage<>(topic, message);

            // Start
            final Stopwatch stopwatch = Stopwatch.createStarted();

            producer.send(data);

            // End
            stopwatch.stop();
            histogram.recordValue(stopwatch.elapsed(Consts.TIME_UNIT_FOR_REPORTING));

        } catch (final Exception e) {
            log.error("Error publishing message to kafka topic {}\n{}", topic, message.toString());
        }
    }

    log.info("Finished production of {} messages", numberOfMessagesToProduce);
}

From source file:io.druid.segment.LoggingProgressIndicator.java

@Override
public void progressSection(String section, String message) {
    Stopwatch sectionWatch = sections.get(section);
    if (sectionWatch == null) {
        throw new ISE("[%s]: Cannot progress tracker for [%s]. Nothing started.", progressName, section);
    }/*w  w  w  . j  av  a  2s  . c  om*/
    long time = sectionWatch.elapsed(TimeUnit.MILLISECONDS);
    log.info("[%s]: [%s] : %s. Elapsed time: [%,d] millis", progressName, section, message, time);
}

From source file:org.glowroot.agent.fat.init.FatAgentModule.java

@OnlyUsedByTests
public UiModule getUiModule() throws InterruptedException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (stopwatch.elapsed(SECONDS) < 60) {
        if (uiModule != null) {
            return uiModule;
        }/*w w  w .j ava 2 s  .  c o  m*/
        Thread.sleep(10);
    }
    throw new IllegalStateException("UI Module failed to start");
}