use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer in project tracecompass by tracecompass.
the class AbstractTimeGraphView method createPartControl.
// ------------------------------------------------------------------------
// ViewPart
// ------------------------------------------------------------------------
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
TimeGraphViewer timeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);
fTimeGraphViewer = timeGraphViewer;
if (fLabelProvider != null) {
timeGraphViewer.setTimeGraphLabelProvider(fLabelProvider);
}
if (fLegendProvider != null) {
timeGraphViewer.setLegendProvider(fLegendProvider);
}
if (fColumns != null) {
timeGraphViewer.setColumns(fColumns);
if (fColumnComparators != null) {
createColumnSelectionListener(timeGraphViewer.getTree());
}
}
timeGraphViewer.setTimeGraphContentProvider(fTimeGraphContentProvider);
timeGraphViewer.setFilterContentProvider(fFilterContentProvider != null ? fFilterContentProvider : fTimeGraphContentProvider);
timeGraphViewer.setFilterLabelProvider(fFilterLabelProvider);
timeGraphViewer.setFilterColumns(fFilterColumns);
timeGraphViewer.addSelectionListener(fMetadataSelectionListener);
ITimeGraphPresentationProvider presentationProvider = getPresentationProvider();
timeGraphViewer.setTimeGraphProvider(presentationProvider);
presentationProvider.addColorListener(stateItems -> TimeGraphStyleUtil.loadValues(getPresentationProvider()));
presentationProvider.refresh();
timeGraphViewer.setAutoExpandLevel(fAutoExpandLevel);
timeGraphViewer.setWeights(fWeight);
TimeGraphControl timeGraphControl = timeGraphViewer.getTimeGraphControl();
Action timeEventFilterAction = new Action() {
@Override
public void run() {
int xCoord = timeGraphControl.toControl(timeGraphControl.getDisplay().getCursorLocation()).x;
if ((timeGraphViewer.getNameSpace() < xCoord) && (xCoord < timeGraphControl.getSize().x)) {
if (fTimeEventFilterDialog != null) {
fTimeEventFilterDialog.close();
fTimeEventFilterDialog = null;
}
fTimeEventFilterDialog = new TimeEventFilterDialog(timeGraphControl.getShell(), AbstractTimeGraphView.this, getTimeGraphViewer().getTimeGraphControl());
fTimeEventFilterDialog.open();
}
}
};
fTimeEventFilterAction = timeEventFilterAction;
timeGraphViewer.addRangeListener(event -> {
final long startTime = event.getStartTime();
final long endTime = event.getEndTime();
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime));
broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView.this, range, fTrace));
startZoomThread(startTime, endTime);
});
timeGraphViewer.addTimeListener(event -> {
ITmfTimestamp startTime = TmfTimestamp.fromNanos(event.getBeginTime());
ITmfTimestamp endTime = TmfTimestamp.fromNanos(event.getEndTime());
broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView.this, startTime, endTime, fTrace));
});
timeGraphViewer.addBookmarkListener(new ITimeGraphBookmarkListener() {
@Override
public void bookmarkAdded(final TimeGraphBookmarkEvent event) {
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
IMarkerEvent bookmark = event.getBookmark();
IFile editorFile = fEditorFile;
if (editorFile == null) {
return;
}
IMarker marker = editorFile.createMarker(IMarker.BOOKMARK);
marker.setAttribute(IMarker.MESSAGE, bookmark.getLabel());
marker.setAttribute(ITmfMarker.MARKER_TIME, Long.toString(bookmark.getTime()));
if (bookmark.getDuration() > 0) {
marker.setAttribute(ITmfMarker.MARKER_DURATION, Long.toString(bookmark.getDuration()));
marker.setAttribute(IMarker.LOCATION, NLS.bind(org.eclipse.tracecompass.internal.tmf.ui.Messages.TmfMarker_LocationTimeRange, TmfTimestamp.fromNanos(bookmark.getTime()), TmfTimestamp.fromNanos(bookmark.getTime() + bookmark.getDuration())));
} else {
marker.setAttribute(IMarker.LOCATION, NLS.bind(org.eclipse.tracecompass.internal.tmf.ui.Messages.TmfMarker_LocationTime, TmfTimestamp.fromNanos(bookmark.getTime())));
}
marker.setAttribute(ITmfMarker.MARKER_COLOR, bookmark.getColor().toString());
}
}, null);
} catch (CoreException e) {
Activator.getDefault().logError(e.getMessage());
}
}
@Override
public void bookmarkRemoved(TimeGraphBookmarkEvent event) {
try {
IMarkerEvent bookmark = event.getBookmark();
IFile editorFile = fEditorFile;
if (editorFile == null) {
return;
}
IMarker[] markers = editorFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO);
for (IMarker marker : markers) {
if (bookmark.getLabel().equals(marker.getAttribute(IMarker.MESSAGE)) && Long.toString(bookmark.getTime()).equals(marker.getAttribute(ITmfMarker.MARKER_TIME, (String) null)) && Long.toString(bookmark.getDuration()).equals(marker.getAttribute(ITmfMarker.MARKER_DURATION, Long.toString(0))) && bookmark.getColor().toString().equals(marker.getAttribute(ITmfMarker.MARKER_COLOR))) {
marker.delete();
break;
}
}
} catch (CoreException e) {
Activator.getDefault().logError(e.getMessage());
}
}
});
fTimeGraphViewer.addMarkerListener(() -> restartZoomThread());
timeGraphControl.addPaintListener(new PaintListener() {
/**
* This paint control allows the virtual time graph refresh to occur on paint
* events instead of just scrolling the time axis or zooming. To avoid
* refreshing the model on every paint event, we use a TmfUiRefreshHandler to
* coalesce requests and only execute the last one, we also check if the entries
* have changed to avoid useless model refresh.
*
* @param e
* paint event on the visible area
*/
@Override
public void paintControl(PaintEvent e) {
TmfUiRefreshHandler.getInstance().queueUpdate(this, () -> {
if (timeGraphControl.isDisposed()) {
return;
}
int timeSpace = getTimeGraphViewer().getTimeSpace();
Set<@NonNull TimeGraphEntry> newSet = getVisibleItems(DEFAULT_BUFFER_SIZE);
if (fPrevTimeSpace != timeSpace || !fVisibleEntries.equals(newSet)) {
/*
* Start a zoom thread if the set of visible entries has changed. We do not use
* lists as the order is not important. We cannot use the start index / size of
* the visible entries as we can collapse / reorder events.
*/
fVisibleEntries = newSet;
fPrevTimeSpace = timeSpace;
startZoomThread(getTimeGraphViewer().getTime0(), getTimeGraphViewer().getTime1());
}
});
}
});
IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager();
timeGraphControl.setStatusLineManager(statusLineManager);
// View Action Handling
makeActions();
contributeToActionBars();
ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
if (trace != null) {
traceSelected(new TmfTraceSelectedSignal(this, trace));
}
// make selection available to other views
IWorkbenchPartSite site = getSite();
site.setSelectionProvider(timeGraphViewer.getSelectionProvider());
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
createContextMenu();
fPartListener = new TimeGraphPartListener();
site.getPage().addPartListener(fPartListener);
fPartListener2 = new TimeGraphPartListener2();
site.getPage().addPartListener(fPartListener2);
fOriginalTabLabel = getPartName();
fContextService = site.getWorkbenchWindow().getService(IContextService.class);
if (timeGraphControl.isInFocus()) {
activateContextService();
}
timeGraphControl.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
deactivateContextService();
}
@Override
public void focusGained(FocusEvent e) {
activateContextService();
}
});
updateTimeFormat();
}
use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer in project tracecompass by tracecompass.
the class FlameChartView method getPreviousEventAction.
/**
* Get the previous event action.
*
* @return The Action object
*/
private Action getPreviousEventAction() {
Action prevAction = fPrevEventAction;
if (prevAction == null) {
Action superPrevAction = getTimeGraphViewer().getPreviousEventAction();
prevAction = new Action() {
@Override
public void run() {
TimeGraphViewer viewer = getTimeGraphViewer();
ITimeGraphEntry entry = viewer.getSelection();
if (entry instanceof TimeGraphEntry) {
TimeGraphEntry callStackEntry = (TimeGraphEntry) entry;
ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider = getProvider(callStackEntry);
long selectionBegin = viewer.getSelectionBegin();
SelectionTimeQueryFilter filter = new SelectionTimeQueryFilter(Lists.newArrayList(Long.MIN_VALUE, selectionBegin), Collections.singleton(callStackEntry.getEntryModel().getId()));
TmfModelResponse<@NonNull TimeGraphModel> response = provider.fetchRowModel(FetchParametersUtils.selectionTimeQueryToMap(filter), null);
TimeGraphModel model = response.getModel();
if (model == null || model.getRows().size() != 1) {
return;
}
List<@NonNull ITimeGraphState> row = model.getRows().get(0).getStates();
if (row.size() != 1) {
return;
}
ITimeGraphState stackInterval = row.get(0);
viewer.setSelectedTimeNotify(stackInterval.getStartTime(), true);
int stackLevel = stackInterval.getValue();
ITimeGraphEntry selectedEntry = callStackEntry.getParent().getChildren().get(Integer.max(0, stackLevel - 1));
viewer.setSelection(selectedEntry, true);
viewer.getTimeGraphControl().fireSelectionChanged();
startZoomThread(viewer.getTime0(), viewer.getTime1());
}
}
};
prevAction.setText(superPrevAction.getText());
prevAction.setToolTipText(superPrevAction.getToolTipText());
prevAction.setImageDescriptor(superPrevAction.getImageDescriptor());
fPrevEventAction = prevAction;
}
return prevAction;
}
use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer in project tracecompass by tracecompass.
the class FlameGraphView method createPartControl.
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
fTimeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);
FlameGraphContentProvider timeGraphContentProvider = new FlameGraphContentProvider();
fTimeGraphContentProvider = timeGraphContentProvider;
fTimeGraphViewer.setTimeGraphContentProvider(timeGraphContentProvider);
fTimeGraphViewer.setTimeGraphProvider(new FlameGraphPresentationProvider());
ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
if (trace != null) {
traceSelected(new TmfTraceSelectedSignal(this, trace));
}
contributeToActionBars();
loadSortOption();
loadContentPresentationOption();
TmfSignalManager.register(this);
getSite().setSelectionProvider(fTimeGraphViewer.getSelectionProvider());
IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
MenuManager item = new MenuManager(Messages.FlameGraphView_ContentPresentation);
item.setRemoveAllWhenShown(true);
item.addMenuListener(manager -> {
item.add(VIEW_BY_THREAD);
item.add(VIEW_AGGREGATE);
});
menuManager.add(item);
createTimeEventContextMenu();
fTimeGraphViewer.getTimeGraphControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
TimeGraphControl timeGraphControl = getTimeGraphViewer().getTimeGraphControl();
ISelection selection = timeGraphControl.getSelection();
if (selection instanceof IStructuredSelection) {
for (Object object : ((IStructuredSelection) selection).toList()) {
if (object instanceof FlamegraphEvent) {
FlamegraphEvent event = (FlamegraphEvent) object;
long startTime = event.getTime();
long endTime = startTime + event.getDuration();
getTimeGraphViewer().setStartFinishTimeNotify(startTime, endTime);
break;
}
}
}
}
});
}
use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer in project tracecompass by tracecompass.
the class XmlTimeGraphView method buildEntryList.
// ------------------------------------------------------------------------
// Internal
// ------------------------------------------------------------------------
@Override
protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
/*
* Get the view element from the XML file. If the element can't be found,
* return.
*/
Element viewElement = fViewInfo.getViewElement(TmfXmlStrings.TIME_GRAPH_VIEW);
if (viewElement == null) {
return;
}
// Empty the additional state values
fStringValueMap.clear();
ITimeGraphPresentationProvider pres = this.getPresentationProvider();
if (pres instanceof XmlPresentationProvider) {
/*
* TODO: Each entry of a line could have their own states/color. That will
* require an update to the presentation provider
*/
((XmlPresentationProvider) pres).loadNewStates(viewElement);
Display.getDefault().asyncExec(() -> {
TimeGraphViewer timeGraphViewer = getTimeGraphViewer();
if (timeGraphViewer.getTimeGraphControl().isDisposed()) {
return;
}
timeGraphViewer.getTimeGraphControl().colorSettingsChanged(timeGraphViewer.getTimeGraphProvider().getStateTable());
});
}
String title = fViewInfo.getViewTitle(viewElement);
setViewTitle(title != null ? title : Messages.XmlTimeGraphView_DefaultTitle);
SubMonitor subMonitor = SubMonitor.convert(monitor);
boolean complete = false;
ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> provider = XmlDataProviderManager.getInstance().getTimeGraphProvider(trace, viewElement);
if (provider == null) {
return;
}
while (!complete && !subMonitor.isCanceled()) {
TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> response = provider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), subMonitor);
if (response.getStatus() == ITmfResponse.Status.FAILED) {
// $NON-NLS-1$
Activator.logError("XML Time Graph Data Provider failed: " + response.getStatusMessage());
return;
} else if (response.getStatus() == ITmfResponse.Status.CANCELLED) {
return;
}
complete = response.getStatus() == ITmfResponse.Status.COMPLETED;
TmfTreeModel<@NonNull TimeGraphEntryModel> model = response.getModel();
if (model != null) {
synchronized (fEntries) {
/*
* Ensure that all the entries exist and are up to date.
*/
for (TimeGraphEntryModel entry : model.getEntries()) {
TimeGraphEntry tgEntry = fEntries.get(provider, entry.getId());
if (tgEntry == null) {
if (entry.getParentId() == -1) {
tgEntry = new TraceEntry(entry, trace, provider);
addToEntryList(parentTrace, Collections.singletonList(tgEntry));
} else {
tgEntry = new TimeGraphEntry(entry);
}
fEntries.put(provider, entry.getId(), tgEntry);
} else {
tgEntry.updateModel(entry);
}
if (entry.getParentId() == -1) {
setStartTime(Long.min(getStartTime(), entry.getStartTime()));
setEndTime(Long.max(getEndTime(), entry.getEndTime()));
}
}
}
/*
* set the correct child / parent relation
*/
for (TimeGraphEntry child : fEntries.row(provider).values()) {
TimeGraphEntry parent = fEntries.get(provider, child.getEntryModel().getParentId());
if (parent != null) {
parent.addChild(child);
}
}
long start = getStartTime();
long end = getEndTime();
final long resolution = Long.max(1, (end - start) / getDisplayWidth());
zoomEntries(fEntries.row(provider).values(), start, end, resolution, subMonitor);
}
if (parentTrace.equals(getTrace())) {
refresh();
}
subMonitor.worked(1);
if (!complete) {
try {
Thread.sleep(BUILD_UPDATE_TIMEOUT);
} catch (InterruptedException e) {
// $NON-NLS-1$
Activator.logError("Failed to wait for data provider", e);
}
}
}
}
use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer in project tracecompass by tracecompass.
the class TsfTraceAnalysisView method makeActions.
private void makeActions() {
// action1
action1 = new Action() {
@Override
public void run() {
showMessage("Action 1 executed");
}
};
action1.setText("Action 1");
action1.setToolTipText("Action 1 tooltip");
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
// action2
action2 = new Action() {
@Override
public void run() {
showMessage("Action 2 executed");
}
};
action2.setText("Action 2");
action2.setToolTipText("Action 2 tooltip");
action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
// action4
resetScale = new Action() {
@Override
public void run() {
TimeGraphViewer inFocusViewer = getActiveTsfCtrl();
if (inFocusViewer != null) {
inFocusViewer.resetStartFinishTime();
}
}
};
resetScale.setText("Reset");
resetScale.setToolTipText("Reset the Time Scale to Default");
// action5
nextEvent = new Action() {
@Override
public void run() {
TimeGraphViewer inFocusViewer = getActiveTsfCtrl();
if (inFocusViewer != null) {
inFocusViewer.selectNextEvent(false);
}
}
};
nextEvent.setText("NextEv");
nextEvent.setToolTipText("Next Event");
// action6
prevEvent = new Action() {
@Override
public void run() {
TimeGraphViewer inFocusViewer = getActiveTsfCtrl();
if (inFocusViewer != null) {
inFocusViewer.selectPrevEvent(false);
}
}
};
prevEvent.setText("PrevEv");
prevEvent.setToolTipText("Previous Event");
// action7
nextTrace = new Action() {
@Override
public void run() {
TimeGraphViewer inFocusViewer = getActiveTsfCtrl();
if (inFocusViewer != null) {
inFocusViewer.selectNextItem();
}
}
};
nextTrace.setText("NextTrace");
nextTrace.setToolTipText("Select Next Trace");
// action8
prevTrace = new Action() {
@Override
public void run() {
TimeGraphViewer inFocusViewer = getActiveTsfCtrl();
if (inFocusViewer != null) {
inFocusViewer.selectPrevItem();
}
}
};
prevTrace.setText("PrevTrace");
prevTrace.setToolTipText("Select Previous Trace");
// action9
showLegent = new Action() {
@Override
public void run() {
TimeGraphViewer inFocusViewer = getActiveTsfCtrl();
if (inFocusViewer != null) {
inFocusViewer.showLegend();
}
}
};
showLegent.setText("Legend");
showLegent.setToolTipText("Show Legend");
// action10
zoomIn = new Action() {
@Override
public void run() {
TimeGraphViewer inFocusViewer = getActiveTsfCtrl();
if (inFocusViewer != null) {
inFocusViewer.zoomIn();
}
}
};
zoomIn.setText("Zoom In");
zoomIn.setToolTipText("Zoom In");
// action10
zoomOut = new Action() {
@Override
public void run() {
TimeGraphViewer inFocusViewer = getActiveTsfCtrl();
if (inFocusViewer != null) {
inFocusViewer.zoomOut();
}
// ISelection selection = inFocusViewer.getSelection();
// Object sel = null;
// if (selection != null && !selection.isEmpty()) {
// sel = ((IStructuredSelection) selection)
// .getFirstElement();
// if (sel instanceof EventImpl) {
// EventImpl event = (EventImpl) sel;
// inFocusViewer.selectNextEvent();
// }
// }
}
};
zoomOut.setText("Zoom Out");
zoomOut.setToolTipText("Zoom Out");
// action12
events300K = new Action() {
@Override
public void run() {
TimeGraphViewer inFocusViewer = getActiveTsfCtrl();
if (inFocusViewer != null) {
ITimeGraphEntry[] traceArr = fact.createLargeTraces(60);
inFocusViewer.setInput(traceArr);
}
}
};
events300K.setText("300K Events");
events300K.setToolTipText("Add 300K Events");
doubleClickAction = new Action() {
@Override
public void run() {
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
showMessage("Double-click detected on " + obj.toString());
}
};
}
Aggregations