tmf: Split the state system in a separate plugin
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / controlflow / ControlFlowPresentationProvider.java
index cb148e03d1febdbc998f72f5e9e9572aa23b1dca..e554e0d93831c91902bbeca12da0453ac8cd88ff 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal
+ * 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
@@ -19,20 +19,20 @@ 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.lttng2.kernel.core.trace.LttngKernelTrace;
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
-import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
-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.ITmfStateSystem;
-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.model.TimeGraphEntry;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.GC;
@@ -121,59 +121,58 @@ public class ControlFlowPresentationProvider extends TimeGraphPresentationProvid
 
     @Override
     public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {
-        Map<String, String> retMap = new LinkedHashMap<String, String>();
+        Map<String, String> 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();
 
-        if (event instanceof TimeEvent && ((TimeEvent) event).hasValue()) {
-            TimeGraphEntry entry = (TimeGraphEntry) event.getEntry();
-            ITmfStateSystem ssq = entry.getTrace().getStateSystems().get(LttngKernelTrace.STATE_ID);
-            if (entry instanceof ControlFlowEntry) {
-                ControlFlowEntry entry2 = (ControlFlowEntry) entry;
-                int tid = entry2.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;
-                            }
-                        }
+        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();
-                } catch (StateSystemDisposedException e) {
-                    /* Ignored */
                 }
-                int status = ((TimeEvent) event).getValue();
-                if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
-                    try {
-                        int syscallQuark = ssq.getQuarkRelative(entry2.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 (StateSystemDisposedException e) {
-                        /* Ignored */
-                    }
+            }
+
+        } 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 */
             }
         }
 
@@ -189,7 +188,14 @@ public class ControlFlowPresentationProvider extends TimeGraphPresentationProvid
             return;
         }
         ControlFlowEntry entry = (ControlFlowEntry) event.getEntry();
-        ITmfStateSystem ss = entry.getTrace().getStateSystems().get(LttngKernelTrace.STATE_ID);
+        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) {
@@ -203,10 +209,8 @@ public class ControlFlowPresentationProvider extends TimeGraphPresentationProvid
                 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 e) {
-            e.printStackTrace();
-        } catch (TimeRangeException e) {
-            e.printStackTrace();
+        } catch (AttributeNotFoundException | TimeRangeException e) {
+            Activator.getDefault().logError("Error in ControlFlowPresentationProvider", e); //$NON-NLS-1$
         } catch (StateSystemDisposedException e) {
             /* Ignored */
         }
This page took 0.026545 seconds and 5 git commands to generate.