Example usage for org.springframework.util StopWatch getTotalTimeMillis

List of usage examples for org.springframework.util StopWatch getTotalTimeMillis

Introduction

In this page you can find the example usage for org.springframework.util StopWatch getTotalTimeMillis.

Prototype

public long getTotalTimeMillis() 

Source Link

Document

Get the total time in milliseconds for all tasks.

Usage

From source file:org.springframework.statemachine.recipes.support.RunnableAction.java

@Override
public final void execute(StateContext<String, String> context) {
    if (!shouldExecute(id, context)) {
        return;//  w w  w. j  av a  2  s .c o m
    }
    StopWatch watch = new StopWatch();
    String logId = (id == null ? "" : (" id=" + id));
    log.info("Executing runnable" + logId);
    if (log.isDebugEnabled()) {
        watch.start();
    }
    try {
        onPreExecute(id, context);
        runnable.run();
        onSuccess(id, context);
    } catch (Exception e) {
        onError(id, context, e);
    } finally {
        onPostExecute(id, context);
    }
    if (log.isDebugEnabled()) {
        watch.stop();
        log.debug("Runnable execution took " + watch.getTotalTimeMillis() + " ms" + logId);
    }
}

From source file:ubic.gemma.core.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * 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./*  w w  w .  jav a  2  s  .c  o  m*/
 *
 * @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) {

                // this is taken care of by the filterResultSets
                assert resultSet.getNumberOfDiffExpressedProbes() != null; // sanity check.
                assert resultSet.getExperimentalFactors().size() == 1; // interactions not okay

                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;
}

From source file:ubic.gemma.core.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * Retrieve the details (contrasts) for results which meet the criterion. (PVALUE_CONTRAST_SELECT_THRESHOLD).
 * Requires a database hit./*from  w ww  .  j  a  v a 2s. c  o  m*/
 *
 * @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;
        }

        /*
         * this check will not be needed if we only store the 'good' results, but we do store everything.
         */
        // 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;
}

From source file:ubic.gemma.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * 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.// w  w  w. jav a 2s.  c  o m
 * 
 * @param searchResult to be initialized
 * @return lsit of the resultSets that should be queried.
 */
private List<ExpressionAnalysisResultSet> addConditionsToSearchResultValueObject(
        DifferentialExpressionGenesConditionsValueObject searchResult) {

    StopWatch watch = new StopWatch("addConditionsToSearchResultValueObject");
    watch.start("Add conditions to search result value object");
    List<ExpressionAnalysisResultSet> usedResultSets = new LinkedList<ExpressionAnalysisResultSet>();

    int experimentGroupIndex = 0;
    int i = 0;
    for (Collection<ExpressionExperiment> experimentGroup : experimentGroups) {

        log.info("Loading " + experimentGroupNames.get(experimentGroupIndex) + " experiments...");

        // database hit: important that this be fast.
        Map<BioAssaySet, Collection<DifferentialExpressionAnalysis>> analyses = differentialExpressionAnalysisService
                .getAnalyses(experimentGroup);

        experiment: for (BioAssaySet bas : analyses.keySet()) {

            if (!(bas instanceof ExpressionExperiment)) {
                log.warn("Subsets not supported yet (" + bas + "), skipping");
                continue;
            }

            ExpressionExperiment experiment = (ExpressionExperiment) bas;

            Collection<DifferentialExpressionAnalysis> analysesForExperiment = filterAnalyses(
                    analyses.get(experiment));

            if (analysesForExperiment.isEmpty()) {
                continue;
            }

            for (DifferentialExpressionAnalysis analysis : analysesForExperiment) {

                List<ExpressionAnalysisResultSet> resultSets = filterResultSets(analysis.getResultSets());
                usedResultSets.addAll(resultSets);

                if (resultSets.isEmpty()) {
                    log.info("No resultSets usable for " + experiment.getShortName());
                }

                for (ExpressionAnalysisResultSet resultSet : resultSets) {

                    // this is taken care of by the filterResultSets
                    assert resultSet.getHitListSizes() != null;
                    assert resultSet.getExperimentalFactors().size() == 1;

                    ExperimentalFactor factor = resultSet.getExperimentalFactors().iterator().next();
                    Collection<FactorValue> factorValues = filterFactorValues(factor.getFactorValues(),
                            resultSet.getBaselineGroup().getId());

                    for (FactorValue factorValue : factorValues) {

                        Condition condition = searchResult.new Condition(experiment, analysis, resultSet,
                                factorValue);

                        condition.setExperimentGroupName(experimentGroupNames.get(experimentGroupIndex));
                        condition.setExperimentGroupIndex(experimentGroupIndex);

                        /*
                         * SANITY CHECKS these fields should be filled in. If not, we are going to skip the results.
                         */
                        if (condition.getNumberDiffExpressedProbes() == -1) {
                            log.warn(bas + ": Error: No hit list sizes for resultSet with ID="
                                    + resultSet.getId());
                            continue;
                        }
                        if (condition.getNumberOfProbesOnArray() == null
                                || condition.getNumberDiffExpressedProbes() == null) {
                            log.error(bas
                                    + ": Error: Null counts for # diff ex probe or # probes on array, Skipping");
                            continue experiment;
                        } else if (condition.getNumberOfProbesOnArray() < condition
                                .getNumberDiffExpressedProbes()) {
                            log.error(bas
                                    + ": Error: More diff expressed probes than probes on array. Skipping.");
                            continue experiment;
                        }

                        searchResult.addCondition(condition);

                        i++;
                    }
                }
            }
        }
        experimentGroupIndex++;
    }

    watch.stop();
    if (watch.getTotalTimeMillis() > 100) {
        // This does not include getting the actual diff ex results.
        log.info("Get information on conditions/analyses for " + i + " factorValues: "
                + watch.getTotalTimeMillis() + "ms");
    }

    return usedResultSets;
}

