X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.lttng2.kernel.ui%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Finternal%2Flttng2%2Fkernel%2Fui%2Fviews%2Fcontrolflow%2FControlFlowPresentationProvider.java;h=e554e0d93831c91902bbeca12da0453ac8cd88ff;hb=bcec0116448fab84a99a822ea9912cabb5c983f4;hp=89d02b56231d0162a2f944820631f0bc3dce704a;hpb=6151d86cb1e3f18d4eb446347fe249f8b26dfa0d;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java index 89d02b5623..e554e0d938 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java +++ b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,6 +8,7 @@ * * Contributors: * Patrick Tasse - Initial API and implementation + * Geneviève Bastien - Move code to provide base classes for time graph view *******************************************************************************/ package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow; @@ -18,17 +19,25 @@ import java.util.Map; import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues; +import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Activator; import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages; -import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; -import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; -import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; -import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; -import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier; -import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; +import org.eclipse.linuxtools.lttng2.kernel.core.analysis.LttngKernelAnalysisModule; +import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem; +import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException; +import org.eclipse.linuxtools.statesystem.core.exceptions.StateSystemDisposedException; +import org.eclipse.linuxtools.statesystem.core.exceptions.StateValueTypeException; +import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException; +import org.eclipse.linuxtools.statesystem.core.interval.ITmfStateInterval; +import org.eclipse.linuxtools.statesystem.core.statevalue.ITmfStateValue; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.Rectangle; /** * Presentation provider for the control flow view @@ -36,29 +45,38 @@ import org.eclipse.swt.graphics.RGB; public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider { private enum State { - UNKNOWN (new RGB(100, 100, 100)), - WAIT (new RGB(200, 200, 0)), - USERMODE (new RGB(0, 200, 0)), - SYSCALL (new RGB(0, 0, 200)), - INTERRUPTED (new RGB(200, 100, 100)); + UNKNOWN (new RGB(100, 100, 100)), + WAIT_BLOCKED (new RGB(200, 200, 0)), + WAIT_FOR_CPU (new RGB(200, 100, 0)), + USERMODE (new RGB(0, 200, 0)), + SYSCALL (new RGB(0, 0, 200)), + INTERRUPTED (new RGB(200, 0, 100)); public final RGB rgb; - private State (RGB rgb) { + private State(RGB rgb) { this.rgb = rgb; } + } - @Override - public String getStateTypeName() { - return Messages.ControlFlowView_stateTypeName; + /** + * Default constructor + */ + public ControlFlowPresentationProvider() { + super(Messages.ControlFlowView_stateTypeName); + } + + private static State[] getStateValues() { + return State.values(); } @Override public StateItem[] getStateTable() { - StateItem[] stateTable = new StateItem[State.values().length]; + State[] states = getStateValues(); + StateItem[] stateTable = new StateItem[states.length]; for (int i = 0; i < stateTable.length; i++) { - State state = State.values()[i]; + State state = states[i]; stateTable[i] = new StateItem(state.rgb, state.toString()); } return stateTable; @@ -66,89 +84,135 @@ public class ControlFlowPresentationProvider extends TimeGraphPresentationProvid @Override public int getStateTableIndex(ITimeEvent event) { - if (event instanceof ControlFlowEvent) { - int status = ((ControlFlowEvent) event).getStatus(); - if (status == StateValues.PROCESS_STATUS_WAIT) { - return State.WAIT.ordinal(); - } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) { - return State.USERMODE.ordinal(); - } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) { - return State.SYSCALL.ordinal(); - } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) { - return State.INTERRUPTED.ordinal(); - } + if (event instanceof TimeEvent && ((TimeEvent) event).hasValue()) { + int status = ((TimeEvent) event).getValue(); + return getMatchingState(status).ordinal(); } - return State.UNKNOWN.ordinal(); + return TRANSPARENT; } @Override public String getEventName(ITimeEvent event) { - if (event instanceof ControlFlowEvent) { - int status = ((ControlFlowEvent) event).getStatus(); - if (status == StateValues.PROCESS_STATUS_WAIT) { - return State.WAIT.toString(); - } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) { - return State.USERMODE.toString(); - } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) { - return State.SYSCALL.toString(); - } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) { - return State.INTERRUPTED.toString(); + if (event instanceof TimeEvent) { + TimeEvent ev = (TimeEvent) event; + if (ev.hasValue()) { + return getMatchingState(ev.getValue()).toString(); } } - return State.UNKNOWN.toString(); + return Messages.ControlFlowView_multipleStates; + } + + private static State getMatchingState(int status) { + switch (status) { + case StateValues.PROCESS_STATUS_WAIT_BLOCKED: + return State.WAIT_BLOCKED; + case StateValues.PROCESS_STATUS_WAIT_FOR_CPU: + return State.WAIT_FOR_CPU; + case StateValues.PROCESS_STATUS_RUN_USERMODE: + return State.USERMODE; + case StateValues.PROCESS_STATUS_RUN_SYSCALL: + return State.SYSCALL; + case StateValues.PROCESS_STATUS_INTERRUPTED: + return State.INTERRUPTED; + default: + return State.UNKNOWN; + } } @Override public Map getEventHoverToolTipInfo(ITimeEvent event) { - Map retMap = new LinkedHashMap(); - if (event instanceof ControlFlowEvent) { - ControlFlowEntry entry = (ControlFlowEntry) event.getEntry(); - IStateSystemQuerier ssq = entry.getTrace().getStateSystem(); - int tid = entry.getThreadId(); - - try { - //Find every CPU first, then get the current thread - int cpusQuark = ssq.getQuarkAbsolute(Attributes.CPUS); - List cpuQuarks = ssq.getSubAttributes(cpusQuark, false); - for (Integer cpuQuark : cpuQuarks) { - int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD); - ITmfStateInterval interval = ssq.querySingleState(event.getTime(), currentThreadQuark); - if (!interval.getStateValue().isNull()) { - ITmfStateValue state = interval.getStateValue(); - int currentThreadId = state.unboxInt(); - if (tid == currentThreadId) { - retMap.put(Messages.ControlFlowView_attributeCpuName, ssq.getAttributeName(cpuQuark)); - break; - } + Map retMap = new LinkedHashMap<>(); + if (!(event instanceof TimeEvent) || !((TimeEvent) event).hasValue() || + !(event.getEntry() instanceof ControlFlowEntry)) { + return retMap; + } + ControlFlowEntry entry = (ControlFlowEntry) event.getEntry(); + LttngKernelAnalysisModule module = entry.getTrace().getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID); + if (module == null) { + return retMap; + } + ITmfStateSystem ssq = module.getStateSystem(); + if (ssq == null) { + return retMap; + } + int tid = entry.getThreadId(); + + try { + // Find every CPU first, then get the current thread + int cpusQuark = ssq.getQuarkAbsolute(Attributes.CPUS); + List cpuQuarks = ssq.getSubAttributes(cpusQuark, false); + for (Integer cpuQuark : cpuQuarks) { + int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD); + ITmfStateInterval interval = ssq.querySingleState(event.getTime(), currentThreadQuark); + if (!interval.getStateValue().isNull()) { + ITmfStateValue state = interval.getStateValue(); + int currentThreadId = state.unboxInt(); + if (tid == currentThreadId) { + retMap.put(Messages.ControlFlowView_attributeCpuName, ssq.getAttributeName(cpuQuark)); + break; } } - - } catch (AttributeNotFoundException e) { - e.printStackTrace(); - } catch (TimeRangeException e) { - e.printStackTrace(); - } catch (StateValueTypeException e) { - e.printStackTrace(); } - int status = ((ControlFlowEvent) event).getStatus(); - if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) { - try { - int syscallQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL); - ITmfStateInterval value = ssq.querySingleState(event.getTime(), syscallQuark); - if (!value.getStateValue().isNull()) { - ITmfStateValue state = value.getStateValue(); - retMap.put(Messages.ControlFlowView_attributeSyscallName, state.toString()); - } - } catch (AttributeNotFoundException e) { - e.printStackTrace(); - } catch (TimeRangeException e) { - e.printStackTrace(); + } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) { + Activator.getDefault().logError("Error in ControlFlowPresentationProvider", e); //$NON-NLS-1$ + } catch (StateSystemDisposedException e) { + /* Ignored */ + } + int status = ((TimeEvent) event).getValue(); + if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) { + try { + int syscallQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL); + ITmfStateInterval value = ssq.querySingleState(event.getTime(), syscallQuark); + if (!value.getStateValue().isNull()) { + ITmfStateValue state = value.getStateValue(); + retMap.put(Messages.ControlFlowView_attributeSyscallName, state.toString()); } + + } catch (AttributeNotFoundException | TimeRangeException e) { + Activator.getDefault().logError("Error in ControlFlowPresentationProvider", e); //$NON-NLS-1$ + } catch (StateSystemDisposedException e) { + /* Ignored */ } } return retMap; } + @Override + public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) { + if (bounds.width <= gc.getFontMetrics().getAverageCharWidth()) { + return; + } + if (!(event instanceof TimeEvent)) { + return; + } + ControlFlowEntry entry = (ControlFlowEntry) event.getEntry(); + LttngKernelAnalysisModule module = entry.getTrace().getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID); + if (module == null) { + return; + } + ITmfStateSystem ss = module.getStateSystem(); + if (ss == null) { + return; + } + int status = ((TimeEvent) event).getValue(); + + if (status != StateValues.PROCESS_STATUS_RUN_SYSCALL) { + return; + } + try { + int syscallQuark = ss.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL); + ITmfStateInterval value = ss.querySingleState(event.getTime(), syscallQuark); + if (!value.getStateValue().isNull()) { + ITmfStateValue state = value.getStateValue(); + gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); + Utils.drawText(gc, state.toString().substring(4), bounds.x, bounds.y - 2, bounds.width, true, true); + } + } catch (AttributeNotFoundException | TimeRangeException e) { + Activator.getDefault().logError("Error in ControlFlowPresentationProvider", e); //$NON-NLS-1$ + } catch (StateSystemDisposedException e) { + /* Ignored */ + } + } }