Use transparent color for unknown states in ControlFlow/Resources view
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / resources / ResourcesPresentationProvider.java
index 3e3012bdba1844111614efe5e5ca8fb02ce99d8c..77fa8fbd7e200466da6bc375193bad338d512db0 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -20,6 +20,7 @@ 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.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;
 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
+import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
 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.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
@@ -29,11 +30,16 @@ import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 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.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.TimeGraphViewer;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
 
 /**
  * Presentation provider for the Resource view, based on the generic TMF
 
 /**
  * Presentation provider for the Resource view, based on the generic TMF
@@ -43,14 +49,16 @@ import org.eclipse.swt.graphics.RGB;
  */
 public class ResourcesPresentationProvider extends TimeGraphPresentationProvider {
 
  */
 public class ResourcesPresentationProvider extends TimeGraphPresentationProvider {
 
+    private final TimeGraphViewer fTimeGraphViewer;
+    private long fLastThreadId = -1; // used to draw the process name label only once per thread id
+
     private enum State {
     private enum State {
-        UNKNOWN         (new RGB(100, 100, 100)),
         IDLE            (new RGB(200, 200, 200)),
         USERMODE        (new RGB(0, 200, 0)),
         SYSCALL         (new RGB(0, 0, 200)),
         IDLE            (new RGB(200, 200, 200)),
         USERMODE        (new RGB(0, 200, 0)),
         SYSCALL         (new RGB(0, 0, 200)),
-        IRQ             (new RGB(200, 100, 100)),
+        IRQ             (new RGB(200,   0, 100)),
         SOFT_IRQ        (new RGB(200, 150, 100)),
         SOFT_IRQ        (new RGB(200, 150, 100)),
-        IRQ_ACTIVE      (new RGB(200, 100, 100)),
+        IRQ_ACTIVE      (new RGB(200,   0, 100)),
         SOFT_IRQ_RAISED (new RGB(200, 200, 0)),
         SOFT_IRQ_ACTIVE (new RGB(200, 150, 100));
 
         SOFT_IRQ_RAISED (new RGB(200, 200, 0)),
         SOFT_IRQ_ACTIVE (new RGB(200, 150, 100));
 
@@ -61,6 +69,16 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
         }
     }
 
         }
     }
 
+    /**
+     * Default constructor
+     *
+     * @param timeGraphViewer the time graph viewer
+     */
+    public ResourcesPresentationProvider(TimeGraphViewer timeGraphViewer) {
+        super();
+        this.fTimeGraphViewer = timeGraphViewer;
+    }
+
     @Override
     public String getStateTypeName() {
         return Messages.ResourcesView_stateTypeName;
     @Override
     public String getStateTypeName() {
         return Messages.ResourcesView_stateTypeName;
@@ -102,10 +120,10 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
                 }
                 return State.SOFT_IRQ_ACTIVE.ordinal();
             } else {
                 }
                 return State.SOFT_IRQ_ACTIVE.ordinal();
             } else {
-                return -1; // NULL
+                return INVISIBLE; // NULL
             }
         }
             }
         }
-        return State.UNKNOWN.ordinal();
+        return TRANSPARENT;
     }
 
     @Override
     }
 
     @Override
@@ -137,7 +155,7 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
                 return null;
             }
         }
                 return null;
             }
         }
-        return State.UNKNOWN.toString();
+        return Messages.ResourcesView_multipleStates;
     }
 
     @Override
     }
 
     @Override
