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:com.github.benmanes.caffeine.profiler.ProfilerHook.java

private void scheduleStatusTask() {
    Stopwatch stopwatch = Stopwatch.createStarted();
    Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(() -> {
        long count = calls.longValue();
        long rate = count / stopwatch.elapsed(TimeUnit.SECONDS);
        System.out.printf("%s - %,d [%,d / sec]%n", stopwatch, count, rate);
    }, DISPLAY_DELAY_SEC, DISPLAY_DELAY_SEC, TimeUnit.SECONDS);
}

From source file:fi.helsinki.moodi.integration.http.RequestTimingInterceptor.java

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {
    Stopwatch stopwatch = Stopwatch.createStarted();

    ClientHttpResponse response = execution.execute(request, body);

    stopwatch.stop();/*ww w.ja v  a 2 s  .com*/

    log.info(String.format("Requesting uri %s took %s", request.getURI(), stopwatch.toString()));

    return response;
}

From source file:com.jaredjstewart.RandomStockPriceGenerator.java

@Override
public void run() {
    int putCounter = 0;
    Stopwatch stopWatch = Stopwatch.createStarted();

    while (stopWatch.elapsed(TimeUnit.SECONDS) < 2) {
        String tickerSymbol = getRandomTickerSymbol();
        putRandomStockPriceInGeode(tickerSymbol);
        putCounter++;//  ww w .j a  va2s . co  m
    }
    stopWatch.stop();
    System.out.println("==============");
    System.out.format("RandomStockPriceGenerator made %d updates in the last two seconds\n", putCounter);
}

From source file:org.opendaylight.infrautils.caches.sample.cli.SampleCacheCommand.java

@Override
@Nullable/*from   ww w .j a  v  a2s. co m*/
@SuppressWarnings("checkstyle:RegexpSinglelineJava")
public Object execute() {
    Stopwatch stopWatch = Stopwatch.createStarted();
    String hello = sampleService.sayHello(whoToGreet);
    long ms = stopWatch.elapsed(TimeUnit.MILLISECONDS);

    System.out.println(ms + "ms: " + hello);
    return null;
}

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();/*from w  w  w.  j av a 2  s.  com*/
    sendObject.setExisting(ingestResults.getExisting()).setInserted(ingestResults.getInserted());
    LOGGER.info(String.format(
            "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.google.devtools.build.android.InMemoryProfiler.java

@Override
public InMemoryProfiler startTask(String taskName) {
    Preconditions.checkArgument(!tasks.containsKey(taskName));
    tasks.put(taskName, Stopwatch.createStarted());
    return this;
}

From source file:io.cloudex.cloud.impl.google.storage.DownloadProgressListener.java

public DownloadProgressListener(Callback callback) {
    this.stopwatch = Stopwatch.createStarted();
    this.callback = callback;
}

From source file:org.apache.james.metrics.logger.DefaultTimeMetric.java

public DefaultTimeMetric(String name) {
    this.name = name;
    this.stopwatch = Stopwatch.createStarted();
}

From source file:com.persinity.common.fp.FunctionUtil.java

/**
 * @param f//from  www .  j  a  v  a2 s . c  o  m
 *         funciton to execute
 * @param arg
 *         argument to the function
 * @return Function Result, Stopwatch
 */
public static <T, E> DirectedEdge<E, Stopwatch> timeOf(final Function<T, E> f, final T arg) {
    notNull(f);

    Stopwatch stopwatch = Stopwatch.createStarted();
    E res;
    try {
        res = f.apply(arg);
    } finally {
        stopwatch.stop();
    }
    return new DirectedEdge<>(res, stopwatch);
}

From source file:es.usc.citius.composit.core.composition.optimization.BackwardMinimizationOptimizer.java

@Override
public ServiceMatchNetwork<E, T> optimize(ServiceMatchNetwork<E, T> network) {
    Stopwatch globalWatch = Stopwatch.createStarted();
    Stopwatch localWatch = Stopwatch.createUnstarted();
    Set<E> newInputs = new HashSet<E>();
    List<Set<Operation<E>>> optimized = new ArrayList<Set<Operation<E>>>(network.numberOfLevels());
    log.debug("Starting service-backward optimization...");
    localWatch.start();//from   w  ww .j  ava 2s  .  c om
    for (int i = network.numberOfLevels() - 1; i >= 0; i--) {
        Set<Operation<E>> current = network.getOperationsAtLevel(i);
        log.debug(" > Analyzing network level {} : {}", i, current);
        Set<Operation<E>> optimizedSet = new HashSet<Operation<E>>();
        Set<E> futureInputs = new HashSet<E>();
        // Find all services that produces at least one of the required inputs. If new inputs is
        // empty, then select all
        for (Operation<E> op : current) {
            log.debug("\t\tChecking operation {}", op.getID());
            if (newInputs.isEmpty()) {
                futureInputs.addAll(op.getSignature().getInputs());
                optimizedSet.add(op);
                log.debug("\t\t+ {} selected as a mandatory operation", op.getID());
            } else {
                boolean used = false;
                next: for (E output : op.getSignature().getOutputs()) {
                    for (E input : newInputs) {
                        used = network.match(output, input) != null;
                        if (used) {
                            log.debug(
                                    "\t\t+ Operation {} marked as useful (match detected between output {} and input {})",
                                    op.getID(), output, input);
                            optimizedSet.add(op);
                            // Update new inputs
                            futureInputs.addAll(op.getSignature().getInputs());
                            break next;
                        }
                    }
                }
                if (!used)
                    log.debug("\t\t- Operation {} marked as useless", op.getID());
            }
            //log.debug(" Inputs for the next iteration: {}", futureInputs);
        }
        newInputs.addAll(futureInputs);
        optimized.add(optimizedSet);
    }
    Collections.reverse(optimized);
    // Create a new match network
    localWatch.reset().start();
    ServiceMatchNetwork<E, T> optimizedNetwork = new DirectedAcyclicSMN<E, T>(
            new HashLeveledServices<E>(optimized), network);
    localWatch.stop();
    log.debug(" > Optimized match network created in {}", localWatch.toString());
    log.debug("Backward Optimization done in {}. Size before/after {}/{}", globalWatch.stop().toString(),
            network.listOperations().size(), optimizedNetwork.listOperations().size());
    // Create a new optimized service match network
    return optimizedNetwork;
}