Example usage for com.google.common.base Stopwatch stop

List of usage examples for com.google.common.base Stopwatch stop

Introduction

In this page you can find the example usage for com.google.common.base Stopwatch stop.

Prototype

public Stopwatch stop() 

Source Link

Document

Stops the stopwatch.

Usage

From source file:org.smartdeveloperhub.vocabulary.publisher.handlers.ProbeTracerHandler.java

@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    final Stopwatch watch = MoreAttachments.getStopwatch(exchange);
    watch.stop();
    LOGGER.trace("[{}][{}] Processing took {} {}", exchange.getRequestPath(), exchange.getRelativePath(),
            watch.elapsed(this.unit), this.unit.toString());
    this.next.handleRequest(exchange);
}

From source file:com.google.pubsub.clients.gcloud.CPSPublisherTask.java

@Override
public void run() {
    try {/*from w w  w .  j a v a  2  s . co  m*/
        List<Message> messages = new ArrayList<>(batchSize);
        String sendTime = String.valueOf(System.currentTimeMillis());
        for (int i = 0; i < batchSize; i++) {
            messages.add(Message.builder(payload).addAttribute("sendTime", sendTime)
                    .addAttribute("clientId", id.toString())
                    .addAttribute("sequenceNumber", Integer.toString(getAndIncrementNumberOfMessages()))
                    .build());
        }
        Stopwatch stopwatch = Stopwatch.createStarted();
        pubSub.publish(topic, messages);
        stopwatch.stop();
        metricsHandler.recordLatencyBatch(stopwatch.elapsed(TimeUnit.MILLISECONDS), batchSize);
    } catch (PubSubException e) {
        log.error("Publish request failed", e);
    }
}

From source file:processing.FolkRankCalculator.java

private static void startFolkRankCreation(BookmarkReader reader, int sampleSize) {
    timeString = "";
    System.out.println("\nStart FolkRank Calculation for Tags");
    frResults = new ArrayList<int[]>();
    prResults = new ArrayList<int[]>();
    int size = reader.getUserLines().size();
    int trainSize = size - sampleSize;
    Stopwatch timer = new Stopwatch();
    timer.start();/*from www .  j a  v a2 s.co  m*/
    FactReader factReader = new WikipediaFactReader(reader, trainSize, 3);
    FactPreprocessor prep = new FactReaderFactPreprocessor(factReader);
    prep.process();
    FolkRankData facts = prep.getFolkRankData();

    FolkRankParam param = new FolkRankParam();
    FolkRankPref pref = new FolkRankPref(new double[] { 1.0, 1.0, 1.0 });
    int usrCounts = facts.getCounts()[1].length;
    System.out.println("Users: " + usrCounts);
    int resCounts = facts.getCounts()[2].length;
    System.out.println("Resources: " + resCounts);
    double[][] prefWeights = new double[][] { new double[] {}, new double[] { usrCounts },
            new double[] { resCounts } };
    FolkRankAlgorithm folk = new FolkRankAlgorithm(param);
    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);

    timer = new Stopwatch();
    // start FolkRank        
    for (int i = trainSize; i < size; i++) {
        timer.start();
        UserData data = reader.getUserLines().get(i);
        int u = data.getUserID();
        int[] uPrefs = (u < usrCounts ? new int[] { u } : new int[] {});
        int r = data.getWikiID();
        int[] rPrefs = (r < resCounts ? new int[] { r } : new int[] {});
        pref.setPreference(new int[][] { new int[] {}, uPrefs, rPrefs }, prefWeights);
        FolkRankResult result = folk.computeFolkRank(facts, pref);

        int[] topTags = new int[10];
        SortedSet<ItemWithWeight> topKTags = ItemWithWeight.getTopK(facts, result.getWeights(), 10, 0);
        int count = 0;
        for (ItemWithWeight item : topKTags) {
            topTags[count++] = item.getItem();
        }
        frResults.add(topTags);
        timer.stop();

        int[] topTagsPr = new int[10];
        SortedSet<ItemWithWeight> topKTagsPr = ItemWithWeight.getTopK(facts, result.getAPRWeights(), 10, 0);
        count = 0;
        for (ItemWithWeight item : topKTagsPr) {
            topTagsPr[count++] = item.getItem();
        }
        prResults.add(topTagsPr);
        //System.out.println(u + "|" + data.getTags().toString().replace("[", "").replace("]", "") + 
        //                  "|" + Arrays.toString(topTags).replace("[", "").replace("]", "") + 
        //                  "|" + Arrays.toString(topTagsPr).replace("[", "").replace("]", ""));
    }
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
    timeString += ("Full training time: " + trainingTime + "\n");
    timeString += ("Full test time: " + testTime + "\n");
    timeString += ("Average test time: " + testTime / (double) sampleSize) + "\n";
    timeString += ("Total time: " + (trainingTime + testTime) + "\n");
}

