List of usage examples for com.google.common.base Stopwatch start
public Stopwatch start()
From source file:org.apache.drill.exec.physical.impl.xsort.MSortTemplate.java
@Override public void sort(final VectorContainer container) { final Stopwatch watch = new Stopwatch(); watch.start(); while (runStarts.size() > 1) { // check if we're cancelled/failed frequently if (!context.shouldContinue()) { return; }/*from w w w . j a v a2s . c o m*/ int outIndex = 0; newRunStarts = Queues.newLinkedBlockingQueue(); newRunStarts.add(outIndex); final int size = runStarts.size(); for (int i = 0; i < size / 2; i++) { final int left = runStarts.poll(); final int right = runStarts.poll(); Integer end = runStarts.peek(); if (end == null) { end = vector4.getTotalCount(); } outIndex = merge(left, right, end, outIndex); if (outIndex < vector4.getTotalCount()) { newRunStarts.add(outIndex); } } if (outIndex < vector4.getTotalCount()) { copyRun(outIndex, vector4.getTotalCount()); } final SelectionVector4 tmp = aux.createNewWrapperCurrent(desiredRecordBatchCount); aux.clear(); aux = this.vector4.createNewWrapperCurrent(desiredRecordBatchCount); vector4.clear(); this.vector4 = tmp.createNewWrapperCurrent(desiredRecordBatchCount); tmp.clear(); runStarts = newRunStarts; } aux.clear(); }
From source file:com.vmware.photon.controller.api.common.db.TransactionalInterceptor.java
@Override public Object invoke(MethodInvocation invocation) throws Throwable { SessionFactory sessionFactory = sessionFactoryProvider.get(); Session session;/*from ww w .ja v a2 s . c o m*/ if (ManagedSessionContext.hasBind(sessionFactory)) { session = sessionFactory.getCurrentSession(); } else { session = sessionFactory.openSession(); ManagedSessionContext.bind(session); } Transaction transaction = session.getTransaction(); if (transaction.isActive()) { return invocation.proceed(); } Stopwatch stopwatch = Stopwatch.createUnstarted(); try { logger.trace("beginning transaction: {}", transaction); stopwatch.start(); transaction.begin(); Object result = invocation.proceed(); transaction.commit(); stopwatch.stop(); logger.debug("committed: {}", transaction); return result; } catch (Throwable t) { logger.debug("rolling back: {}", transaction, t); transaction.rollback(); transactionExceptions.mark(); throw t; } finally { final long elapsedTime = stopwatch.elapsed(TimeUnit.MILLISECONDS); transactions.update(elapsedTime, TimeUnit.MILLISECONDS); ManagedSessionContext.unbind(sessionFactory); if (session.isOpen()) { session.close(); } final long transactionTimeWarningThresholdInMilliseconds = 2000L; if (elapsedTime > transactionTimeWarningThresholdInMilliseconds) { logger.warn("Transaction {} took {} milliseconds", transaction, elapsedTime); } } }
From source file:com.flipkart.foxtrot.core.datastore.impl.hbase.HBaseDataStore.java
@Override public void save(final Table table, Document document) throws DataStoreException { if (document == null || document.getData() == null || document.getId() == null) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_INVALID_REQUEST, "Invalid Document"); }/*w w w.ja v a 2s . c o m*/ HTableInterface hTable = null; try { hTable = tableWrapper.getTable(table); Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); hTable.put(getPutForDocument(table, document)); logger.error(String.format("HBASE put took : %d table : %s", stopwatch.elapsedMillis(), table)); } catch (JsonProcessingException e) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_INVALID_REQUEST, e.getMessage(), e); } catch (IOException e) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_SINGLE_SAVE, e.getMessage(), e); } catch (Exception e) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_SINGLE_SAVE, e.getMessage(), e); } finally { if (null != hTable) { try { hTable.close(); } catch (IOException e) { logger.error("Error closing table: ", e); } } } }
From source file:com.facebook.presto.split.NativeSplitManager.java
@Override public Iterable<Split> getPartitionSplits(TableHandle tableHandle, List<Partition> partitions) { Stopwatch splitTimer = new Stopwatch(); splitTimer.start(); checkNotNull(partitions, "partitions is null"); if (partitions.isEmpty()) { return ImmutableList.of(); }/*from ww w.j a va 2 s .c o m*/ Map<String, Node> nodesById = uniqueIndex(nodeManager.getAllNodes().getActiveNodes(), Node.getIdentifierFunction()); List<Split> splits = new ArrayList<>(); Multimap<Long, Entry<Long, String>> partitionShardNodes = shardManager .getCommittedPartitionShardNodes(tableHandle); for (Partition partition : partitions) { checkArgument(partition instanceof NativePartition, "Partition must be a native partition"); NativePartition nativePartition = (NativePartition) partition; ImmutableMultimap.Builder<Long, String> shardNodes = ImmutableMultimap.builder(); for (Entry<Long, String> partitionShardNode : partitionShardNodes .get(nativePartition.getNativePartitionId())) { shardNodes.put(partitionShardNode.getKey(), partitionShardNode.getValue()); } for (Map.Entry<Long, Collection<String>> entry : shardNodes.build().asMap().entrySet()) { List<HostAddress> addresses = getAddressesForNodes(nodesById, entry.getValue()); checkState(addresses.size() > 0, "no host for shard %s found", entry.getKey()); Split split = new NativeSplit(entry.getKey(), addresses); splits.add(split); } } log.debug("Split retrieval for %d partitions (%d splits): %dms", partitions.size(), splits.size(), splitTimer.elapsed(TimeUnit.MILLISECONDS)); // the query engine assumes that splits are returned in a somewhat random fashion. The native split manager, // because it loads the data from a db table will return the splits somewhat ordered by node id so only a sub // set of nodes is fired up. Shuffle the splits to ensure random distribution. Collections.shuffle(splits); return ImmutableList.copyOf(splits); }
From source file:io.grpc.internal.Rescheduler.java
Rescheduler(Runnable r, Executor serializingExecutor, ScheduledExecutorService scheduler, Stopwatch stopwatch) { this.runnable = r; this.serializingExecutor = serializingExecutor; this.scheduler = scheduler; this.stopwatch = stopwatch; stopwatch.start(); }
From source file:com.flipkart.foxtrot.core.datastore.impl.hbase.HBaseDataStore.java
@Override public void save(final Table table, List<Document> documents) throws DataStoreException { if (documents == null || documents.isEmpty()) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_INVALID_REQUEST, "Invalid Documents List"); }/*from w w w . j a v a 2 s .co m*/ List<Put> puts = new Vector<Put>(); try { for (Document document : documents) { if (document == null || document.getData() == null || document.getId() == null) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_INVALID_REQUEST, "Invalid Document"); } puts.add(getPutForDocument(table, document)); } } catch (JsonProcessingException e) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_INVALID_REQUEST, e.getMessage(), e); } HTableInterface hTable = null; try { hTable = tableWrapper.getTable(table); Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); hTable.put(puts); logger.error(String.format("HBASE put took : %d table : %s", stopwatch.elapsedMillis(), table)); } catch (IOException e) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_MULTI_SAVE, e.getMessage(), e); } catch (Exception e) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_MULTI_SAVE, e.getMessage(), e); } finally { if (null != hTable) { try { hTable.close(); } catch (IOException e) { logger.error("Error closing table: ", e); } } } }
From source file:co.cask.cdap.data.stream.MultiLiveStreamFileReader.java
@Override public int read(Collection<? super StreamEventOffset> events, int maxEvents, long timeout, TimeUnit unit, ReadFilter readFilter) throws IOException, InterruptedException { int eventsRead = 0; Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); while (eventsRead < maxEvents && !(emptySources.isEmpty() && eventSources.isEmpty())) { if (!emptySources.isEmpty()) { prepareEmptySources(readFilter); }/*from w w w.j a v a2 s .co m*/ eventsRead += read(events, readFilter); if (eventSources.isEmpty() && stopwatch.elapsedTime(unit) >= timeout) { break; } } return (eventsRead == 0 && emptySources.isEmpty() && eventSources.isEmpty()) ? -1 : eventsRead; }
From source file:be.nbb.cli.util.BasicCliLauncher.java
public void launch(@Nonnull String[] args) { ArgsParser<T> parser = parserSupplier.get(); T params = null;//from ww w . jav a2 s. c o m try { params = parser.parse(args); } catch (IllegalArgumentException ex) { System.err.println(ex.getMessage()); System.exit(-1); } StandardOptions so = toSo.apply(params); if (so.isShowHelp()) { printHelp(System.out, parser); System.exit(0); } if (so.isShowVersion()) { printVersion(System.out, commandSupplier.get()); System.exit(0); } try { Stopwatch stopwatch = Stopwatch.createUnstarted(); if (so.isVerbose()) { printParams(params, System.err); stopwatch.start(); } commandSupplier.get().exec(params); if (so.isVerbose()) { System.err.println("Executed in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms"); } } catch (Exception ex) { if (so.isVerbose()) { ex.printStackTrace(System.err); } else { System.err.println(ex.getMessage()); } System.exit(-1); } }
From source file:org.geoserver.web.GeoServerHomePage.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public GeoServerHomePage() { GeoServer gs = getGeoServer();//from ww w . j a v a2 s . c om ContactInfo contact = gs.getGlobal().getSettings().getContact(); //add some contact info add(new ExternalLink("contactURL", contact.getOnlineResource()) .add(new Label("contactName", contact.getContactOrganization()))); { String version = String.valueOf(new ResourceModel("version").getObject()); String contactEmail = contact.getContactEmail(); HashMap<String, String> params = new HashMap<String, String>(); params.put("version", version); params.put("contactEmail", contactEmail); Label label = new Label("footerMessage", new StringResourceModel("GeoServerHomePage.footer", this, new Model(params))); label.setEscapeModelStrings(false); add(label); } Authentication auth = getSession().getAuthentication(); if (isAdmin(auth)) { Stopwatch sw = new Stopwatch(); sw.start(); Fragment f = new Fragment("catalogLinks", "catalogLinksFragment", this); Catalog catalog = getCatalog(); NumberFormat numberFormat = NumberFormat.getIntegerInstance(getLocale()); numberFormat.setGroupingUsed(true); final Filter allLayers = acceptAll(); final Filter allStores = acceptAll(); final Filter allWorkspaces = acceptAll(); final int layerCount = catalog.count(LayerInfo.class, allLayers); final int storesCount = catalog.count(StoreInfo.class, allStores); final int wsCount = catalog.count(WorkspaceInfo.class, allWorkspaces); f.add(new BookmarkablePageLink("layersLink", LayerPage.class) .add(new Label("nlayers", numberFormat.format(layerCount)))); f.add(new BookmarkablePageLink("addLayerLink", NewLayerPage.class)); f.add(new BookmarkablePageLink("storesLink", StorePage.class) .add(new Label("nstores", numberFormat.format(storesCount)))); f.add(new BookmarkablePageLink("addStoreLink", NewDataPage.class)); f.add(new BookmarkablePageLink("workspacesLink", WorkspacePage.class) .add(new Label("nworkspaces", numberFormat.format(wsCount)))); f.add(new BookmarkablePageLink("addWorkspaceLink", WorkspaceNewPage.class)); add(f); sw.stop(); } else { Label placeHolder = new Label("catalogLinks"); placeHolder.setVisible(false); add(placeHolder); } final IModel<List<GeoServerHomePageContentProvider>> contentProviders; contentProviders = getContentProviders(GeoServerHomePageContentProvider.class); ListView<GeoServerHomePageContentProvider> contentView = new ListView<GeoServerHomePageContentProvider>( "contributedContent", contentProviders) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<GeoServerHomePageContentProvider> item) { GeoServerHomePageContentProvider provider = item.getModelObject(); Component extraContent = provider.getPageBodyComponent("contentList"); if (null == extraContent) { Label placeHolder = new Label("contentList"); placeHolder.setVisible(false); extraContent = placeHolder; } item.add(extraContent); } }; add(contentView); final IModel<List<CapabilitiesHomePageLinkProvider>> capsProviders; capsProviders = getContentProviders(CapabilitiesHomePageLinkProvider.class); ListView<CapabilitiesHomePageLinkProvider> capsView = new ListView<CapabilitiesHomePageLinkProvider>( "providedCaps", capsProviders) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<CapabilitiesHomePageLinkProvider> item) { CapabilitiesHomePageLinkProvider provider = item.getModelObject(); Component capsList = provider.getCapabilitiesComponent("capsList"); item.add(capsList); } }; add(capsView); }
From source file:at.sti2.sparkwave.parser.StreamParserThread.java
public void run() { long tripleCounter = 0; try {//from w w w . ja v a 2 s . c om Stopwatch stopWatch = new Stopwatch(); stopWatch.start(); while (run) { // Get triple from the stream Triple triple = getTriple(); tripleCounter++; if (!triple.isPoisonTriple()) { long currentTimeMillis = System.currentTimeMillis(); triple.setTimestamp(currentTimeMillis); //synchronized because it might happen that SparkwaveKernel thread removes a queue from queues synchronized (queues) { // put triple in all queues for (BlockingQueue<Triple> queue : queues) { queue.put(triple); } } } else { run = false; } } stopWatch.stop(); StringBuffer timeBuffer = new StringBuffer(); timeBuffer.append("Streaming took [" + stopWatch.elapsedTime(TimeUnit.MILLISECONDS) + "ms] "); timeBuffer.append(stopWatch.elapsedTime(TimeUnit.MINUTES)); timeBuffer.append(" min "); timeBuffer.append(stopWatch.elapsedTime(TimeUnit.SECONDS)); timeBuffer.append(" s "); timeBuffer.append(stopWatch.elapsedTime(TimeUnit.MILLISECONDS)); timeBuffer.append(" ms."); logger.info(timeBuffer.toString()); logger.info("Processed " + tripleCounter + " triples."); // logger.info("Pattern has been matched "+ sparkwaveNetwork.getReteNetwork().getNumMatches()+ " times."); } catch (InterruptedException e) { logger.error(e.getMessage()); } }