From source file:ubic.gemma.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * Staging for getting the diff ex results.
 * /*from   w  w  w . ja v  a  2 s .com*/
 * @param resultSets to be searched
 * @param geneIds to be searched
 * @param searchResult holds the results
 */
private void fetchDifferentialExpressionResults(List<ExpressionAnalysisResultSet> resultSets,
        List<Long> geneIds, DifferentialExpressionGenesConditionsValueObject searchResult) {

    Map<ExpressionAnalysisResultSet, Collection<Long>> resultSetIdsToArrayDesignsUsed = new HashMap<ExpressionAnalysisResultSet, Collection<Long>>();

    StopWatch timer = new StopWatch();
    timer.start();
    // DATABASE CALL HERE, but should be quite fast.
    for (ExpressionAnalysisResultSet rs : resultSets) {
        resultSetIdsToArrayDesignsUsed.put(rs,
                EntityUtils.getIds(eeService.getArrayDesignsUsed(rs.getAnalysis().getExperimentAnalyzed())));
    }
    timer.stop();
    if (timer.getTotalTimeMillis() > 100) {
        log.info("Fetch array designs used: " + timer.getTotalTimeMillis() + "ms");
    }

    fetchDifferentialExpressionResults(resultSetIdsToArrayDesignsUsed, geneIds, searchResult);

}

From source file:ubic.gemma.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * Retrieve the details (contrasts) for results which meet the criterion. (PVALUE_CONTRAST_SELECT_THRESHOLD)
 * /*from w ww .  j  ava  2 s. c  o  m*/
 * @param geneToProbeResult
 * @return
 */
private Map<Long, ContrastsValueObject> getDetailsForContrasts(
        Collection<DiffExprGeneSearchResult> diffExResults) {

    StopWatch timer = new StopWatch();
    timer.start();
    List<Long> resultsWithContrasts = new ArrayList<Long>();

    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;
        }

        /*
         * this check will not be needed if we only store the 'good' results?
         */
        // 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() > 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<Long, ContrastsValueObject>();
    if (!resultsWithContrasts.isEmpty()) {
        // uses a left join so it will have all the results.
        detailedResults = differentialExpressionResultService
                .loadContrastDetailsForResults(resultsWithContrasts);
    }

    timer.stop();
    if (timer.getTotalTimeMillis() > 1) {
        log.info("Fetch contrasts for " + resultsWithContrasts.size() + " results: "
                + timer.getTotalTimeMillis() + "ms");
    }
    return detailedResults;
}