List of usage examples for com.google.common.base Stopwatch createStarted
@CheckReturnValue public static Stopwatch createStarted()
From source file:com.google.gerrit.server.index.group.AllGroupsIndexer.java
@Override public SiteIndexer.Result indexAll(GroupIndex index) { ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut)); progress.start(2);// w w w .j a v a 2 s .co m Stopwatch sw = Stopwatch.createStarted(); List<AccountGroup.UUID> uuids; try { uuids = collectGroups(progress); } catch (OrmException e) { log.error("Error collecting groups", e); return new SiteIndexer.Result(sw, false, 0, 0); } return reindexGroups(index, uuids, progress); }
From source file:tds.dll.common.diagnostic.services.impl.DiagnosticDatabaseServiceImpl.java
private DatabaseOperation readOperation(LegacyDbNameUtility.Databases dbName) { Stopwatch stopwatch = Stopwatch.createStarted(); try {/* w w w. ja v a 2s . co m*/ switch (dbName) { case Archive: readTestDao.readArchiveDatabase(); break; case Config: readTestDao.readConfigsDatabase(); break; case Itembank: readTestDao.readItemBankDatabase(); break; case Session: readTestDao.readSessionDatabase(); break; } } catch (DiagnosticException diagnosticException) { stopwatch.stop(); return new DatabaseOperation(Rating.FAILED, DatabaseOperationType.READ, stopwatch.elapsed(TimeUnit.MILLISECONDS), diagnosticException.getMessage()); } return new DatabaseOperation(Rating.IDEAL, DatabaseOperationType.READ, stopwatch.elapsed(TimeUnit.MILLISECONDS)); }
From source file:de.metas.ui.web.config.ServletLoggingFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { final Stopwatch stopwatch = Stopwatch.createStarted(); try {/*w w w . jav a 2 s .com*/ updateMDC(request); chain.doFilter(request, response); } finally { // // log the request if (logger.isInfoEnabled()) { final String requestInfo = extractRequestInfo(request); logger.info("Executed in {}: {}", stopwatch.stop(), requestInfo); } // // Cleanup MDC (keep it last) cleanupMDC(); } }
From source file:com.github.benmanes.caffeine.jcache.JCacheProfiler.java
private void scheduleStatusTask() { Stopwatch stopwatch = Stopwatch.createStarted(); Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(() -> { long count = this.count.longValue(); long rate = count / stopwatch.elapsed(TimeUnit.SECONDS); System.out.printf("%s - %,d [%,d / sec]%n", stopwatch, count, rate); }, 5, 5, TimeUnit.SECONDS);/*w w w. ja v a 2 s . com*/ }
From source file:com.squareup.wire.sample.CodegenSample.java
public void execute() throws IOException { Schema schema = loadSchema(); if (!identifierSet.isEmpty()) { schema = retainRoots(schema);/*from w ww. j a v a 2 s.c om*/ } JavaGenerator javaGenerator = JavaGenerator.get(schema); ServiceGenerator serviceGenerator = new ServiceGenerator(javaGenerator); for (ProtoFile protoFile : schema.protoFiles()) { for (Type type : protoFile.types()) { Stopwatch stopwatch = Stopwatch.createStarted(); ClassName javaTypeName = (ClassName) javaGenerator.typeName(type.type()); TypeSpec typeSpec = type instanceof MessageType ? javaGenerator.generateMessage((MessageType) type) : javaGenerator.generateEnum((EnumType) type); writeJavaFile(javaTypeName, typeSpec, type.location(), stopwatch); } for (Service service : protoFile.services()) { Stopwatch stopwatch = Stopwatch.createStarted(); ClassName javaTypeName = (ClassName) javaGenerator.typeName(service.type()); TypeSpec typeSpec = serviceGenerator.api(service); writeJavaFile(javaTypeName, typeSpec, service.location(), stopwatch); } } }
From source file:com.edduarte.argus.diff.DifferenceDetector.java
@Override public List<Difference> call() { Stopwatch sw = Stopwatch.createStarted(); DiffMatchPatch dmp = new DiffMatchPatch(); String original = oldSnapshot.getProcessedContent(); String revision = newSnapshot.getProcessedContent(); LinkedList<DiffMatchPatch.Diff> diffs = dmp.diff_main(original, revision); dmp.diff_cleanupSemantic(diffs);//from www . j ava 2s .co m Parser parser; try { parser = parserPool.take(); } catch (InterruptedException ex) { logger.error(ex.getMessage(), ex); return null; } int insertedCountOffset = 0, deletedCountOffset = 0; List<Difference> retrievedDiffs = new ArrayList<>(); for (DiffMatchPatch.Diff diff : diffs) { String diffText = diff.text; List<Parser.Result> results = parser.parse(new MutableString(diffText)); for (Parser.Result result : results) { String snippet; String occurrenceText = result.text.toString(); switch (diff.action) { case inserted: { int wordNum = insertedCountOffset++; snippet = getSnippet(newSnapshot, occurrenceText, wordNum); break; } case deleted: { int wordNum = deletedCountOffset++; snippet = getSnippet(oldSnapshot, occurrenceText, wordNum); break; } default: { insertedCountOffset++; deletedCountOffset++; continue; } } retrievedDiffs.add(new Difference(diff.action, result.text.toString(), snippet)); } results.clear(); results = null; } try { parserPool.place(parser); } catch (InterruptedException ex) { logger.error(ex.getMessage(), ex); return null; } // ListIterator<MatchedDiff> it = retrievedDiffs.listIterator(); // int i = 1; // while (it.hasNext() && i < retrievedDiffs.size()) { // MatchedDiff d1 = it.next(); // MatchedDiff d2 = retrievedDiffs.get(i); // // if (d1.status == d2.status && // d1.keyword.equals(d2.keyword) && // d1.endIndex + SNIPPET_INDEX_OFFSET >= d2.startIndex - SNIPPET_INDEX_OFFSET) { //// d2.startIndex = d1.startIndex; // it.remove(); // // } else { // i++; // } // } sw.stop(); logger.info("Completed difference detection for document '{}' in {}", newSnapshot.getUrl(), sw.toString()); return retrievedDiffs; }
From source file:fr.ymanvieu.trading.Update.java
@Bean public ApplicationRunner run() { return (args) -> { List<SymbolEntity> symbols = symbolRepo.findAll(); SymbolEntity euro = symbolRepo.findOne("EUR"); ThreadLocalRandom r = ThreadLocalRandom.current(); IntStream.range(1, 11).forEach(ii -> { List<Quote> rates = new ArrayList<>(); int nb = ii * 1000; IntStream.range(0, nb).forEach(i -> { float fl = r.nextFloat() * symbols.size(); Calendar c = Calendar.getInstance(); c.setTime(new Date(r.nextLong(-30610227600000L, 253402210800000L))); rates.add(new Quote(euro.getCode(), symbols.get((int) fl).getCode(), new BigDecimal(fl), c.getTime()));//from www . java 2 s . co m }); Stopwatch sw = Stopwatch.createStarted(); hRateRepo.updateRates(rates); float rps = nb / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000f); log.info("save {} rates in {} ({}/s)", nb, sw, rps); }); }; }
From source file:org.glowroot.container.impl.JavaagentMain.java
private static void startViewer() throws AssertionError { Executors.newSingleThreadExecutor().execute(new Runnable() { @Override/*from w w w .ja va2 s . co m*/ public void run() { try { Viewer.main(); } catch (Exception e) { logger.error(e.getMessage(), e); } } }); Stopwatch stopwatch = Stopwatch.createStarted(); // need to wait longer than expected here when running with jacoco on travis ci boxes while (stopwatch.elapsed(SECONDS) < 30) { if (MainEntryPoint.getGlowrootModule() != null) { break; } } if (MainEntryPoint.getGlowrootModule() == null) { throw new AssertionError("Timeout occurred waiting for glowroot to start"); } }
From source file:com.google.api.ads.adwords.awreporting.server.kratu.KratuProcessor.java
public void processKratus(Long topAccountId, Set<Long> accountIdsSet, Date dateStart, Date dateEnd) throws InterruptedException { System.out.println("Processing Kratus for " + topAccountId); // 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(topAccountId, accountIdsSet, storageHelper, dateStart, dateEnd);//from w w w. j a v a 2 s. co m ExecutorService executorService = Executors.newFixedThreadPool(1); runnableKratu.setLatch(latch); executorService.execute(runnableKratu); latch.await(); stopwatch.stop(); }
From source file:com.edduarte.vokter.diff.DifferenceDetector.java
@Override public List<Difference> call() { Stopwatch sw = Stopwatch.createStarted(); DiffMatchPatch dmp = new DiffMatchPatch(); String original = oldSnapshot.getProcessedContent(); String revision = newSnapshot.getProcessedContent(); // TODO: use LSH to determine a similarity index. If distance is above // 0.4, the documents are different enough and a more computational // intensive task (analysing token by token differences). LinkedList<DiffMatchPatch.Diff> diffs = dmp.diff_main(original, revision); dmp.diff_cleanupSemantic(diffs);// w w w.j av a 2s. co m Parser parser; try { parser = parserPool.take(); } catch (InterruptedException ex) { logger.error(ex.getMessage(), ex); return null; } int insertedCountOffset = 0, deletedCountOffset = 0; List<Difference> retrievedDiffs = new ArrayList<>(); for (DiffMatchPatch.Diff diff : diffs) { String diffText = diff.text; List<Parser.Result> results = parser.parse(new MutableString(diffText)); for (Parser.Result result : results) { String snippet; String occurrenceText = result.text.toString(); switch (diff.action) { case inserted: { int wordNum = insertedCountOffset++; snippet = getSnippet(newSnapshot, occurrenceText, wordNum); break; } case deleted: { int wordNum = deletedCountOffset++; snippet = getSnippet(oldSnapshot, occurrenceText, wordNum); break; } default: { insertedCountOffset++; deletedCountOffset++; continue; } } retrievedDiffs.add(new Difference(diff.action, result.text.toString(), snippet)); } results.clear(); results = null; } try { parserPool.place(parser); } catch (InterruptedException ex) { logger.error(ex.getMessage(), ex); return null; } // ListIterator<MatchedDiff> it = retrievedDiffs.listIterator(); // int i = 1; // while (it.hasNext() && i < retrievedDiffs.size()) { // MatchedDiff d1 = it.next(); // MatchedDiff d2 = retrievedDiffs.get(i); // // if (d1.status == d2.status && // d1.keyword.equals(d2.keyword) && // d1.endIndex + SNIPPET_INDEX_OFFSET >= d2.startIndex - SNIPPET_INDEX_OFFSET) { //// d2.startIndex = d1.startIndex; // it.remove(); // // } else { // i++; // } // } sw.stop(); logger.info("Completed difference detection for document '{}' in {}", newSnapshot.getUrl(), sw.toString()); return retrievedDiffs; }