@@ -165,19 +183,18 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
                 if (status == StateValues.CPU_STATUS_IRQ) {
                     // In IRQ state get the IRQ that caused the interruption
                     ResourcesEntry entry = (ResourcesEntry) event.getEntry();
                 if (status == StateValues.CPU_STATUS_IRQ) {
                     // In IRQ state get the IRQ that caused the interruption
                     ResourcesEntry entry = (ResourcesEntry) event.getEntry();
-                    ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+                    ITmfStateSystem ss = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
                     int cpu = entry.getId();
 
                     int cpu = entry.getId();
 
-                    ITmfStateSystem ss = entry.getTrace().getStateSystem();
                     try {
                         List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());
                         List<Integer> irqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
 
                         for (int irqQuark : irqQuarks) {
                             if (fullState.get(irqQuark).getStateValue().unboxInt() == cpu) {
                     try {
                         List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());
                         List<Integer> irqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
 
                         for (int irqQuark : irqQuarks) {
                             if (fullState.get(irqQuark).getStateValue().unboxInt() == cpu) {
-                                ITmfStateInterval value = ssq.querySingleState(event.getTime(), irqQuark);
+                                ITmfStateInterval value = ss.querySingleState(event.getTime(), irqQuark);
                                 if (!value.getStateValue().isNull()) {
                                 if (!value.getStateValue().isNull()) {
-                                    int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
+                                    int irq = Integer.parseInt(ss.getAttributeName(irqQuark));
                                     retMap.put(Messages.ResourcesView_attributeIrqName, String.valueOf(irq));
                                 }
                                 break;
                                     retMap.put(Messages.ResourcesView_attributeIrqName, String.valueOf(irq));
                                 }
                                 break;
@@ -195,19 +212,18 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
                 } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {
                     // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption
                     ResourcesEntry entry = (ResourcesEntry) event.getEntry();
                 } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {
                     // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption
                     ResourcesEntry entry = (ResourcesEntry) event.getEntry();
-                    ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+                    ITmfStateSystem ss = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
                     int cpu = entry.getId();
 
                     int cpu = entry.getId();
 
-                    ITmfStateSystem ss = entry.getTrace().getStateSystem();
                     try {
                         List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());
                         List<Integer> softIrqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
 
                         for (int softIrqQuark : softIrqQuarks) {
                             if (fullState.get(softIrqQuark).getStateValue().unboxInt() == cpu) {
                     try {
                         List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());
                         List<Integer> softIrqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
 
                         for (int softIrqQuark : softIrqQuarks) {
                             if (fullState.get(softIrqQuark).getStateValue().unboxInt() == cpu) {
-                                ITmfStateInterval value = ssq.querySingleState(event.getTime(), softIrqQuark);
+                                ITmfStateInterval value = ss.querySingleState(event.getTime(), softIrqQuark);
                                 if (!value.getStateValue().isNull()) {
                                 if (!value.getStateValue().isNull()) {
-                                    int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
+                                    int softIrq = Integer.parseInt(ss.getAttributeName(softIrqQuark));
                                     retMap.put(Messages.ResourcesView_attributeSoftIrqName, String.valueOf(softIrq));
                                 }
                                 break;
                                     retMap.put(Messages.ResourcesView_attributeSoftIrqName, String.valueOf(softIrq));
                                 }
                                 break;
@@ -225,10 +241,10 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
                 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE || status == StateValues.CPU_STATUS_RUN_SYSCALL){
                     // In running state get the current tid
                     ResourcesEntry entry = (ResourcesEntry) event.getEntry();
                 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE || status == StateValues.CPU_STATUS_RUN_SYSCALL){
                     // In running state get the current tid
                     ResourcesEntry entry = (ResourcesEntry) event.getEntry();
-                    ITmfStateSystem ssq = entry.getTrace().getStateSystem();
+                    ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
 
                     try {
 
                     try {
-                        retMap.put(Messages.ResourcesView_attributeHoverTime, Utils.formatTime(hoverTime, TimeFormat.ABSOLUTE, Resolution.NANOSEC));
+                        retMap.put(Messages.ResourcesView_attributeHoverTime, Utils.formatTime(hoverTime, TimeFormat.CALENDAR, Resolution.NANOSEC));
                         int cpuQuark = entry.getQuark();
                         int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD);
                         ITmfStateInterval interval = ssq.querySingleState(hoverTime, currentThreadQuark);
                         int cpuQuark = entry.getQuark();
                         int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD);
                         ITmfStateInterval interval = ssq.querySingleState(hoverTime, currentThreadQuark);
@@ -267,4 +283,88 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider
         return retMap;
     }
 
         return retMap;
     }
 
+    @Override
+    public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) {
+        if (bounds.width <= gc.getFontMetrics().getAverageCharWidth()) {
+            return;
+        }
+        if (!(event instanceof ResourcesEvent)) {
+            return;
+        }
+        ResourcesEvent resourcesEvent = (ResourcesEvent) event;
+        if (!resourcesEvent.getType().equals(Type.CPU)) {
+            return;
+        }
+        int status = resourcesEvent.getValue();
+        if (status != StateValues.CPU_STATUS_RUN_USERMODE && status != StateValues.CPU_STATUS_RUN_SYSCALL) {
+            return;
+        }
+        ResourcesEntry entry = (ResourcesEntry) event.getEntry();
+        ITmfStateSystem ss = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID);
+        long time = event.getTime();
+        try {
+            while (time < event.getTime() + event.getDuration()) {
+                int cpuQuark = entry.getQuark();
+                int currentThreadQuark = ss.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD);
+                ITmfStateInterval tidInterval = ss.querySingleState(time, currentThreadQuark);
+                if (!tidInterval.getStateValue().isNull()) {
+                    ITmfStateValue value = tidInterval.getStateValue();
+                    int currentThreadId = value.unboxInt();
+                    if (status == StateValues.CPU_STATUS_RUN_USERMODE && currentThreadId != fLastThreadId) {
+                        int execNameQuark = ss.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThreadId), Attributes.EXEC_NAME);
+                        ITmfStateInterval interval = ss.querySingleState(time, execNameQuark);
+                        if (!interval.getStateValue().isNull()) {
+                            value = interval.getStateValue();
+                            gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
+                            long startTime = Math.max(tidInterval.getStartTime(), event.getTime());
+                            long endTime = Math.min(tidInterval.getEndTime() + 1, event.getTime() + event.getDuration());
+                            if (fTimeGraphViewer.getXForTime(endTime) > bounds.x) {
+                                int x = Math.max(fTimeGraphViewer.getXForTime(startTime), bounds.x);
+                                int width = Math.min(fTimeGraphViewer.getXForTime(endTime), bounds.x + bounds.width) - x;
+                                int drawn = Utils.drawText(gc, value.unboxStr(), x + 1, bounds.y - 2, width - 1, true, true);
+                                if (drawn > 0) {
+                                    fLastThreadId = currentThreadId;
+                                }
+                            }
+                        }
+                    } else if (status == StateValues.CPU_STATUS_RUN_SYSCALL) {
+                        int syscallQuark = ss.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThreadId), Attributes.SYSTEM_CALL);
+                        ITmfStateInterval interval = ss.querySingleState(time, syscallQuark);
+                        if (!interval.getStateValue().isNull()) {
+                            value = interval.getStateValue();
+                            gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
+                            long startTime = Math.max(tidInterval.getStartTime(), event.getTime());
+                            long endTime = Math.min(tidInterval.getEndTime() + 1, event.getTime() + event.getDuration());
+                            if (fTimeGraphViewer.getXForTime(endTime) > bounds.x) {
+                                int x = Math.max(fTimeGraphViewer.getXForTime(startTime), bounds.x);
+                                int width = Math.min(fTimeGraphViewer.getXForTime(endTime), bounds.x + bounds.width) - x;
+                                Utils.drawText(gc, value.unboxStr().substring(4), x + 1, bounds.y - 2, width - 1, true, true);
+                            }
+                        }
+                    }
+                }
+                time = tidInterval.getEndTime() + 1;
+                if (time < event.getTime() + event.getDuration()) {
+                    int x = fTimeGraphViewer.getXForTime(time);
+                    if (x >= bounds.x) {
+                        gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_GRAY));
+                        gc.drawLine(x, bounds.y + 1, x, bounds.y + bounds.height - 2);
+                    }
+                }
+            }
+        } catch (AttributeNotFoundException e) {
+            e.printStackTrace();
+        } catch (TimeRangeException e) {
+            e.printStackTrace();
+        } catch (StateValueTypeException e) {
+            e.printStackTrace();
+        } catch (StateSystemDisposedException e) {
+            /* Ignored */
+        }
+    }
+
+    @Override
+    public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc) {
+        fLastThreadId = -1;
+    }
 }
 }
This page took 0.027373 seconds and 5 git commands to generate.