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