Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / controlflow / ControlFlowPresentationProvider.java
index 7e2e9e5551c7d891c8048a4f6abd14d3c6317069..89d02b56231d0162a2f944820631f0bc3dce704a 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *   Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;\r
-\r
-import java.util.LinkedHashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;\r
-import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;\r
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;\r
-import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;\r
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;\r
-import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.swt.graphics.RGB;\r
-\r
-/**\r
- * Presentation provider for the control flow view\r
- */\r
-public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider {\r
-\r
-    private enum State {\r
-        UNKNOWN     (new RGB(100, 100, 100)),\r
-        WAIT        (new RGB(200, 200, 0)),\r
-        USERMODE    (new RGB(0, 200, 0)),\r
-        SYSCALL     (new RGB(0, 0, 200)),\r
-        INTERRUPTED (new RGB(200, 100, 100));\r
-\r
-        public final RGB rgb;\r
-\r
-        private State (RGB rgb) {\r
-            this.rgb = rgb;\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public String getStateTypeName() {\r
-        return Messages.ControlFlowView_stateTypeName;\r
-    }\r
-\r
-    @Override\r
-    public StateItem[] getStateTable() {\r
-        StateItem[] stateTable = new StateItem[State.values().length];\r
-        for (int i = 0; i < stateTable.length; i++) {\r
-            State state = State.values()[i];\r
-            stateTable[i] = new StateItem(state.rgb, state.toString());\r
-        }\r
-        return stateTable;\r
-    }\r
-\r
-    @Override\r
-    public int getStateTableIndex(ITimeEvent event) {\r
-        if (event instanceof ControlFlowEvent) {\r
-            int status = ((ControlFlowEvent) event).getStatus();\r
-            if (status == StateValues.PROCESS_STATUS_WAIT) {\r
-                return State.WAIT.ordinal();\r
-            } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {\r
-                return State.USERMODE.ordinal();\r
-            } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {\r
-                return State.SYSCALL.ordinal();\r
-            } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {\r
-                return State.INTERRUPTED.ordinal();\r
-            }\r
-        }\r
-        return State.UNKNOWN.ordinal();\r
-    }\r
-\r
-    @Override\r
-    public String getEventName(ITimeEvent event) {\r
-        if (event instanceof ControlFlowEvent) {\r
-            int status = ((ControlFlowEvent) event).getStatus();\r
-            if (status == StateValues.PROCESS_STATUS_WAIT) {\r
-                return State.WAIT.toString();\r
-            } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {\r
-                return State.USERMODE.toString();\r
-            } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {\r
-                return State.SYSCALL.toString();\r
-            } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {\r
-                return State.INTERRUPTED.toString();\r
-            }\r
-        }\r
-        return State.UNKNOWN.toString();\r
-    }\r
-\r
-    @Override\r
-    public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {\r
-        Map<String, String> retMap = new LinkedHashMap<String, String>();\r
-        if (event instanceof ControlFlowEvent) {\r
-            ControlFlowEntry entry = (ControlFlowEntry) event.getEntry();\r
-            IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r
-            int tid = entry.getThreadId();\r
-\r
-            try {\r
-                //Find every CPU first, then get the current thread\r
-                int cpusQuark = ssq.getQuarkAbsolute(Attributes.CPUS);\r
-                List<Integer> cpuQuarks = ssq.getSubAttributes(cpusQuark, false);\r
-                for (Integer cpuQuark : cpuQuarks) {\r
-                    int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD);\r
-                    ITmfStateInterval interval = ssq.querySingleState(event.getTime(), currentThreadQuark);\r
-                    if (!interval.getStateValue().isNull()) {\r
-                        ITmfStateValue state = interval.getStateValue();\r
-                        int currentThreadId = state.unboxInt();\r
-                        if (tid == currentThreadId) {\r
-                            retMap.put(Messages.ControlFlowView_attributeCpuName, ssq.getAttributeName(cpuQuark));\r
-                            break;\r
-                        }\r
-                    }\r
-                }\r
-\r
-            } catch (AttributeNotFoundException e) {\r
-                e.printStackTrace();\r
-            } catch (TimeRangeException e) {\r
-                e.printStackTrace();\r
-            } catch (StateValueTypeException e) {\r
-                e.printStackTrace();\r
-            }\r
-            int status = ((ControlFlowEvent) event).getStatus();\r
-            if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {\r
-                try {\r
-                    int syscallQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL);\r
-                    ITmfStateInterval value = ssq.querySingleState(event.getTime(), syscallQuark);\r
-                    if (!value.getStateValue().isNull()) {\r
-                        ITmfStateValue state = value.getStateValue();\r
-                        retMap.put(Messages.ControlFlowView_attributeSyscallName, state.toString());\r
-                    }\r
-\r
-                } catch (AttributeNotFoundException e) {\r
-                    e.printStackTrace();\r
-                } catch (TimeRangeException e) {\r
-                    e.printStackTrace();\r
-                }\r
-            }\r
-        }\r
-\r
-        return retMap;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+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.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.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.swt.graphics.RGB;
+
+/**
+ * Presentation provider for the control flow view
+ */
+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));
+
+        public final RGB rgb;
+
+        private State (RGB rgb) {
+            this.rgb = rgb;
+        }
+    }
+
+    @Override
+    public String getStateTypeName() {
+        return Messages.ControlFlowView_stateTypeName;
+    }
+
+    @Override
+    public StateItem[] getStateTable() {
+        StateItem[] stateTable = new StateItem[State.values().length];
+        for (int i = 0; i < stateTable.length; i++) {
+            State state = State.values()[i];
+            stateTable[i] = new StateItem(state.rgb, state.toString());
+        }
+        return stateTable;
+    }
+
+    @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();
+            }
+        }
+        return State.UNKNOWN.ordinal();
+    }
+
+    @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();
+            }
+        }
+        return State.UNKNOWN.toString();
+    }
+
+    @Override
+    public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {
+        Map<String, String> retMap = new LinkedHashMap<String, String>();
+        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<Integer> 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();
+                }
+            }
+        }
+
+        return retMap;
+    }
+
+}
This page took 0.033898 seconds and 5 git commands to generate.