Search in sources :

Example 81 with StopWatch

use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.

the class DebugBotIncomingMessageToEventMappingAction method validate.

private void validate(EventListenerContext ctx, EventBus bus, Connection con) {
    Model messageModel = WonRdfUtils.MessageUtils.textMessage("ok, I'll validate the connection - but I'll need to crawl the connection data first, please be patient.");
    bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
    // initiate crawl behaviour
    CrawlConnectionCommandEvent command = new CrawlConnectionCommandEvent(con.getNeedURI(), con.getConnectionURI());
    CrawlConnectionDataBehaviour crawlConnectionDataBehaviour = new CrawlConnectionDataBehaviour(ctx, command, Duration.ofSeconds(60));
    final StopWatch crawlStopWatch = new StopWatch();
    crawlStopWatch.start("crawl");
    crawlConnectionDataBehaviour.onResult(new SendMessageReportingCrawlResultAction(ctx, con, crawlStopWatch));
    crawlConnectionDataBehaviour.onResult(new SendMessageOnCrawlResultAction(ctx, con) {

        @Override
        protected Model makeSuccessMessage(CrawlConnectionCommandSuccessEvent successEvent) {
            try {
                logger.debug("validating data of connection {}", command.getConnectionURI());
                // TODO: use one validator for all invocations
                WonConnectionValidator validator = new WonConnectionValidator();
                StringBuilder message = new StringBuilder();
                boolean valid = validator.validate(successEvent.getCrawledData(), message);
                String successMessage = "Connection " + command.getConnectionURI() + " is valid: " + valid + " " + message.toString();
                return WonRdfUtils.MessageUtils.textMessage(successMessage);
            } catch (Exception e) {
                return WonRdfUtils.MessageUtils.textMessage("Caught exception during validation: " + e);
            }
        }
    });
    crawlConnectionDataBehaviour.activate();
}
Also used : CrawlConnectionCommandSuccessEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandSuccessEvent) CrawlConnectionDataBehaviour(won.bot.framework.eventbot.behaviour.CrawlConnectionDataBehaviour) StopWatch(org.springframework.util.StopWatch) WonConnectionValidator(won.protocol.validation.WonConnectionValidator) Model(org.apache.jena.rdf.model.Model) ConnectionMessageCommandEvent(won.bot.framework.eventbot.event.impl.command.connectionmessage.ConnectionMessageCommandEvent) CrawlConnectionCommandEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandEvent)

Example 82 with StopWatch

use of org.springframework.util.StopWatch in project loc-framework by lord-of-code.

