Search in sources :

Example 1 with PerformanceStats

use of org.eclipse.core.runtime.PerformanceStats in project che by eclipse.

the class ProcessorBasedRefactoring method createChange.

/**
	 * {@inheritDoc}
	 */
public Change createChange(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    //$NON-NLS-1$
    pm.beginTask("", fParticipants.size() + 3);
    pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_create_change);
    Change processorChange = getProcessor().createChange(new SubProgressMonitor(pm, 1));
    if (pm.isCanceled())
        throw new OperationCanceledException();
    fTextChangeMap = new HashMap();
    addToTextChangeMap(processorChange);
    List /*<Change>*/
    changes = new ArrayList();
    List /*<Change>*/
    preChanges = new ArrayList();
    Map /*<Change, RefactoringParticipant>*/
    participantMap = new HashMap();
    for (Iterator iter = fParticipants.iterator(); iter.hasNext(); ) {
        final RefactoringParticipant participant = (RefactoringParticipant) iter.next();
        try {
            //$NON-NLS-1$
            final PerformanceStats stats = PerformanceStats.getStats(PERF_CREATE_CHANGES, getName() + ", " + participant.getName());
            stats.startRun();
            Change preChange = participant.createPreChange(new SubProgressMonitor(pm, 1));
            Change change = participant.createChange(new SubProgressMonitor(pm, 1));
            stats.endRun();
            if (preChange != null) {
                if (fPreChangeParticipants == null)
                    fPreChangeParticipants = new ArrayList();
                fPreChangeParticipants.add(participant);
                preChanges.add(preChange);
                participantMap.put(preChange, participant);
                addToTextChangeMap(preChange);
            }
            if (change != null) {
                changes.add(change);
                participantMap.put(change, participant);
                addToTextChangeMap(change);
            }
        } catch (CoreException e) {
            disableParticipant(participant, e);
            throw e;
        } catch (OperationCanceledException e) {
            throw e;
        } catch (RuntimeException e) {
            disableParticipant(participant, e);
            throw e;
        }
        if (pm.isCanceled())
            throw new OperationCanceledException();
    }
    fTextChangeMap = null;
    Change postChange = getProcessor().postCreateChange((Change[]) changes.toArray(new Change[changes.size()]), new SubProgressMonitor(pm, 1));
    ProcessorChange result = new ProcessorChange(getName());
    result.addAll((Change[]) preChanges.toArray(new Change[preChanges.size()]));
    result.add(processorChange);
    result.addAll((Change[]) changes.toArray(new Change[changes.size()]));
    result.setParticipantMap(participantMap);
    result.setPreChangeParticipants(fPreChangeParticipants);
    if (postChange != null)
        result.add(postChange);
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Change(org.eclipse.ltk.core.refactoring.Change) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) PerformanceStats(org.eclipse.core.runtime.PerformanceStats) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with PerformanceStats

use of org.eclipse.core.runtime.PerformanceStats in project che by eclipse.

the class ProposalSorterHandle method startMeter.

private PerformanceStats startMeter(String context, AbstractProposalSorter sorter) {
    final PerformanceStats stats;
    if (MEASURE_PERFORMANCE) {
        stats = PerformanceStats.getStats(PERFORMANCE_EVENT, sorter);
        stats.startRun(context);
    } else {
        stats = null;
    }
    return stats;
}
Also used : PerformanceStats(org.eclipse.core.runtime.PerformanceStats)

Example 3 with PerformanceStats

use of org.eclipse.core.runtime.PerformanceStats in project che by eclipse.

the class ProposalSorterHandle method sortProposals.

/**
	 * Safely computes completion proposals through the described extension. If the extension throws
	 * an exception or otherwise does not adhere to the contract described in
	 * {@link AbstractProposalSorter}, the list is returned as is.
	 *
	 * @param context the invocation context passed on to the extension
	 * @param proposals the list of computed completion proposals to be sorted (element type:
	 *        {@link ICompletionProposal}), must be writable
	 */