From source file:me.bramhaag.discordselfbot.commands.admin.CommandPing.java

@Command(name = "ping")
public void execute(@NonNull Message message, @NonNull TextChannel channel, @NonNull String[] args) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    message.editMessage("`Waiting...`").queue(m -> {
        stopwatch.stop();
        m.editMessage(new EmbedBuilder().setTitle(Constants.PONG_EMOTE + " Pong!", null)
                .addField("Response time (Bot)", stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms", true)
                .addField("Response time (API)", message.getJDA().getPing() + " ms", true)
                .setFooter("Ping | " + Util.generateTimestamp(), null).build())
                .queue(embed -> embed.delete().queueAfter(Constants.REMOVE_TIME_LONG, TimeUnit.SECONDS));
    });/*from   w ww  .  java 2  s .co m*/
}

From source file:com.smithsmodding.smithscore.SmithsCore.java

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
    Stopwatch watch = Stopwatch.createStarted();

    watch.stop();

    Long milliseconds = watch.elapsed(TimeUnit.MILLISECONDS);
    getLogger().info(CoreReferences.LogMarkers.POSTINIT,
            "SmithsCore Post-Init completed after: " + milliseconds + " ms.");
}

From source file:com.couchbase.roadrunner.workloads.GetSetWorkload.java

private void setWorkloadWithMeasurement(String key) throws Exception {
    Stopwatch watch = new Stopwatch().start();
    setWorkload(key);//from  ww w  . j a va2  s. co  m
    watch.stop();
    addMeasure("set", watch);
}

From source file:com.couchbase.roadrunner.workloads.GetSetWorkload.java

private void getWorkloadWithMeasurement(String key) throws Exception {
    Stopwatch watch = new Stopwatch().start();
    getWorkload(key);//from  w  w  w.  ja  v a  2  s  .  co m
    watch.stop();
    addMeasure("get", watch);
}

From source file:org.arbeitspferde.friesian.WorkEngine.java

public void run() {
    long startMillis;
    init();/*from  ww w  .ja v a  2s.  co  m*/
    while (workNotFinished()) {
        // TODO(mtp): This introduces non-determinism for testing; fix.
        final Stopwatch timer = new Stopwatch().start();
        doWork();
        timer.stop();
        jtaWorkerWorkTime.addAndGet(timer.elapsed(TimeUnit.MILLISECONDS));
        if (sleepProbability >= RandomNumber.generatePercentage(rng)) {
            try {
                Thread.sleep(workerSleepTime);
                jtaWorkerSleepTime.addAndGet(workerSleepTime);
            } catch (InterruptedException e) {
                log.log(Level.WARNING, "Worker is unable to sleep", e);
            }
        }
    }
    cache();
}

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();

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

    return response;
}

From source file:org.zalando.zmon.actuator.ZmonRestResponseFilter.java

@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
        final ClientHttpRequestExecution execution) throws IOException {

    Stopwatch stopwatch = Stopwatch.createStarted();
    ClientHttpResponse response = execution.execute(request, body);
    stopwatch.stop();
    metricsWrapper.recordBackendRoundTripMetrics(request, response, stopwatch);
    return response;
}