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.trustedanalytics.platformoperations.service.ControllerMetricsTask.java

@Override
public ControllerSummary get() {
    final Stopwatch stopwatch = Stopwatch.createStarted();
    LOGGER.info("{} started", taskName);

    final Observable<CcOrg> organizations = client.getOrgs().cache();

    final Observable<List<CcBuildpack>> buildpacks = client.getBuildpacks().toList();

    final Observable<CcOrgSummary> summaries = organizations.flatMap(org -> client.getOrgSummary(org.getGuid()))
            .onExceptionResumeNext(Observable.empty()).cache();

    final Observable<Integer> usersCount = client.getUsersCount();
    final Observable<Integer> serviceCount = client.getServicesCount();
    final Observable<Integer> serviceInstancesCount = client.getServiceInstancesCount();
    final Observable<Integer> appCount = client.getApplicationsCount();
    final Observable<Integer> orgCount = client.getOrgsCount();
    final Observable<Integer> buildpackCount = client.getBuildpacksCount();
    final Observable<Integer> spaceCount = client.getSpacesCount();

    LOGGER.info("{} completed in {}s", taskName, stopwatch.elapsed(TimeUnit.SECONDS));

    return ControllerSummary.builder().buildpacks(buildpacks.toBlocking().first())
            .userCount(usersCount.toBlocking().first().longValue())
            .orgs(summaries.toList().toBlocking().first()).appCount(appCount.toBlocking().first().longValue())
            .buildpackCount(buildpackCount.toBlocking().first().longValue())
            .orgCount(orgCount.toBlocking().first().longValue())
            .serviceCount(serviceCount.toBlocking().first().longValue())
            .serviceInstancesCount(serviceInstancesCount.toBlocking().first().longValue())
            .spaceCount(spaceCount.toBlocking().first().longValue())
            .memUsedInMb(// w  w  w  .  jav  a 2s .  c om
                    summaries.flatMapIterable(CcOrgSummary::getSpaces).map(CcOrgSummarySpace::getMemDevTotal)
                            .reduce((acc, memDevTotal) -> acc + memDevTotal).toBlocking().singleOrDefault(0))
            .build();

}

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

public static Collector<ResultGroups, ResultGroups> collect(final QueryTrace.Identifier what) {
    final Stopwatch w = Stopwatch.createStarted();

    return results -> {
        final ImmutableList.Builder<ResultGroup> groups = ImmutableList.builder();
        final ImmutableList.Builder<RequestError> errors = ImmutableList.builder();
        final ImmutableList.Builder<QueryTrace> traces = ImmutableList.builder();

        Statistics statistics = Statistics.empty();

        for (final ResultGroups r : results) {
            groups.addAll(r.groups);//from  ww w .  j  a  va 2s. c  om
            errors.addAll(r.errors);
            traces.add(r.trace);
            statistics = statistics.merge(r.statistics);
        }

        return new ResultGroups(groups.build(), errors.build(), statistics,
                new QueryTrace(what, w.elapsed(TimeUnit.NANOSECONDS), traces.build()));
    };
}

From source file:benchmarkio.benchmark.ProducerNoConsumerThenConsumer.java

@Override
public void run(final MessageConsumerCoordinator messageConsumerCoordinator,
        final MessageProducerCoordinator messageProducerCoordinator, final int numConsumers,
        final int numProducers, final long totalNumberOfMessages, final Report report) {
    CompletionService<Histogram> producerCompletionService = messageProducerCoordinator.startProducers();

    // Producer / No Consumer
    Stopwatch producerStartTime = Stopwatch.createStarted();
    report.aggregateAndPrintResults(CoordinatorType.PRODUCER, producerCompletionService, numProducers,
            totalNumberOfMessages, producerStartTime);

    // Now, let's start some consumers with producers
    final CompletionService<Histogram> consumerCompletionService = messageConsumerCoordinator.startConsumers();
    producerCompletionService = messageProducerCoordinator.startProducers();

    producerStartTime = Stopwatch.createStarted();
    final Stopwatch consumerStartTime = Stopwatch.createStarted();

    report.aggregateAndPrintResults(CoordinatorType.PRODUCER, producerCompletionService, numProducers,
            totalNumberOfMessages, producerStartTime);
    report.aggregateAndPrintResults(CoordinatorType.CONSUMER, consumerCompletionService, numConsumers,
            totalNumberOfMessages, consumerStartTime);
}

From source file:eu.amidst.huginlink.learning.ParallelPC.java

public static void main(String[] args) throws IOException {

    OptionParser.setArgsOptions(ParallelPC.class, args);

    BayesianNetworkGenerator.loadOptions();

    BayesianNetworkGenerator.setNumberOfGaussianVars(0);
    BayesianNetworkGenerator.setNumberOfMultinomialVars(100, 10);
    BayesianNetworkGenerator.setSeed(0);

    BayesianNetwork bn = BayesianNetworkGenerator.generateNaiveBayes(2);

    int sampleSize = 5000;
    BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn);
    sampler.loadOptions();/*from ww w .  j av a  2 s.  co  m*/

    DataStream<DataInstance> data = sampler.sampleToDataStream(sampleSize);

    for (int i = 1; i <= 4; i++) {
        int samplesOnMemory = 1000;
        int numCores = i;
        System.out
                .println("Learning PC: " + samplesOnMemory + " samples on memory, " + numCores + "core/s ...");
        ParallelPC parallelPC = new ParallelPC();
        parallelPC.setOptions(args);
        //tan.loadOptionsFromFile("configurationFiles/conf.txt");
        parallelPC.setNumCores(numCores);
        parallelPC.setNumSamplesOnMemory(samplesOnMemory);
        Stopwatch watch = Stopwatch.createStarted();
        BayesianNetwork model = parallelPC.learn(data);
        System.out.println(watch.stop());
    }
}