public void sortProposals(ContentAssistInvocationContext context, List<ICompletionProposal> proposals) {
    IStatus status;
    try {
        AbstractProposalSorter sorter = getSorter();
        PerformanceStats stats = startMeter(SORT, sorter);
        sorter.beginSorting(context);
        Collections.sort(proposals, sorter);
        sorter.endSorting();
        status = stopMeter(stats, SORT);
        // valid result
        if (status == null)
            return;
        status = createAPIViolationStatus(SORT);
    } catch (InvalidRegistryObjectException x) {
        status = createExceptionStatus(x);
    } catch (CoreException x) {
        status = createExceptionStatus(x);
    } catch (RuntimeException x) {
        status = createExceptionStatus(x);
    }
    JavaPlugin.log(status);
    return;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) AbstractProposalSorter(org.eclipse.jdt.ui.text.java.AbstractProposalSorter) PerformanceStats(org.eclipse.core.runtime.PerformanceStats) CoreException(org.eclipse.core.runtime.CoreException) InvalidRegistryObjectException(org.eclipse.core.runtime.InvalidRegistryObjectException)

Example 4 with PerformanceStats

use of org.eclipse.core.runtime.PerformanceStats in project che by eclipse.

the class DeltaProcessor method notifyListeners.

private void notifyListeners(IJavaElementDelta deltaToNotify, int eventType, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) {
    final ElementChangedEvent extraEvent = new ElementChangedEvent(deltaToNotify, eventType);
    for (int i = 0; i < listenerCount; i++) {
        if ((listenerMask[i] & eventType) != 0) {
            final IElementChangedListener listener = listeners[i];
            long start = -1;
            if (VERBOSE) {
                //$NON-NLS-1$//$NON-NLS-2$
                System.out.print("Listener #" + (i + 1) + "=" + listener.toString());
                start = System.currentTimeMillis();
            }
            // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief
            SafeRunner.run(new ISafeRunnable() {

                public void handleException(Throwable exception) {
                    //$NON-NLS-1$
                    Util.log(exception, "Exception occurred in listener of Java element change notification");
                }

                public void run() throws Exception {
                    PerformanceStats stats = null;
                    if (PERF) {
                    //							stats = PerformanceStats.getStats(JavaModelManager.DELTA_LISTENER_PERF, listener);
                    //							stats.startRun();
                    }
                    listener.elementChanged(extraEvent);
                    if (PERF) {
                        stats.endRun();
                    }
                }
            });
            if (VERBOSE) {
                //$NON-NLS-1$ //$NON-NLS-2$
                System.out.println(" -> " + (System.currentTimeMillis() - start) + "ms");
            }
        }
    }
}
Also used : PerformanceStats(org.eclipse.core.runtime.PerformanceStats) IElementChangedListener(org.eclipse.jdt.core.IElementChangedListener) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) ElementChangedEvent(org.eclipse.jdt.core.ElementChangedEvent)

Example 5 with PerformanceStats

use of org.eclipse.core.runtime.PerformanceStats in project che by eclipse.

the class JavaSearchQuery method run.

