List of usage examples for org.apache.commons.lang.time StopWatch getTime
public long getTime()
Get the time on the stopwatch.
This is either the time between the start and the moment this method is called, or the amount of time between start and stop.
From source file:chibi.gemmaanalysis.ExperimentMetaDataExtractorCli.java
public void generateExperimentMetaData(Collection<BioAssaySet> expressionExperiments) throws IOException { File file = getOutputFile(this.viewFile); try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)));) { String[] colNames = { "ShortName", "Taxon", "DateUpload", "IsPublic", "NumPlatform", "Platform", "Channel", "IsExonArray", "QtIsRatio", "QtIsNormalized", "QtScale", "NumProfiles", "NumFilteredProfiles", "NumSamples", "NumConditions", "NumReplicatesPerCondition", "PossibleOutliers", "CuratedOutlier", "IsTroubled", "PubTroubled", "PubYear", "PubJournal", "Batch.PC1.Var", "Batch.PC2.Var", "Batch.PC3.Var", "Batch.PC1.Pval", "Batch.PC2.Pval", "Batch.PC3.Pval", "NumFactors", "FactorNames", "FactorCategories", "NumFactorValues" }; // log.info( StringUtils.join( colNames, "\t" ) + "\n" ); writer.write(StringUtils.join(colNames, "\t") + "\n"); int i = 0; Collection<String> failedEEs = new ArrayList<>(); StopWatch timer = new StopWatch(); timer.start();// w ww . java 2s . c o m for (BioAssaySet bas : expressionExperiments) { /* * Skip subsets */ if (bas instanceof ExpressionExperimentSubSet) return; try { ExpressionExperiment ee = (ExpressionExperiment) bas; ee = eeService.thawLite(ee); ExpressionExperimentValueObject vo = eeService.loadValueObject(ee.getId()); vo.setIsPublic(!securityService.isPrivate(ee)); log.info("Processing (" + ++i + "/" + expressionExperiments.size() + ") : " + ee); BibliographicReference primaryPublication = ee.getPrimaryPublication(); Status pubStatus = primaryPublication != null ? statusService.getStatus(primaryPublication) : null; Collection<ArrayDesign> arrayDesignsUsed = eeService.getArrayDesignsUsed(ee); Collection<String> arrayDesignIsExon = new ArrayList<>(); Collection<String> arrayDesignTechTypes = new ArrayList<>(); Collection<String> arrayDesignShortNames = new ArrayList<>(); // for multiple platforms e.g. GSE5949 for (ArrayDesign ad : arrayDesignsUsed) { arrayDesignShortNames.add(ad.getShortName()); arrayDesignTechTypes.add(ad.getTechnologyType().getValue()); arrayDesignIsExon.add(ad.getName().toLowerCase().contains("exon") + ""); } QuantitationType qt = null; for (QuantitationType q : ee.getQuantitationTypes()) { if (q.getIsPreferred().booleanValue()) { qt = q; break; } } int manualOutlierCount = 0; for (BioAssay ba : ee.getBioAssays()) { if (ba.getIsOutlier().booleanValue()) { manualOutlierCount++; } } ExperimentalDesign experimentalDesign = edService.load(vo.getExperimentalDesign()); // Batch PCs int maxcomp = 3; BatchEffectDetails batchEffectPC1 = null; BatchEffectDetails batchEffectPC2 = null; BatchEffectDetails batchEffectPC3 = null; Collection<BatchEffectDetails> batchEffects = getBatchEffect(ee, maxcomp); Iterator<BatchEffectDetails> batchEffectsIterator; if (batchEffects == null || batchEffects.size() == 0) { log.warn("No batch effect info"); } else { batchEffectsIterator = batchEffects.iterator(); if (batchEffectsIterator.hasNext()) { batchEffectPC1 = batchEffectsIterator.next(); } if (batchEffectsIterator.hasNext()) { batchEffectPC2 = batchEffectsIterator.next(); } if (batchEffectsIterator.hasNext()) { batchEffectPC3 = batchEffectsIterator.next(); } } // eeService.getExperimentsWithOutliers(); StopWatch timerOutlier = new StopWatch(); timerOutlier.start(); // log.info( "Outlier detection service started " + timer.getTime() + "ms" ); Collection<OutlierDetails> possibleOutliers = outlierDetectionService.identifyOutliers(ee); if (timerOutlier.getTime() > 10000) { log.info("Automatic outlier detection took " + timerOutlier.getTime() + "ms"); } // Collection<OutlierDetails> possibleOutliers = null; // samples per condition boolean removeBatchFactor = false; Collection<String> samplesPerConditionCount = new ArrayList<>(); CountingMap<FactorValueVector> assayCount = ExperimentalDesignUtils.getDesignMatrix(ee, removeBatchFactor); List<FactorValueVector> keys = assayCount.sortedKeyList(true); for (FactorValueVector key : keys) { samplesPerConditionCount.add(Integer.toString(assayCount.get(key).intValue())); } // factor names Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors(); Collection<String> factorNames = new ArrayList<>(); Collection<String> factorCategories = new ArrayList<>(); Collection<Integer> factorValues = new ArrayList<>(); for (ExperimentalFactor f : factors) { factorNames.add(f.getName()); String cat = f.getCategory() != null ? f.getCategory().getCategory() : NA; factorCategories.add(cat); factorValues.add(Integer.valueOf(f.getFactorValues().size())); } int filteredProfilesCount = -1; try { FilterConfig filterConfig = new FilterConfig(); filterConfig.setIgnoreMinimumSampleThreshold(true); filteredProfilesCount = expressionDataMatrixService.getFilteredMatrix(ee, filterConfig, expressionDataMatrixService.getProcessedExpressionDataVectors(ee)).rows(); } catch (Exception e) { log.error(e.getMessage(), e); } String val[] = { vo.getShortName(), vo.getTaxon(), DateFormat.getDateInstance(DateFormat.MEDIUM).format(vo.getDateCreated()), vo != null ? Boolean.toString(vo.getIsPublic()) : NA, Integer.toString(arrayDesignsUsed.size()), StringUtils.join(arrayDesignShortNames, ','), StringUtils.join(arrayDesignTechTypes, ','), // arrayDesign.getTechnologyType().getValue(), // ONE-COLOR, TWO-COLOR, NONE (RNA-seq // GSE37646), DUAL-MODE (one or two color) StringUtils.join(arrayDesignIsExon, ','), // exon GSE28383 qt != null ? Boolean.toString(qt.getIsRatio().booleanValue()) : NA, qt != null ? Boolean.toString(qt.getIsNormalized().booleanValue()) : NA, qt != null ? qt.getScale().getValue() : NA, Integer.toString(vo.getProcessedExpressionVectorCount().intValue()), // NumProfiles Integer.toString(filteredProfilesCount), // NumFilteredProfiles Integer.toString(vo.getBioAssayCount().intValue()), // NumSamples Integer.toString(assayCount.size()), // NumConditions StringUtils.join(samplesPerConditionCount, ","), possibleOutliers != null ? Integer.toString(possibleOutliers.size()) : NA, Integer.toString(manualOutlierCount), Boolean.toString(vo.getTroubled()), pubStatus != null ? Boolean.toString(pubStatus.getTroubled().booleanValue()) : NA, primaryPublication != null ? DateFormat.getDateInstance(DateFormat.MEDIUM) .format(primaryPublication.getPublicationDate()) : NA, primaryPublication != null ? primaryPublication.getPublication() : NA, batchEffectPC1 != null ? Double.toString(batchEffectPC1.getComponentVarianceProportion()) : NA, batchEffectPC2 != null ? Double.toString(batchEffectPC2.getComponentVarianceProportion()) : NA, batchEffectPC3 != null ? Double.toString(batchEffectPC3.getComponentVarianceProportion()) : NA, batchEffectPC1 != null ? Double.toString(batchEffectPC1.getPvalue()) : NA, batchEffectPC2 != null ? Double.toString(batchEffectPC2.getPvalue()) : NA, batchEffectPC3 != null ? Double.toString(batchEffectPC3.getPvalue()) : NA, // factors factors != null ? Integer.toString(factors.size()) : NA, // NumFactors factorNames != null ? StringUtils.join(factorNames, ",") : NA, factorCategories != null ? StringUtils.join(factorCategories, ",") : NA, factorValues != null ? StringUtils.join(factorValues, ",") : NA, }; // log.info( StringUtils.join( val, "\t" ) + "\n" ); writer.write(StringUtils.join(val, "\t") + "\n"); } catch (Exception e) { failedEEs.add(((ExpressionExperiment) bas).getShortName()); StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); log.error(sw.toString()); } } log.info("Finished processing " + expressionExperiments.size() + " datasets in " + timer.getTime() + " ms. "); log.info("Writen to " + file); log.info("Number of failed experiment metadata extraction(s): " + failedEEs.size() + " / " + expressionExperiments.size()); if (failedEEs.size() > 0) { log.info("Skipped experiments:"); log.info(StringUtils.join(failedEEs, ",")); } } }
From source file:com.bemis.portal.migration.customer.service.impl.CustomerMigrationLocalServiceImpl.java
protected List<User> migrateCustomerUsers(List<CustomerUser> customerUsers, long companyId) { StopWatch stopWatch = new StopWatch(); stopWatch.start();//from w w w . j a va 2 s . c om List<User> liferayUsers = new ArrayList<>(); for (CustomerUser customerUser : customerUsers) { try { liferayUsers.add(addUser(customerUser, companyId)); } catch (Exception e) { e.printStackTrace(); } } if (_log.isDebugEnabled()) { _log.debug(">>> Customer user migration completed in " + stopWatch.getTime() + "ms: " + liferayUsers.size() + " total users migrated."); } return liferayUsers; }
From source file:com.liferay.vldap.server.handler.SearchLdapHandler.java
protected void addObjectEntry(InternalSearchRequest internalSearchRequest, List<InternalResponse> internalResponses, LdapHandlerContext ldapHandlerContext, Directory directory, StopWatch stopWatch) throws Exception { InternalSearchResponseEntry internalSearchResponseEntry = new SearchResponseEntryImpl( internalSearchRequest.getMessageId()); if (directory.getAttribute("objectClass", "groupOfNames") != null) { directory.getDirectories();/*from w w w . j a v a2 s . c o m*/ } Entry entry = directory.toEntry(ldapHandlerContext.getSchemaManager(), internalSearchRequest.getAttributes()); internalSearchResponseEntry.setEntry(entry); if (internalResponses.size() > getSizeLimit(internalSearchRequest)) { throw new SearchSizeLimitException(); } if ((stopWatch.getTime() / Time.SECOND) > getTimeLimit(internalSearchRequest)) { throw new SearchTimeLimitException(); } ExprNode exprNode = internalSearchRequest.getFilter(); if (isMatch(exprNode, directory)) { internalResponses.add(internalSearchResponseEntry); } }
From source file:com.hihsoft.sso.sysmonitor.syslogs.aop.LogServiceCallAdvice.java
@Override public Object invoke(final MethodInvocation invocation) throws Throwable { final String clazzString = invocation.getThis().getClass().getName();// ?? final String methodName = invocation.getMethod().getName();// ?? final String fullPath = clazzString + "." + methodName; final StopWatch clock = new StopWatch(); clock.start(); // final Object result = invocation.proceed(); clock.stop(); // ? //???? final Class<?>[] params = invocation.getMethod().getParameterTypes(); final String[] simpleParams = new String[params.length]; for (int i = 0; i < params.length; i++) { simpleParams[i] = params[i].getSimpleName(); }/*from w w w . j a v a 2 s . c om*/ //log4j.xml??? log.info( "-----------------------------------------------------------------------------"); log.info("[" + methodName + "(" + StringUtils.join(simpleParams, ",") + ")];:" + clock.getTime() + ";[" + fullPath + "]"); return result; }
From source file:edu.utah.further.i2b2.hook.further.FurtherInterceptionFilter.java
/** * Send the i2b2 query request message to the FURTHeR FQE. Must be run after the i2b2 * processing chain, because it depends on the i2b2 query ID generated by the i2b2 * server.// w w w. j a v a 2 s .c om * * @param request * @param i2b2QueryId * i2b2 query ID, obtained from the i2b2 response */ private void spawnFurtherRequest(final HttpServletRequest request, final long i2b2QueryId) { if (log.isDebugEnabled()) { log.debug("Read i2b2QueryId from request: " + i2b2QueryId); } try { // Need to read create from request.getInputStream() multiple times // in this method ==> save a copy in a buffer first // inputStream is already at the end of the file. final InputStream inputStream = request.getInputStream(); final byte[] buffer = CoreUtil.readBytesFromStream(inputStream); inputStream.close(); // Decide whether to fork or not if (StringUtil.isValidLong(i2b2QueryId) && isProcessRequest(buffer)) { // Read the FURTHeR section of the i2b2 request body final String requestXml = new String(buffer); // Request contains an FQE processing flag, send to FURTHeR if (log.isDebugEnabled()) { ServletUtil.printRequestHeaders(request); ServletUtil.printRequestParameters(request); ServletUtil.printRequestAttributes(request); } // TODO: read query instance id from i2b2 response and pass to the // following call final QueryContextIdentifier id = furtherServices.i2b2QueryRequest(requestXml, i2b2QueryId); // Make available to response through the request, ensures thread safety // instead of using instance var request.setAttribute(QUERY_ID, id); QueryState state = furtherServices.getQueryState(id).getState(); final StopWatch stopWatch = new StopWatch(); final int interval = 10; int i = 0; stopWatch.start(); // Poll state every sec final long maxQueryTimeMillis = furtherServices.getMaxQueryTime() * 1000; while (state != QueryState.COMPLETED && state != QueryState.STOPPED && state != QueryState.FAILED && state != QueryState.INVALID && state != null && stopWatch.getTime() < maxQueryTimeMillis) { Thread.yield(); state = furtherServices.getQueryState(id).getState(); if (log.isDebugEnabled() && ((i % interval) == 0)) { log.debug("QueryState for query " + id.getId() + ": " + state); } i++; } stopWatch.stop(); } else { if (log.isDebugEnabled()) { log.info("Ignoring unrecognized/irrelvant requestXml"); } } } catch (final Throwable throwable) { if (log.isDebugEnabled()) { log.error("Caught " + throwable + ", ignoring", throwable); } } }
From source file:au.id.hazelwood.xmltvguidebuilder.mapper.XmltvMapper.java
public Tv toXmltv(ChannelListings channelListings) { LOGGER.debug("Creating TV"); StopWatch stopWatch = new StopWatch(); stopWatch.start();//from w w w. j a v a2 s .c o m Tv tv = OBJECT_FACTORY.createTv(); tv.setDate(DATE_FORMAT.print(new LocalDate())); tv.setSourceInfoName(format("{0} {1}", applicationName, applicationVersion)); tv.setGeneratorInfoName(format("{0} {1}", applicationName, applicationVersion)); for (ChannelDetail channelDetail : channelListings.getChannels()) { tv.getChannel().add(createChannel(channelDetail)); for (ProgrammeDetail programmeDetail : channelListings.getPrograms(channelDetail.getId())) { tv.getProgramme().add(createProgramme(channelDetail, programmeDetail)); } } stopWatch.stop(); LOGGER.debug("Created tv in {}", formatDurationWords(stopWatch.getTime())); return tv; }
From source file:com.liferay.portlet.InvokerPortletImpl.java
public void processEvent(EventRequest eventRequest, EventResponse eventResponse) throws IOException, PortletException { StopWatch stopWatch = null; if (_log.isDebugEnabled()) { stopWatch = new StopWatch(); stopWatch.start();//from ww w . j a v a2s . c o m } invokeEvent(eventRequest, eventResponse); if (_log.isDebugEnabled()) { _log.debug("processEvent for " + _portletId + " takes " + stopWatch.getTime() + " ms"); } }
From source file:com.auditbucket.test.functional.TestTrack.java
@Test public void headersForDifferentCompaniesAreNotVisible() throws Exception { regService.registerSystemUser(new RegistrationBean(monowai, mike, "bah")); String hummingbird = "Hummingbird"; regService.registerSystemUser(new RegistrationBean(hummingbird, mark, "bah")); //Monowai/Mike SecurityContextHolder.getContext().setAuthentication(authMike); Fortress fortWP = fortressService.registerFortress(new FortressInputBean("wportfolio", true)); MetaInputBean inputBean = new MetaInputBean(fortWP.getName(), "wally", "CompanyNode", new DateTime(), "AHWP"); String ahWP = mediationFacade.createHeader(inputBean, null).getMetaKey(); assertNotNull(ahWP);//from ww w .ja v a 2 s. c om assertNotNull(trackService.getHeader(ahWP)); //Hummingbird/Gina SecurityContextHolder.getContext().setAuthentication(authMark); Fortress fortHS = fortressService.registerFortress(new FortressInputBean("honeysuckle", true)); inputBean = new MetaInputBean(fortHS.getName(), "harry", "CompanyNode", new DateTime(), "AHHS"); String ahHS = mediationFacade.createHeader(inputBean, null).getMetaKey(); assertNotNull(fortressService.getFortressUser(fortWP, "wally", true)); assertNotNull(fortressService.getFortressUser(fortHS, "harry", true)); assertNull(fortressService.getFortressUser(fortWP, "wallyz", false)); double max = 2000d; StopWatch watch = new StopWatch(); watch.start(); createLogRecords(authMike, ahWP, what, 20); createLogRecords(authMark, ahHS, what, 40); watch.stop(); logger.info("End " + watch.getTime() / 1000d + " avg = " + (watch.getTime() / 1000d) / max); }
From source file:hrider.hbase.Scanner.java
/** * Gets the total number of rows in the table. This value is calculated by scanning throughout the whole table to count the rows. This value is then cached * for future uses.//from w ww. ja va 2 s. com * * @return A total number of rows in the table. * @throws IOException Error accessing hbase. */ public long getRowsCount(long timeout) throws IOException { if (this.rowsCount == 0) { this.partialRowsCount = 0; Scan scan = getScanner(); FilterList filters = new FilterList(); if (scan.getFilter() != null) { filters.addFilter(scan.getFilter()); } filters.addFilter(new FirstKeyOnlyFilter()); scan.setFilter(filters); scan.setCaching(GlobalConfig.instance().getBatchSizeForRead()); HTable table = this.connection.getTableFactory().get(this.tableName); ResultScanner scanner = table.getScanner(scan); StopWatch stopWatch = new StopWatch(); stopWatch.start(); try { int count = 0; for (Result rr = scanner.next(); rr != null; rr = scanner.next(), count++) { if (stopWatch.getTime() > timeout) { this.partialRowsCount = count; break; } } this.rowsCount = count; } finally { stopWatch.stop(); scanner.close(); } } return this.rowsCount; }
From source file:au.id.hazelwood.xmltvguidebuilder.config.ConfigFactory.java
public Config create(File file) throws InvalidConfigException { try {// w w w . jav a 2 s. co m StopWatch stopWatch = new StopWatch(); stopWatch.start(); LOGGER.debug("Validating config file {}", file); schema.newValidator().validate(new StreamSource(file)); LOGGER.debug("Loading config file {}", file); HierarchicalConfiguration configuration = new XMLConfiguration(file); int offset = configuration.getInt("listing.offset"); int days = configuration.getInt("listing.days"); int synopsis = configuration.getInt("listing.synopsis"); String regionId = configuration.getString("listing.regionId"); Map<Integer, ChannelConfig> channelConfigById = loadChannelConfigs(configuration); Config config = new Config(offset, days, synopsis, regionId, new ArrayList<>(channelConfigById.values())); LOGGER.debug("Loaded {} from {} in {}", config, file, formatDurationWords(stopWatch.getTime())); return config; } catch (Throwable e) { throw new InvalidConfigException(e.getMessage(), e); } }