Search in sources :

Example 1 with ITmfCallsite

use of org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite in project tracecompass by tracecompass.

the class TmfCallsiteTest method testEqualsSymmetry.

@Test
public void testEqualsSymmetry() {
    final ITmfCallsite callsite1 = new TmfCallsite(fCallsite1);
    final ITmfCallsite callsite2 = new TmfCallsite(fCallsite2);
    assertTrue("equals", callsite1.equals(fCallsite1));
    assertTrue("equals", fCallsite1.equals(callsite1));
    assertTrue("equals", callsite2.equals(fCallsite2));
    assertTrue("equals", fCallsite2.equals(callsite2));
}
Also used : TmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite) ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) Test(org.junit.Test)

Example 2 with ITmfCallsite

use of org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite in project tracecompass by tracecompass.

the class OpenSourceCodeAction method create.

/**
 * Builder
 *
 * @param actionText
 *            "open" message recommended to be "lookup" if the location can be
 *            erroneous and open if it's accurate.
 * @param sourceLookup
 *            the source code to lookup
 * @param shell
 *            the parent shell for source file dialog
 * @return an contribution item to open a callsite or null if invalid
 */
public static IContributionItem create(String actionText, ITmfSourceLookup sourceLookup, Shell shell) {
    List<ITmfCallsite> cs = sourceLookup.getCallsites();
    if (cs == null) {
        return null;
    }
    List<ITmfCallsite> callsites = cs.stream().filter(callstack -> callstack.getLineNo() != null).collect(Collectors.toList());
    if (callsites.isEmpty()) {
        /* Not enough information to provide a full callsite */
        return null;
    }
    if (callsites.size() == 1) {
        return new ActionContributionItem(new OpenSourceCodeAction(actionText, callsites.get(0), shell));
    }
    MenuManager mgr = new MenuManager(actionText);
    for (ITmfCallsite callsite : callsites) {
        mgr.add(new OpenSourceCodeAction(callsite.toString(), callsite, shell));
    }
    return mgr;
}
Also used : ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IDE(org.eclipse.ui.ide.IDE) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) CoreException(org.eclipse.core.runtime.CoreException) ITmfSourceLookup(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup) ArrayList(java.util.ArrayList) IDocument(org.eclipse.jface.text.IDocument) IPath(org.eclipse.core.runtime.IPath) IFile(org.eclipse.core.resources.IFile) BadLocationException(org.eclipse.jface.text.BadLocationException) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TraceUtils(org.eclipse.tracecompass.tmf.ui.project.model.TraceUtils) EFS(org.eclipse.core.filesystem.EFS) IEditorPart(org.eclipse.ui.IEditorPart) IFileStore(org.eclipse.core.filesystem.IFileStore) IMarker(org.eclipse.core.resources.IMarker) IRegion(org.eclipse.jface.text.IRegion) Shell(org.eclipse.swt.widgets.Shell) PlatformUI(org.eclipse.ui.PlatformUI) Messages(org.eclipse.tracecompass.internal.tmf.ui.Messages) MenuManager(org.eclipse.jface.action.MenuManager) Action(org.eclipse.jface.action.Action) ListDialog(org.eclipse.ui.dialogs.ListDialog) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) List(java.util.List) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IResource(org.eclipse.core.resources.IResource) Path(org.eclipse.core.runtime.Path) IContributionItem(org.eclipse.jface.action.IContributionItem) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) MenuManager(org.eclipse.jface.action.MenuManager)

Example 3 with ITmfCallsite

use of org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite in project tracecompass by tracecompass.

the class OpenSourceCodeAction method run.

