List of usage examples for com.google.common.base Stopwatch createStarted
@CheckReturnValue public static Stopwatch createStarted()
From source file:com.salesforce.grpc.contrib.interceptor.StopwatchClientInterceptor.java
@Override public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { logStart(method);// w w w .ja va 2s. c o m return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) { private Stopwatch stopwatch = Stopwatch.createStarted(); @Override public void start(Listener<RespT> responseListener, Metadata headers) { super.start(new ForwardingClientCallListener.SimpleForwardingClientCallListener<RespT>( responseListener) { @Override public void onClose(Status status, Metadata trailers) { super.onClose(status, trailers); logStop(method, Duration.ofNanos(stopwatch.stop().elapsed(TimeUnit.NANOSECONDS))); } }, headers); } }; }
From source file:org.apache.jackrabbit.oak.backup.FileStoreBackup.java
public static void backup(@Nonnull SegmentReader reader, @Nonnull Revisions revisions, @Nonnull File destination) throws IOException { Stopwatch watch = Stopwatch.createStarted(); SegmentGCOptions gcOptions = SegmentGCOptions.defaultGCOptions().setOffline(); FileStoreBuilder builder = fileStoreBuilder(destination).withDefaultMemoryMapping(); if (USE_FAKE_BLOBSTORE) { builder.withBlobStore(new BasicReadOnlyBlobStore()); }//from www . jav a 2 s . co m builder.withGCOptions(gcOptions); FileStore backup = builder.build(); SegmentNodeState current = reader.readHeadState(revisions); try { int gen = 0; gen = current.getRecordId().getSegment().getGcGeneration(); SegmentBufferWriter bufferWriter = new SegmentBufferWriter(backup, backup.getTracker(), backup.getReader(), "b", gen); SegmentWriter writer = new SegmentWriter(backup, backup.getReader(), backup.getBlobStore(), new WriterCacheManager.Default(), bufferWriter); Compactor compactor = new Compactor(backup.getReader(), writer, backup.getBlobStore(), Suppliers.ofInstance(false), gcOptions); compactor.setContentEqualityCheck(true); SegmentNodeState head = backup.getHead(); SegmentNodeState after = compactor.compact(head, current, head); if (after != null) { backup.getRevisions().setHead(head.getRecordId(), after.getRecordId()); } } finally { backup.close(); backup = null; } FileStoreBuilder builder2 = fileStoreBuilder(destination).withDefaultMemoryMapping(); builder2.withGCOptions(gcOptions); backup = builder2.build(); try { cleanup(backup); } finally { backup.close(); } watch.stop(); log.info("Backup finished in {}.", watch); }
From source file:qa.qcri.nadeef.core.pipeline.ScopeOperator.java
/** * {@inheritDoc}//from w w w .j a va 2s .com */ @Override @SuppressWarnings("unchecked") public Collection<Table> execute(Collection<Table> tables) throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); ExecutionContext context = getCurrentContext(); Rule rule = context.getRule(); // Scope // Here the horizontalScope needs to be called before vertical Scope since // it may needs the attributes which are going to be removed from verticals scope. Collection<Table> horizontalScopeResult = rule.horizontalScope(tables); setPercentage(0.5f); long time = stopwatch.elapsed(TimeUnit.MILLISECONDS); long currentTime; Collection<Table> verticalScopeResult = rule.verticalScope(horizontalScopeResult); currentTime = stopwatch.elapsed(TimeUnit.MILLISECONDS); PerfReport.appendMetric(PerfReport.Metric.HScopeTime, time); PerfReport.appendMetric(PerfReport.Metric.VScopeTime, currentTime - time); PerfReport.appendMetric(PerfReport.Metric.AfterScopeTuple, verticalScopeResult.size()); Collection<Table> result = verticalScopeResult; // Block // Currently we don't support co-group, so once a rule is working with two tables we // ignore the block function. if (!rule.supportTwoTables()) { result = rule.block(verticalScopeResult); PerfReport.appendMetric(PerfReport.Metric.Blocks, result.size()); } stopwatch.stop(); return result; }
From source file:com.spotify.heroic.statistics.semantic.SemanticHeroicTimerGauge.java
@Override public Context time() { final Stopwatch stopwatch = Stopwatch.createStarted(); return new Context() { @Override/*from w w w . ja v a2 s.co m*/ public long stop() { final long elapsed = stopwatch.elapsed(TimeUnit.NANOSECONDS); value.set(elapsed); return elapsed; } @Override public void finished() throws Exception { stop(); } }; }
From source file:org.opendaylight.bgpcep.pcep.topology.provider.PCEPRequest.java
PCEPRequest(final Metadata metadata) { this.future = SettableFuture.create(); this.metadata = metadata; this.state = State.UNSENT; this.stopwatch = Stopwatch.createStarted(); this.timer = new Timer(); }
From source file:com.google.copybara.util.CommandUtil.java
/** * Executes a {@link Command} with the given input and writes to the console and the log depending * on the exit code of the command and the verbose flag. *///from w w w. j a v a 2s . c o m public static CommandOutputWithStatus executeCommand(Command cmd, byte[] input, boolean verbose) throws CommandException { Stopwatch stopwatch = Stopwatch.createStarted(); String startMsg = "Executing [" + ShellUtils.prettyPrintArgv(Arrays.asList(cmd.getCommandLineElements())) + "]"; logger.log(Level.INFO, startMsg); if (verbose) { System.err.println(startMsg); } ByteArrayOutputStream stdoutCollector = new ByteArrayOutputStream(); ByteArrayOutputStream stderrCollector = new ByteArrayOutputStream(); CommandResult cmdResult; TerminationStatus exitStatus = null; try { cmdResult = cmd.execute(input, new SimpleKillableObserver(), // If verbose we stream to the user console too verbose ? new DemultiplexOutputStream(System.err, stdoutCollector) : stdoutCollector, verbose ? new DemultiplexOutputStream(System.err, stderrCollector) : stderrCollector, true); exitStatus = cmdResult.getTerminationStatus(); return new CommandOutputWithStatus(cmdResult.getTerminationStatus(), stdoutCollector.toByteArray(), stderrCollector.toByteArray()); } catch (BadExitStatusException e) { exitStatus = e.getResult().getTerminationStatus(); throw new BadExitStatusWithOutputException(e.getCommand(), e.getResult(), e.getMessage(), stdoutCollector.toByteArray(), stderrCollector.toByteArray()); } finally { String finishMsg = "Command '" + cmd.getCommandLineElements()[0] + "' finished in " + stopwatch + ". " + (exitStatus != null ? exitStatus.toString() : "(No exit status)"); boolean success = exitStatus != null && exitStatus.success(); Level logLevel = success ? Level.INFO : Level.SEVERE; logOutput(logLevel, cmd, "STDOUT", stdoutCollector); logOutput(logLevel, cmd, "STDERR", stderrCollector); logger.log(logLevel, finishMsg); if (verbose) { System.err.println(finishMsg); } } }
From source file:org.apache.bookkeeper.common.stats.OpStatsListener.java
public OpStatsListener(OpStatsLogger opStatsLogger, Stopwatch stopwatch) { this.opStatsLogger = opStatsLogger; if (null == stopwatch) { this.stopwatch = Stopwatch.createStarted(); } else {//from www .j a v a 2 s. c o m this.stopwatch = stopwatch; } }
From source file:org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreHelper.java
public static void garbageReport(DocumentNodeStore dns) { System.out.print("Collecting top 100 nodes with most blob garbage "); Stopwatch sw = Stopwatch.createStarted(); Iterable<BlobReferences> refs = scan(dns, new BlobGarbageSizeComparator(), 100); for (BlobReferences br : refs) { System.out.println(br);// ww w .ja v a2 s .c om } System.out.println("Collected in " + sw.stop()); }
From source file:net.sf.lucis.core.LucisQuery.java
public static <T> LucisQuery<Item<T>> first(final Query query, final Filter filter, final Sort sort, final DocMapper<T> mapper, final Highlight highlight) { return new LucisQuery<Item<T>>() { public Item<T> perform(final LucisSearcher searcher) { Stopwatch w = Stopwatch.createStarted(); Query rewritten = searcher.rewrite(query); TopDocs docs = getTopDocs(searcher, query, filter, sort, 1); if (docs.totalHits > 0) { ScoreDoc sd = docs.scoreDocs[0]; Document doc = searcher.doc(sd.doc); HighlightedQuery highlighted = MoreObjects.firstNonNull(highlight, Highlight.no()) .highlight(rewritten); float score = sd.score; T item = mapper.map(sd.doc, score, doc, highlighted.getFragments(doc)); return new Item<T>(docs.totalHits, score, w.elapsed(TimeUnit.MILLISECONDS), item); } else { return new Item<T>(docs.totalHits, 0.0f, w.elapsed(TimeUnit.MILLISECONDS), null); }// w ww . java2s. co m } }; }
From source file:com.google.devtools.build.android.LoggingProfiler.java
@Override public Profiler startTask(String taskName) { Preconditions.checkArgument(!tasks.containsKey(taskName)); tasks.put(taskName, Stopwatch.createStarted()); return this; }