the class LocAccessLogFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
    if (ignoreRequest(httpServletRequest)) {
        filterChain.doFilter(httpServletRequest, httpServletResponse);
    } else {
        final boolean isFirstRequest = !isAsyncDispatch(httpServletRequest);
        final LocAccessLogger accessLogger = new LocAccessLogger(this.properties);
        HttpServletRequest requestToUse = httpServletRequest;
        ContentCachingResponseWrapper responseToUse = new ContentCachingResponseWrapper(httpServletResponse);
        StopWatch watch = new StopWatch();
        watch.start();
        if (isFirstRequest && !(httpServletRequest instanceof ContentCachingRequestWrapper)) {
            requestToUse = new ContentCachingRequestWrapper(httpServletRequest, properties.getRequestBodyLength());
        }
        try {
            filterChain.doFilter(requestToUse, responseToUse);
        } finally {
            if (isFirstRequest) {
                accessLogger.appendRequestCommonMessage(requestToUse);
                accessLogger.appendRequestDetailMessage(properties.isIncludeRequest(), requestToUse);
            }
            watch.stop();
            if (!isAsyncStarted(requestToUse)) {
                accessLogger.appendResponseCommonMessage(responseToUse, watch.getTotalTimeMillis());
                if (properties.isIncludeResponse() && !isBinaryContent(httpServletResponse) && !isMultipart(httpServletResponse)) {
                    accessLogger.appendResponseDetailMessage(responseToUse);
                }
                accessLogger.appendResponseLast();
            }
            responseToUse.copyBodyToResponse();
            accessLogger.printLog();
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContentCachingResponseWrapper(org.springframework.web.util.ContentCachingResponseWrapper) ContentCachingRequestWrapper(org.springframework.web.util.ContentCachingRequestWrapper) StopWatch(org.springframework.util.StopWatch)

Example 83 with StopWatch

use of org.springframework.util.StopWatch in project Gemma by PavlidisLab.

the class DifferentialExpressionSearchTaskImpl method addConditionsToSearchResultValueObject.

/**
 * Get information on the conditions to be searched. This is not part of the query for the results themselves, but
 * uses the database to get metadata/summaries about the analyses that will be used. Initializes the searchResult
 * value object. Later, values which are non-missing will be replaced with either 'non-significant' or 'significant'
 * results.
 *
 * @param searchResult to be initialized
 * @return list of the resultSets that should be queried.
 */
private List<DiffExResultSetSummaryValueObject> addConditionsToSearchResultValueObject(DifferentialExpressionGenesConditionsValueObject searchResult) {
    StopWatch watch = new StopWatch("addConditionsToSearchResultValueObject");
    watch.start("Add conditions to search result value object");
    List<DiffExResultSetSummaryValueObject> usedResultSets = new LinkedList<>();
    int i = 0;
    DifferentialExpressionSearchTaskImpl.log.info("Loading " + experimentGroupName + " experiments...");
    // database hit: important that this be fast.
    Map<ExpressionExperimentDetailsValueObject, Collection<DifferentialExpressionAnalysisValueObject>> analyses = differentialExpressionAnalysisService.getAnalysesByExperiment(EntityUtils.getIds(experimentGroup));
    experiment: for (ExpressionExperimentDetailsValueObject bas : analyses.keySet()) {
        Collection<DifferentialExpressionAnalysisValueObject> analysesForExperiment = this.filterAnalyses(analyses.get(bas));
        if (analysesForExperiment.isEmpty()) {
            continue;
        }
        /*
             * There will often just be one analysis for the experiment. Exception would be when there is subsetting.
             */
        for (DifferentialExpressionAnalysisValueObject analysis : analysesForExperiment) {
            List<DiffExResultSetSummaryValueObject> resultSets = this.filterResultSets(analysis);
            usedResultSets.addAll(resultSets);
            if (resultSets.isEmpty()) {
                DifferentialExpressionSearchTaskImpl.log.info("No resultSets usable for " + bas.getId());
            }
            for (DiffExResultSetSummaryValueObject resultSet : resultSets) {
                // sanity check.
                assert resultSet.getNumberOfDiffExpressedProbes() != null;
                // interactions not okay
                assert resultSet.getExperimentalFactors().size() == 1;
                ExperimentalFactorValueObject factor = resultSet.getExperimentalFactors().iterator().next();
                Collection<FactorValueValueObject> factorValues = this.filterFactorValues(analysis, factor.getValues(), resultSet.getBaselineGroup().getId());
                if (factorValues.isEmpty()) {
                    /*
                         * This can only happen if there is just a baseline factorvalue. Even for one-sided tests //
                         * that // won't be the case.
                         */
                    DifferentialExpressionSearchTaskImpl.log.warn("Nothing usable for resultSet=" + resultSet.getResultSetId());
                    continue;
                }
                for (FactorValueValueObject factorValue : factorValues) {
                    Condition condition = searchResult.new Condition(bas, analysis, resultSet, factorValue);
                    condition.setExperimentGroupName(experimentGroupName);
                    /*
                         * SANITY CHECKS these fields should be filled in. If not, we are going to skip the results.
                         */
                    if (condition.getNumberDiffExpressedProbes() == -1) {
                        DifferentialExpressionSearchTaskImpl.log.warn(bas + ": Error: No hit list sizes for resultSet with ID=" + resultSet.getResultSetId());
                        continue;
                    }
                    if (condition.getNumberOfProbesOnArray() == null || condition.getNumberDiffExpressedProbes() == null) {
                        DifferentialExpressionSearchTaskImpl.log.error(bas + ": Error: Null counts for # diff ex probe or # probes on array, Skipping");
                        continue experiment;
                    } else if (condition.getNumberOfProbesOnArray() < condition.getNumberDiffExpressedProbes()) {
                        DifferentialExpressionSearchTaskImpl.log.error(bas + ": Error: More diff expressed probes than probes on array. Skipping.");
                        continue experiment;
                    }
                    searchResult.addCondition(condition);
                    i++;
                }
            }
        }
    }
    watch.stop();
    if (watch.getTotalTimeMillis() > 100) {
        // This does not include getting the actual diff ex results.
        DifferentialExpressionSearchTaskImpl.log.info("Get information on conditions/analyses for " + i + " factorValues: " + watch.getTotalTimeMillis() + "ms");
    }
    return usedResultSets;
}
Also used : FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) Condition(ubic.gemma.core.tasks.visualization.DifferentialExpressionGenesConditionsValueObject.Condition) ExpressionExperimentDetailsValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentDetailsValueObject) ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject) StopWatch(org.springframework.util.StopWatch)