public IStatus run(IProgressMonitor monitor) {
    final JavaSearchResult textResult = (JavaSearchResult) getSearchResult();
    textResult.removeAll();
    // Don't need to pass in working copies in 3.0 here
    SearchEngine engine = new SearchEngine();
    try {
        int totalTicks = 1000;
        IProject[] projects = JavaSearchScopeFactory.getInstance().getProjects(fPatternData.getScope());
        final SearchParticipantRecord[] participantDescriptors = SearchParticipantsExtensionPoint.getInstance().getSearchParticipants(projects);
        final int[] ticks = new int[participantDescriptors.length];
        for (int i = 0; i < participantDescriptors.length; i++) {
            final int iPrime = i;
            ISafeRunnable runnable = new ISafeRunnable() {

                public void handleException(Throwable exception) {
                    ticks[iPrime] = 0;
                    String message = SearchMessages.JavaSearchQuery_error_participant_estimate;
                    JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, exception));
                }

                public void run() throws Exception {
                    ticks[iPrime] = participantDescriptors[iPrime].getParticipant().estimateTicks(fPatternData);
                }
            };
            SafeRunner.run(runnable);
            totalTicks += ticks[i];
        }
        SearchPattern pattern;
        String stringPattern;
        if (fPatternData instanceof ElementQuerySpecification) {
            IJavaElement element = ((ElementQuerySpecification) fPatternData).getElement();
            stringPattern = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
            if (!element.exists()) {
                return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null);
            }
            pattern = SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
        } else {
            PatternQuerySpecification patternSpec = (PatternQuerySpecification) fPatternData;
            stringPattern = patternSpec.getPattern();
            int matchMode = getMatchMode(stringPattern) | SearchPattern.R_ERASURE_MATCH;
            if (patternSpec.isCaseSensitive())
                matchMode |= SearchPattern.R_CASE_SENSITIVE;
            pattern = SearchPattern.createPattern(patternSpec.getPattern(), patternSpec.getSearchFor(), patternSpec.getLimitTo(), matchMode);
        }
        if (pattern == null) {
            return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_unsupported_pattern, stringPattern), null);
        }
        monitor.beginTask(Messages.format(SearchMessages.JavaSearchQuery_task_label, stringPattern), totalTicks);
        IProgressMonitor mainSearchPM = new SubProgressMonitor(monitor, 1000);
        boolean ignorePotentials = NewSearchUI.arePotentialMatchesIgnored();
        NewSearchResultCollector collector = new NewSearchResultCollector(textResult, ignorePotentials);
        engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, fPatternData.getScope(), collector, mainSearchPM);
        for (int i = 0; i < participantDescriptors.length; i++) {
            final ISearchRequestor requestor = new SearchRequestor(participantDescriptors[i].getParticipant(), textResult);
            final IProgressMonitor participantPM = new SubProgressMonitor(monitor, ticks[i]);
            final int iPrime = i;
            ISafeRunnable runnable = new ISafeRunnable() {

                public void handleException(Throwable exception) {
                    participantDescriptors[iPrime].getDescriptor().disable();
                    String message = SearchMessages.JavaSearchQuery_error_participant_search;
                    JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, exception));
                }

                public void run() throws Exception {
                    final IQueryParticipant participant = participantDescriptors[iPrime].getParticipant();
                    final PerformanceStats stats = PerformanceStats.getStats(PERF_SEARCH_PARTICIPANT, participant);
                    stats.startRun();
                    participant.search(requestor, fPatternData, participantPM);
                    stats.endRun();
                }
            };
            SafeRunner.run(runnable);
        }
    } catch (CoreException e) {
        return e.getStatus();
    }
    String message = Messages.format(SearchMessages.JavaSearchQuery_status_ok_message, String.valueOf(textResult.getMatchCount()));
    return new Status(IStatus.OK, JavaPlugin.getPluginId(), 0, message, null);
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IJavaElement(org.eclipse.jdt.core.IJavaElement) IQueryParticipant(org.eclipse.jdt.ui.search.IQueryParticipant) ElementQuerySpecification(org.eclipse.jdt.ui.search.ElementQuerySpecification) PatternQuerySpecification(org.eclipse.jdt.ui.search.PatternQuerySpecification) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ISearchRequestor(org.eclipse.jdt.ui.search.ISearchRequestor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISearchRequestor(org.eclipse.jdt.ui.search.ISearchRequestor) PerformanceStats(org.eclipse.core.runtime.PerformanceStats) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

PerformanceStats (org.eclipse.core.runtime.PerformanceStats)6 CoreException (org.eclipse.core.runtime.CoreException)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)2 IStatus (org.eclipse.core.runtime.IStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 IProject (org.eclipse.core.resources.IProject)1 InvalidRegistryObjectException (org.eclipse.core.runtime.InvalidRegistryObjectException)1 Status (org.eclipse.core.runtime.Status)1 ElementChangedEvent (org.eclipse.jdt.core.ElementChangedEvent)1 IElementChangedListener (org.eclipse.jdt.core.IElementChangedListener)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1