@Override
public void run() {
    ITmfCallsite cs = fCallsite;
    if (cs == null) {
        return;
    }
    String fileName = cs.getFileName();
    Long lineNo = cs.getLineNo();
    if (lineNo == null) {
        /* Not enough information to provide a full callsite */
        return;
    }
    // $NON-NLS-1$
    final String trimmedPath = fileName.replaceAll("\\.\\./", EMPTY_STRING);
    File fileToOpen = new File(trimmedPath);
    try {
        if (fileToOpen.exists() && fileToOpen.isFile()) {
            /*
                 * The path points to a "real" file, attempt to open that
                 */
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IEditorPart editor = IDE.openEditorOnFileStore(page, fileStore);
            if (editor instanceof ITextEditor) {
                /*
                     * Calculate the "document offset" corresponding to the line
                     * number, then seek there.
                     */
                ITextEditor textEditor = (ITextEditor) editor;
                int lineNumber = lineNo.intValue();
                IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
                IRegion region = document.getLineInformation(lineNumber - 1);
                if (region != null) {
                    textEditor.selectAndReveal(region.getOffset(), region.getLength());
                }
            }
        } else {
            /*
                 * The file was not found on disk, attempt to find it in the
                 * workspace instead.
                 */
            IMarker marker = null;
            final ArrayList<IFile> files = new ArrayList<>();
            IPath p = new Path(trimmedPath);
            ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() {

                @Override
                public boolean visit(IResource resource) throws CoreException {
                    if (resource instanceof IFile && resource.getFullPath().toString().endsWith(p.lastSegment())) {
                        files.add((IFile) resource);
                    }
                    return true;
                }
            });
            IFile file = null;
            if (files.size() > 1) {
                ListDialog dialog = new ListDialog(fShell);
                dialog.setContentProvider(ArrayContentProvider.getInstance());
                dialog.setLabelProvider(new LabelProvider() {

                    @Override
                    public String getText(Object element) {
                        return ((IFile) element).getFullPath().toString();
                    }
                });
                dialog.setInput(files);
                dialog.setTitle(Messages.TmfSourceLookup_OpenSourceCodeSelectFileDialogTitle);
                dialog.setMessage(Messages.TmfSourceLookup_OpenSourceCodeSelectFileDialogTitle + '\n' + cs.toString());
                dialog.open();
                Object[] result = dialog.getResult();
                if (result != null && result.length > 0) {
                    file = (IFile) result[0];
                }
            } else if (files.size() == 1) {
                file = files.get(0);
            }
            if (file != null) {
                marker = file.createMarker(IMarker.MARKER);
                marker.setAttribute(IMarker.LINE_NUMBER, lineNo.intValue());
                IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker);
                marker.delete();
            } else if (files.isEmpty()) {
                TraceUtils.displayWarningMsg(new FileNotFoundException('\'' + cs.toString() + '\'' + '\n' + Messages.TmfSourceLookup_OpenSourceCodeNotFound));
            }
        }
    } catch (BadLocationException | CoreException e) {
        TraceUtils.displayErrorMsg(e);
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IRegion(org.eclipse.jface.text.IRegion) ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IPath(org.eclipse.core.runtime.IPath) IEditorPart(org.eclipse.ui.IEditorPart) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IMarker(org.eclipse.core.resources.IMarker) IFile(org.eclipse.core.resources.IFile) File(java.io.File) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IDocument(org.eclipse.jface.text.IDocument) IResource(org.eclipse.core.resources.IResource) ListDialog(org.eclipse.ui.dialogs.ListDialog) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with ITmfCallsite

use of org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite in project tracecompass by tracecompass.

the class CallStackDataProvider method fetchTooltip.

@Override
@NonNull
public TmfModelResponse<@NonNull Map<@NonNull String, @NonNull String>> fetchTooltip(Map<String, Object> parameters, @Nullable IProgressMonitor monitor) {
    CallStackAnalysis analysis = getAnalysisModule();
    Map<String, String> tooltips = new HashMap<>();
    List<@NonNull Long> selected = DataProviderParameterUtils.extractSelectedItems(parameters);
    List<@NonNull Long> times = DataProviderParameterUtils.extractTimeRequested(parameters);
    // This data provider doesn't have any annotations or arrows
    Object element = parameters.get(DataProviderParameterUtils.REQUESTED_ELEMENT_KEY);
    if (element instanceof IAnnotation || element instanceof ITimeGraphArrow) {
        return new TmfModelResponse<>(tooltips, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    if (selected != null && times != null) {
        Map<@NonNull Long, @NonNull Integer> md = getSelectedEntries(selected);
        ITmfTrace trace = getTrace();
        for (Long time : times) {
            for (Entry<@NonNull Long, @NonNull Integer> entry : md.entrySet()) {
                Long result = analysis.resolveDeviceId(entry.getValue(), time);
                if (result != null) {
                    String deviceId = String.valueOf(result);
                    String deviceType = analysis.resolveDeviceType(entry.getValue(), time);
                    tooltips.put(deviceType, deviceId);
                    Iterable<@NonNull CallsiteAnalysis> csas = TmfTraceUtils.getAnalysisModulesOfClass(trace, CallsiteAnalysis.class);
                    for (CallsiteAnalysis csa : csas) {
                        List<@NonNull ITmfCallsite> res = csa.getCallsites(String.valueOf(trace.getUUID()), deviceType, deviceId, time);
                        if (!res.isEmpty()) {
                            tooltips.put(TmfStrings.source(), String.valueOf(res.get(0)));
                        }
                    }
                    return new TmfModelResponse<>(tooltips, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
                }
                ITmfStateSystem stateSystem = analysis.getStateSystem();
                if (stateSystem != null) {
                    try {
                        Collection<@NonNull ISymbolProvider> symbolProviders = SymbolProviderManager.getInstance().getSymbolProviders(trace);
                        ITmfStateInterval interval = stateSystem.querySingleState(Objects.requireNonNull(time), Objects.requireNonNull(entry.getValue()));
                        Object value = interval.getValue();
                        if (value instanceof Number) {
                            long longValue = ((Number) value).longValue();
                            for (ISymbolProvider provider : symbolProviders) {
                                TmfResolvedSymbol symbol = provider.getSymbol(longValue);
                                if (symbol != null) {
                                    tooltips.put(Messages.CallStackDataProvider_toolTipState, symbol.getSymbolName());
                                    tooltips.put(Messages.CallStackDataProvider_toolTipAddress, String.format(ADDRESS_FORMAT, symbol.getBaseAddress()));
                                    break;
                                }
                            }
                            tooltips.computeIfAbsent(Messages.CallStackDataProvider_toolTipState, unused -> String.format(ADDRESS_FORMAT, longValue));
                        } else if (value != null) {
                            tooltips.put(Messages.CallStackDataProvider_toolTipState, interval.getValueString());
                        }
                    } catch (StateSystemDisposedException e) {
                        // $NON-NLS-1$
                        Activator.getInstance().logError("State System Disposed", e);
                    }
                }
            }
        }
    }
    return new TmfModelResponse<>(tooltips, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : IAnnotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IAnnotation) HashMap(java.util.HashMap) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) CallsiteAnalysis(org.eclipse.tracecompass.internal.tmf.core.analysis.callsite.CallsiteAnalysis) ISymbolProvider(org.eclipse.tracecompass.tmf.core.symbols.ISymbolProvider) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) ITimeGraphArrow(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow) CallStackAnalysis(org.eclipse.tracecompass.analysis.profiling.core.callstack.CallStackAnalysis) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfResolvedSymbol(org.eclipse.tracecompass.tmf.core.symbols.TmfResolvedSymbol) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 5 with ITmfCallsite

use of org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite in project tracecompass by tracecompass.

the class CtfTmfEvent method getCallsite.

// ------------------------------------------------------------------------
// ITmfSourceLookup
// ------------------------------------------------------------------------
/**
 * Get the call site for this event.
 *
 * @return the call site information, or null if there is none
 * @since 3.0
 */
@Override
@Nullable
public ITmfCallsite getCallsite() {
    ITmfCallsite callsite = null;
    ITmfEventField ipField = getContent().getField(CtfConstants.CONTEXT_FIELD_PREFIX + CtfConstants.IP_KEY);
    if (ipField != null && ipField.getValue() instanceof Long) {
        long ip = (Long) ipField.getValue();
        callsite = getTrace().getCallsite(fEventName, ip);
    }
    if (callsite == null) {
        callsite = getTrace().getCallsite(fEventName);
    }
    return callsite;
}
Also used : ITmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

ITmfCallsite (org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite)11 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)3 TmfCallsite (org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite)3 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IFile (org.eclipse.core.resources.IFile)2 IMarker (org.eclipse.core.resources.IMarker)2 IResource (org.eclipse.core.resources.IResource)2 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IDocument (org.eclipse.jface.text.IDocument)2