Example 84 with StopWatch

use of org.springframework.util.StopWatch in project Gemma by PavlidisLab.

the class DifferentialExpressionSearchTaskImpl method getDetailsForContrasts.

/**
 * Retrieve the details (contrasts) for results which meet the criterion. (PVALUE_CONTRAST_SELECT_THRESHOLD).
 * Requires a database hit.
 *
 * @param diffExResults results
 * @return map
 */
private Map<Long, ContrastsValueObject> getDetailsForContrasts(Collection<DiffExprGeneSearchResult> diffExResults) {
    StopWatch timer = new StopWatch();
    timer.start();
    List<Long> resultsWithContrasts = new ArrayList<>();
    for (DiffExprGeneSearchResult r : diffExResults) {
        if (r.getResultId() == null) {
            // it is a dummy result. It means there is no result for this gene in this resultset.
            continue;
        }
        // Here I am trying to avoid fetching them when there is no hope that the results will be interesting.
        if (r instanceof MissingResult || r instanceof NonRetainedResult || r.getCorrectedPvalue() > DifferentialExpressionSearchTaskImpl.PVALUE_CONTRAST_SELECT_THRESHOLD) {
            // Then it won't have contrasts; no need to fetch.
            continue;
        }
        resultsWithContrasts.add(r.getResultId());
    }
    Map<Long, ContrastsValueObject> detailedResults = new HashMap<>();
    if (!resultsWithContrasts.isEmpty()) {
        // uses a left join so it will have all the results.
        detailedResults = differentialExpressionResultService.loadContrastDetailsForResults(resultsWithContrasts);
    }
    timer.stop();
    if (timer.getTotalTimeMillis() > 1) {
        DifferentialExpressionSearchTaskImpl.log.info("Fetch contrasts for " + resultsWithContrasts.size() + " results: " + timer.getTotalTimeMillis() + "ms");
    }
    return detailedResults;
}
Also used : MissingResult(ubic.gemma.persistence.service.analysis.expression.diff.MissingResult) NonRetainedResult(ubic.gemma.persistence.service.analysis.expression.diff.NonRetainedResult) StopWatch(org.springframework.util.StopWatch)

Example 85 with StopWatch

use of org.springframework.util.StopWatch in project RxJavaInAction by fengzhizi715.

the class TasksController method sequential.

@GetMapping("/sequential")
public ApiResponseDTO sequential(@RequestParam("task") int[] taskDelaysInSeconds) {
    StopWatch watch = new StopWatch();
    watch.start();
    IntStream.of(taskDelaysInSeconds).mapToObj(MockTask::new).forEach(MockTask::execute);
    watch.stop();
    return new ApiResponseDTO(watch.getTotalTimeSeconds());
}
Also used : MockTask(com.safframework.study.task.core.impl.MockTask) ApiResponseDTO(com.safframework.study.task.web.dto.ApiResponseDTO) StopWatch(org.springframework.util.StopWatch)

Aggregations

StopWatch (org.springframework.util.StopWatch)112 Test (org.junit.Test)44 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)12 ArrayList (java.util.ArrayList)9 Test (org.junit.jupiter.api.Test)9 ITestBean (org.springframework.tests.sample.beans.ITestBean)9 TestBean (org.springframework.tests.sample.beans.TestBean)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 List (java.util.List)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)6 ApplicationMap (com.navercorp.pinpoint.web.applicationmap.ApplicationMap)5 Ignore (org.junit.Ignore)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)5 Range (com.navercorp.pinpoint.web.vo.Range)4 Dataset (org.apache.jena.query.Dataset)4