List of usage examples for com.google.common.base Stopwatch createStarted
@CheckReturnValue public static Stopwatch createStarted()
From source file:fr.ens.transcriptome.aozan.fastqscreen.FastqScreen.java
/** * Mode single-end : execute fastqscreen. * @param fastqRead1 fastq read1 file input for mapper * @param fastqRead2 fastq read2 file input for mapper * @param fastqSample instance to describe fastq sample * @param genomes list or reference genome, used by mapper * @param genomeSample genome reference corresponding to sample * @param isPairedMode true if a pair-end run and option paired mode equals * true else false/* w ww . j a v a2 s . com*/ * @throws AozanException */ public FastqScreenResult execute(final File fastqRead1, final File fastqRead2, final FastqSample fastqSample, final List<String> genomes, final String genomeSample, final boolean isPairedMode) throws AozanException { // Timer final Stopwatch timer = Stopwatch.createStarted(); final FastqScreenPseudoMapReduce pmr = new FastqScreenPseudoMapReduce(this.tmpDir, isPairedMode, this.mapperName, this.mapperArgument); try { if (isPairedMode) { pmr.doMap(fastqRead1, fastqRead2, genomes, genomeSample, this.confThreads); } else { pmr.doMap(fastqRead1, genomes, genomeSample, this.confThreads); } LOGGER.fine("FASTQSCREEN : step map for " + fastqSample.getKeyFastqSample() + " in mode " + (isPairedMode ? "paired" : "single") + " on genome(s) " + genomes + " in " + toTimeHumanReadable(timer.elapsed(TimeUnit.MILLISECONDS))); timer.reset(); timer.start(); pmr.doReduce(new File(this.tmpDir + "/outputDoReduce.txt")); LOGGER.fine("FASTQSCREEN : step reduce for " + fastqSample.getKeyFastqSample() + " in mode " + (isPairedMode ? "paired" : "single") + " in " + toTimeHumanReadable(timer.elapsed(TimeUnit.MILLISECONDS))); // Remove temporary output file use in map-reduce step final File f = new File(this.tmpDir + "/outputDoReduce.txt"); if (!f.delete()) { LOGGER.warning("Fastqscreen : fail to delete file " + f.getAbsolutePath()); } } catch (final IOException e) { throw new AozanException(e); } finally { timer.stop(); } return pmr.getFastqScreenResult(); }
From source file:org.lenskit.cli.commands.GlobalRecommend.java
@Override public void execute(Namespace opts) throws IOException, RecommenderBuildException { ScriptEnvironment env = new ScriptEnvironment(opts); InputData input = new InputData(env, opts); RecommenderLoader loader = new RecommenderLoader(input, env, opts); LenskitRecommenderEngine engine = loader.loadEngine(); List<Long> items = opts.get("items"); final int n = opts.getInt("num_recs"); try (LenskitRecommender rec = engine.createRecommender()) { ItemBasedItemRecommender irec = rec.getItemBasedItemRecommender(); ItemNameDAO indao = rec.get(ItemNameDAO.class); if (irec == null) { logger.error("recommender has no global recommender"); throw new UnsupportedOperationException("no global recommender"); }//w w w. j a v a 2 s .com logger.info("using {} reference items: {}", items.size(), items); Stopwatch timer = Stopwatch.createStarted(); ResultList recs = irec.recommendRelatedItemsWithDetails(LongUtils.packedSet(items), n, null, null); for (Result item : recs) { System.out.format("%d", item.getId()); if (indao != null) { System.out.format(" (%s)", indao.getItemName(item.getId())); } System.out.format(": %.3f", item.getScore()); System.out.println(); } timer.stop(); logger.info("recommended in {}", timer); } }
From source file:com.google.api.ads.adwords.jaxws.extensions.downloader.MultipleClientReportDownloader.java
/** * Downloads the specified report for all specified CIDs. Prints out list of failed CIDs. Returns * List<File> for all successful downloads. * * @param reportDefinition Report to download. * @param cids CIDs to download the report for. * @return Collection of File objects reports have been downloaded to. * @throws InterruptedException error trying to stop downloader thread. *//*ww w . j a v a 2 s . co m*/ public Collection<File> downloadReports(final AdWordsSession.Builder builder, final ReportDefinition reportDefinition, final Set<Long> cids) throws InterruptedException { AdWordsSessionBuilderSynchronizer sessionBuilder = new AdWordsSessionBuilderSynchronizer(builder); final Collection<Long> failed = new ConcurrentSkipListSet<Long>(); final Collection<File> results = new ConcurrentSkipListSet<File>(); // We use a Latch so the main thread knows when all the worker threads are complete. final CountDownLatch latch = new CountDownLatch(cids.size()); Stopwatch stopwatch = Stopwatch.createStarted(); for (final Long cid : cids) { RunnableDownloader downloader = new RunnableDownloader(this.retriesCount, this.backoffInterval, this.bufferSize, cid, reportDefinition, sessionBuilder, results); downloader.setFailed(failed); executeRunnableDownloader(downloader, latch); } latch.await(); stopwatch.stop(); return this.printResultsAndReturn(results, stopwatch.elapsed(TimeUnit.MILLISECONDS), failed, cids); }
From source file:org.lenskit.cli.util.RecommenderLoader.java
public LenskitRecommenderEngine loadEngine() throws RecommenderBuildException, IOException { LenskitConfiguration roots = new LenskitConfiguration(); roots.addRoot(ItemNameDAO.class); File modelFile = options.get("model_file"); if (modelFile == null) { logger.info("creating fresh recommender"); LenskitRecommenderEngineBuilder builder = LenskitRecommenderEngine.newBuilder(); for (LenskitConfiguration config : environment.loadConfigurations(getConfigFiles())) { builder.addConfiguration(config); }// w ww .jav a 2 s . c o m builder.addConfiguration(input.getConfiguration()); builder.addConfiguration(roots); Stopwatch timer = Stopwatch.createStarted(); LenskitRecommenderEngine engine = builder.build(); timer.stop(); logger.info("built recommender in {}", timer); return engine; } else { logger.info("loading recommender from {}", modelFile); LenskitRecommenderEngineLoader loader = LenskitRecommenderEngine.newLoader(); loader.setClassLoader(environment.getClassLoader()); for (LenskitConfiguration config : environment.loadConfigurations(getConfigFiles())) { loader.addConfiguration(config); } loader.addConfiguration(input.getConfiguration()); loader.addConfiguration(roots); Stopwatch timer = Stopwatch.createStarted(); LenskitRecommenderEngine engine; InputStream input = new FileInputStream(modelFile); try { input = CompressionMode.autodetect(modelFile).wrapInput(input); engine = loader.load(input); } finally { input.close(); } timer.stop(); logger.info("loaded recommender in {}", timer); return engine; } }
From source file:dk.dma.dmiweather.service.WeatherService.java
public GridResponse request(GridRequest request, boolean removeEmpty, boolean gridMetrics) { GeoCoordinate northWest = request.getNorthWest(); GeoCoordinate southEast = request.getSouthEast(); if (northWest.getLon() > southEast.getLon()) { throw new APIException(ErrorMessage.INVALID_GRID_LOT); }// w w w . ja v a 2s.c om if (northWest.getLat() < southEast.getLat()) { throw new APIException(ErrorMessage.INVALID_GRID_LAT); } Stopwatch stopwatch = Stopwatch.createStarted(); try { return findForecastData(request.getTime()).getData(request, removeEmpty, gridMetrics); } finally { log.info("Completed weather request in {} ms", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS)); } }
From source file:org.apache.distributedlog.client.proxy.ProxyClientManager.java
public ProxyClientManager(ClientConfig clientConfig, ProxyClient.Builder clientBuilder, HashedWheelTimer timer, HostProvider hostProvider, ClientStats clientStats) { this.clientConfig = clientConfig; this.clientBuilder = clientBuilder; this.timer = timer; this.hostProvider = hostProvider; this.handshakeStats = clientStats.getOpStats("handshake"); scheduleHandshake();/*from w w w. j a v a 2 s .c om*/ this.lastOwnershipSyncStopwatch = Stopwatch.createStarted(); }
From source file:net.sf.lucis.core.LucisQuery.java
public static <T> LucisQuery<Page<T>> page(final Query query, final Filter filter, final Sort sort, final DocMapper<T> mapper, final int first, final int pageSize, final Highlight highlight) { return new LucisQuery<Page<T>>() { public Page<T> perform(LucisSearcher searcher) { Stopwatch w = Stopwatch.createStarted(); int total = first + pageSize; Query rewritten = searcher.rewrite(query); TopDocs docs = getTopDocs(searcher, rewritten, filter, sort, total); if (docs.totalHits > 0) { int n = Math.min(total, docs.scoreDocs.length); float score = docs.getMaxScore(); if (n > first) { final List<T> items = Lists.newArrayListWithCapacity(n - first); HighlightedQuery highlighted = MoreObjects.firstNonNull(highlight, Highlight.no()) .highlight(rewritten); for (int i = first; i < n; i++) { ScoreDoc sd = docs.scoreDocs[i]; Document doc = searcher.doc(sd.doc); T item = mapper.map(sd.doc, score, doc, highlighted.getFragments(doc)); items.add(item); }//from w w w . j av a 2 s . co m return new Page<T>(docs.totalHits, score, w.elapsed(TimeUnit.MILLISECONDS), first, items); } else { return new Page<T>(docs.totalHits, score, w.elapsed(TimeUnit.MILLISECONDS), first, null); } } else { return new Page<T>(docs.totalHits, 0.0f, w.elapsed(TimeUnit.MILLISECONDS), first, null); } } }; }
From source file:org.apache.rocketmq.console.task.DashboardCollectTask.java
@Scheduled(cron = "30 0/1 * * * ?") @MultiMQAdminCmdMethod(timeoutMillis = 5000) public void collectTopic() { if (!rmqConfigure.isEnableDashBoardCollect()) { return;//from w w w. ja va2 s. c o m } Date date = new Date(); Stopwatch stopwatch = Stopwatch.createStarted(); try { TopicList topicList = mqAdminExt.fetchAllTopicList(); Set<String> topicSet = topicList.getTopicList(); for (String topic : topicSet) { if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) { continue; } TopicRouteData topicRouteData = mqAdminExt.examineTopicRouteInfo(topic); GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic); double inTPS = 0; long inMsgCntToday = 0; double outTPS = 0; long outMsgCntToday = 0; for (BrokerData bd : topicRouteData.getBrokerDatas()) { String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID); if (masterAddr != null) { try { stopwatch.start(); log.info("start time: {}", stopwatch.toString()); BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic); stopwatch.stop(); log.info("stop time : {}", stopwatch.toString()); stopwatch.reset(); inTPS += bsd.getStatsMinute().getTps(); inMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd); } catch (Exception e) { // throw Throwables.propagate(e); } } } if (groupList != null && !groupList.getGroupList().isEmpty()) { for (String group : groupList.getGroupList()) { for (BrokerData bd : topicRouteData.getBrokerDatas()) { String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID); if (masterAddr != null) { try { String statsKey = String.format("%s@%s", topic, group); BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey); outTPS += bsd.getStatsMinute().getTps(); outMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd); } catch (Exception e) { // throw Throwables.propagate(e); } } } } } List<String> list; try { list = dashboardCollectService.getTopicMap().get(topic); } catch (ExecutionException e) { throw Throwables.propagate(e); } if (null == list) { list = Lists.newArrayList(); } list.add(date.getTime() + "," + new BigDecimal(inTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + inMsgCntToday + "," + new BigDecimal(outTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + outMsgCntToday); dashboardCollectService.getTopicMap().put(topic, list); } log.debug("Topic Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getTopicMap().asMap())); } catch (Exception err) { throw Throwables.propagate(err); } }
From source file:org.activityinfo.server.endpoint.gwtrpc.AdvisoryLock.java
@Override public void close() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); String sql = String.format("SELECT RELEASE_LOCK('%s')", ADVISORY_LOCK_NAME); Query query = entityManager.getSession().createSQLQuery(sql); Object result = query.uniqueResult(); int resultCode = ((Number) result).intValue(); if (resultCode != SUCCESS_CODE) { throw new RuntimeException("Failed to release lock, result code: " + resultCode); }//ww w . j av a 2 s .c om stopwatch.stop(); LOGGER.finest("Release lock takes: " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms"); }
From source file:nl.knaw.huygens.timbuctoo.tools.conversion.DomainEntityCollectionConverter.java
public void convert() { String simpleName = type.getSimpleName(); LOG.info("Start converting for {}", simpleName); List<DomainEntityConverter<T>> converters = Lists.newArrayList(); try {//ww w . j a va 2s . co m //first create the jobs to prevent a mongo cursor timeout exception. for (StorageIterator<T> iterator = mongoStorage.getDomainEntities(type); iterator.hasNext();) { T entity = iterator.next(); String oldId = entity.getId(); converters.add(entityConverterFactory.create(type, oldId)); } Stopwatch stopwatch = Stopwatch.createStarted(); int number = 0; for (DomainEntityConverter<T> converter : converters) { String oldId = converter.getOldId(); try { converter.convert(); if (number % 1000 == 0) { commit(); LOG.info("Time per conversion: {} ms, number of conversions {}", (double) stopwatch.elapsed(TimeUnit.MILLISECONDS) / number, number); } number++; } catch (IllegalArgumentException | IllegalAccessException e) { LOG.error("Could not convert {} with id \"{}\"", simpleName, oldId); } } } catch (StorageException e) { LOG.error("Could not retrieve DomainEntities of type \"{}\"", simpleName); } finally { LOG.info("End converting for {}.", simpleName); commit(); } }