From source file:de.hybris.telcotrail.storefront.filters.RequestLoggerFilter.java

@Override
public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws IOException, ServletException {
    if (LOG.isDebugEnabled()) {
        final String requestDetails = buildRequestDetails(request);

        if (LOG.isDebugEnabled()) {
            LOG.debug(requestDetails + "Begin");
        }//from  www.j  ava  2  s .  c  om

        logCookies(request);

        final ResponseWrapper wrappedResponse = new ResponseWrapper(response);

        final Stopwatch stopwatch = Stopwatch.createStarted();
        try {
            filterChain.doFilter(request, wrappedResponse);
        } finally {
            stopwatch.stop();
            final int status = wrappedResponse.getStatus();

            if (status != 0) {
                LOG.debug(requestDetails + stopwatch.toString() + " (" + status + ")");
            } else {
                LOG.debug(requestDetails + stopwatch.toString());
            }
        }

        return;
    }

    filterChain.doFilter(request, response);
}

From source file:blue.lapis.pore.event.PoreEventWrapper.java

@SuppressWarnings("unchecked")
public static void register() throws IOException {
    Stopwatch watch = Stopwatch.createStarted();

    BufferedReader reader = new BufferedReader(
            new InputStreamReader(PoreEventWrapper.class.getResourceAsStream("events.txt")));

    String line;//w  w w .j a va2 s.c o m
    while ((line = reader.readLine()) != null) {
        line = line.trim();
        if (line.isEmpty() || line.charAt(0) == '#') {
            continue;
        }

        try {
            register((Class<? extends Event>) Class.forName(line));
        } catch (ClassNotFoundException e) {
            Pore.getLogger().warn("Failed to register class {} as an event", line, e);
        }
    }

    Pore.getLogger().debug("Registered events in {}", watch.stop());
}

From source file:es.usc.citius.composit.wsc08.data.matcher.WSCMatchGraph.java

public WSCMatchGraph(HierarchicalKnowledgeBase kb) {
    this.kb = kb;
    // Build a table using the kb and using exact/plugin match.
    Stopwatch w = Stopwatch.createStarted();
    Table<Concept, Concept, Boolean> table = HashBasedTable.create();
    for (Concept source : kb.getConcepts()) {
        Set<Concept> set = new HashSet<Concept>(kb.getSuperclasses(source));
        set.add(source);//from www.j ava  2  s  .  c o  m
        for (Concept target : set) {
            table.put(source, target, true);
        }
    }
    this.matchGraph = new HashMatchGraph<Concept, Boolean>(new MatchTable<Concept, Boolean>(table));
    logger.debug("MatchGraph computed in {}", w.stop().toString());
}

From source file:org.eclipse.viatra.dse.evolutionary.EvolutionaryStrategyLogAdapter.java

@Override
public void init(ThreadContext context) {
    this.context = context;
    for (IObjective objective : context.getObjectives()) {
        csv.columnNamesInOrder.add(objective.getName());
    }//ww  w. ja va 2  s  .  c om
    csv.createCsvFile();
    stopwatch = Stopwatch.createStarted();
}

From source file:de.perdoctus.ebikeconnect.gui.cdi.PerformanceInterceptor.java

@AroundInvoke
public Object logTime(InvocationContext invocationContext) throws Exception {
    final Stopwatch stopwatch = Stopwatch.createStarted();
    final Object proceed = invocationContext.proceed();
    logger.debug("Call to " + invocationContext.getMethod().getName() + " took "
            + stopwatch.stop().elapsed(TimeUnit.MILLISECONDS) + "ms");
    return proceed;
}

From source file:benchmarkio.benchmark.ProducerAndConsumer.java

@Override
public void run(final MessageConsumerCoordinator messageConsumerCoordinator,
        final MessageProducerCoordinator messageProducerCoordinator, final int numConsumers,
        final int numProducers, final long totalNumberOfMessages, final Report report) {
    final CompletionService<Histogram> consumerCompletionService = messageConsumerCoordinator.startConsumers();
    final CompletionService<Histogram> producerCompletionService = messageProducerCoordinator.startProducers();

    // Note that the timer is started after startConsumers() and startProducers(), this is by purpose to exclude the initialization time.
    final Stopwatch producerStartTime = Stopwatch.createStarted();
    final Stopwatch consumerStartTime = Stopwatch.createStarted();

    report.aggregateAndPrintResults(CoordinatorType.PRODUCER, producerCompletionService, numProducers,
            totalNumberOfMessages, producerStartTime);
    report.aggregateAndPrintResults(CoordinatorType.CONSUMER, consumerCompletionService, numConsumers,
            totalNumberOfMessages, consumerStartTime);
}