Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

profiling: add wasd controls to flamegraphview #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.MenuDetectEvent;
import org.eclipse.swt.events.MenuDetectListener;
import org.eclipse.swt.events.MouseAdapter;
Expand All @@ -85,6 +87,8 @@
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.filters.TraceCompassFilter;
import org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets.timegraph.BaseDataProviderTimeGraphPresentationProvider;
import org.eclipse.tracecompass.internal.tmf.core.model.filters.FetchParametersUtils;
import org.eclipse.tracecompass.internal.tmf.ui.views.ITmfTimeNavigationProvider;
import org.eclipse.tracecompass.internal.tmf.ui.views.ITmfTimeZoomProvider;
import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager;
Expand Down Expand Up @@ -133,6 +137,8 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;

import com.google.common.annotations.VisibleForTesting;
Expand All @@ -156,6 +162,7 @@ public class FlameGraphView extends TmfView {
* ID of the view
*/
public static final String ID = "org.eclipse.tracecompass.analysis.profiling.ui.flamegraph"; //$NON-NLS-1$
private static final String TMF_VIEW_UI_CONTEXT = "org.eclipse.tracecompass.tmf.ui.view.context"; //$NON-NLS-1$

private static final @NonNull String SYMBOL_MAPPING_ICON_PATH = "icons/obj16/binaries_obj.gif"; //$NON-NLS-1$
private static final @NonNull String GROUP_BY_ICON_PATH = "icons/etool16/group_by.gif"; //$NON-NLS-1$
Expand Down Expand Up @@ -214,6 +221,9 @@ public class FlameGraphView extends TmfView {
private @Nullable ZoomThread fZoomThread;
private final Object fZoomThreadResultLock = new Object();

private IContextService fContextService;

private List<IContextActivation> fActiveContexts = new ArrayList<>();
/**
* Constructor
*/
Expand Down Expand Up @@ -309,6 +319,34 @@ public void paintControl(PaintEvent e) {
});
}
});

fContextService = Objects.requireNonNull(getSite().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();
}
});
}

private void activateContextService() {
if (fActiveContexts.isEmpty()) {
fActiveContexts.add(fContextService.activateContext(TMF_VIEW_UI_CONTEXT));
}
}

private void deactivateContextService() {
fContextService.deactivateContexts(fActiveContexts);
fActiveContexts.clear();
}

/**
Expand Down Expand Up @@ -527,6 +565,57 @@ public BaseDataProviderTimeGraphPresentationProvider getPresentationProvider() {
return fPresentationProvider;
}

@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter == ITmfTimeNavigationProvider.class) {
return (T) getTimeNavigator();
}
if (adapter == ITmfTimeZoomProvider.class) {
return (T) getTimeZoomProvider();
}
return super.getAdapter(adapter);
}

private ITmfTimeNavigationProvider getTimeNavigator() {
return left -> {
TimeGraphControl control = getTimeGraphControl();
if (control != null) {
control.horizontalScroll(left);
}
};
}

private ITmfTimeZoomProvider getTimeZoomProvider() {
return (zoomIn, useMousePosition) -> {
TimeGraphControl control = getTimeGraphControl();
TimeGraphViewer viewer = getTimeGraphViewer();
if (control != null && viewer != null) {
if (useMousePosition) {
control.zoom(zoomIn);
} else {
int xCoord = control.toControl(control.getDisplay().getCursorLocation()).x;
if ((viewer.getNameSpace() <= xCoord) && (xCoord < control.getSize().x)) {
if (zoomIn) {
control.zoomIn();
} else {
control.zoomOut();
}
}
}
}
};
}

private @Nullable TimeGraphControl getTimeGraphControl() {
TimeGraphViewer viewer = getTimeGraphViewer();
TimeGraphControl control = viewer.getTimeGraphControl();
if (control != null) {
return control;
}
return null;
}

private static BiFunction<ITimeEvent, Long, Map<String, String>> getTooltipResolver(ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider) {
return (event, time) -> getTooltip(event, time, provider, false);
}
Expand Down
2 changes: 1 addition & 1 deletion tmf/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Export-Package: org.eclipse.tracecompass.internal.provisional.tmf.ui.model;x-int
org.eclipse.tracecompass.internal.tmf.ui.viewers.timegraph.handlers;x-internal:=true,
org.eclipse.tracecompass.internal.tmf.ui.viewers.tree;x-internal:=true,
org.eclipse.tracecompass.internal.tmf.ui.viewers.xychart;x-internal:=true,
org.eclipse.tracecompass.internal.tmf.ui.views;x-friends:="org.eclipse.tracecompass.tmf.ui.swtbot.tests",
org.eclipse.tracecompass.internal.tmf.ui.views;x-friends:="org.eclipse.tracecompass.tmf.ui.swtbot.tests,org.eclipse.tracecompass.analysis.profiling.ui",
org.eclipse.tracecompass.internal.tmf.ui.views.eventdensity;x-internal:=true,
org.eclipse.tracecompass.internal.tmf.ui.views.handler;x-internal:=true,
org.eclipse.tracecompass.internal.tmf.ui.views.histogram;x-internal:=true,
Expand Down
Loading