linux.ui: Add support to show CPU usage per-cpu
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 8 Mar 2016 15:37:25 +0000 (10:37 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 11 Apr 2016 13:57:07 +0000 (09:57 -0400)
This adds support to the CpuUsageView to make it update when a
TmfCpuSelectedSignal is received.

The title updates to show which cpus are selected.

Change-Id: Ia315159b4746b8f33f747da6b2f6327065a32995
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/65423
Reviewed-by: Hudson CI
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageComposite.java
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageXYViewer.java

index 285fc3f502dc40a4537b6775a9d6df6203dfaa32..f75d85bb100da11b71308d97aab88fccd27d6ad9 100644 (file)
@@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.tracecompass.segmentstore.core,
  org.eclipse.tracecompass.analysis.timing.core,
  org.eclipse.tracecompass.analysis.timing.ui
-Import-Package: com.google.common.collect,
+Import-Package: com.google.common.base,
+ com.google.common.collect,
  org.swtchart
 Export-Package: org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow,
  org.eclipse.tracecompass.analysis.os.linux.ui.views.cpuusage,
index 44749ad794866e80f6ce9f6a7efc0bb3bb177dba..8251642d943150582a0d595294cad2f43fc5d065 100644 (file)
@@ -20,7 +20,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeSet;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.osgi.util.NLS;
@@ -69,6 +72,8 @@ public class CpuUsageComposite extends AbstractTmfTreeViewer {
     /* A map that saves the mapping of a thread ID to its executable name */
     private final Map<String, String> fProcessNameMap = new HashMap<>();
 
+    private final @NonNull Set<@NonNull Integer> fCpus = new TreeSet<>();
+
     /** Provides label for the CPU usage tree viewer cells */
     protected static class CpuLabelProvider extends TreeLabelProvider {
 
@@ -230,7 +235,7 @@ public class CpuUsageComposite extends AbstractTmfTreeViewer {
         }
 
         /* Initialize the data */
-        Map<String, Long> cpuUsageMap = fModule.getCpuUsageInRange(Collections.EMPTY_SET, Math.max(start, getStartTime()), Math.min(end, getEndTime()));
+        Map<String, Long> cpuUsageMap = fModule.getCpuUsageInRange(fCpus, Math.max(start, getStartTime()), Math.min(end, getEndTime()));
 
         TmfTreeViewerEntry root = new TmfTreeViewerEntry(""); //$NON-NLS-1$
         List<ITmfTreeViewerEntry> entryList = root.getChildren();
@@ -289,7 +294,9 @@ public class CpuUsageComposite extends AbstractTmfTreeViewer {
                         execNameQuark = kernelSs.getQuarkRelative(tidQuark, Attributes.EXEC_NAME);
                         execNameIntervals = StateSystemUtils.queryHistoryRange(kernelSs, execNameQuark, getStartTime(), getEndTime());
                     } catch (AttributeNotFoundException e) {
-                        /* No information on this thread (yet?), skip it for now */
+                        /*
+                         * No information on this thread (yet?), skip it for now
+                         */
                         continue;
                     } catch (StateSystemDisposedException e) {
                         /* State system is closing down, no point continuing */
@@ -323,4 +330,39 @@ public class CpuUsageComposite extends AbstractTmfTreeViewer {
         fSelectedThread = tid;
     }
 
+    /**
+     * Add a core
+     *
+     * @param core
+     *            the core to add
+     * @since 2.0
+     */
+    public void addCpu(int core) {
+        fCpus.add(core);
+        updateContent(getWindowStartTime(), getWindowEndTime(), false);
+    }
+
+    /**
+     * Remove a core
+     *
+     * @param core
+     *            the core to remove
+     * @since 2.0
+     */
+    public void removeCpu(int core) {
+        fCpus.remove(core);
+        updateContent(getWindowStartTime(), getWindowEndTime(), false);
+    }
+
+    /**
+     * Clears the cores
+     *
+     * @since 2.0
+     *
+     */
+    public void clearCpu() {
+        fCpus.clear();
+        updateContent(getWindowStartTime(), getWindowEndTime(), false);
+    }
+
 }
index 520049b6965cdb6493b33cbeb63479e882f7836a..2aba6ec5044979554aad36e07c1d6fb08a186875 100644 (file)
@@ -20,6 +20,8 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.swt.events.ControlAdapter;
 import org.eclipse.swt.events.ControlEvent;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tracecompass.analysis.os.linux.core.signals.TmfCpuSelectedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
@@ -117,4 +119,27 @@ public class CpuUsageView extends TmfChartView {
         }
     }
 
+    /**
+     * Signal handler for when a cpu is selected
+     *
+     * @param signal
+     *            the cpu being selected
+     * @since 2.0
+     */
+    @TmfSignalHandler
+    public void cpuSelect(TmfCpuSelectedSignal signal) {
+        final @Nullable CpuUsageXYViewer xyViewer = fXYViewer;
+        final @Nullable CpuUsageComposite treeViewer = fTreeViewer;
+        if (xyViewer != null && treeViewer != null) {
+            int core = signal.getCore();
+            if (core >= 0) {
+                xyViewer.addCpu(core);
+                treeViewer.addCpu(core);
+            } else {
+                xyViewer.clearCpu();
+                treeViewer.clearCpu();
+            }
+        }
+    }
+
 }
index 3b6d05e7865f8236afba9b3efdf88cdfd5a3f492..8d1ace114198b95fa039f91733699c9563924e06 100644 (file)
@@ -15,13 +15,15 @@ package org.eclipse.tracecompass.analysis.os.linux.ui.views.cpuusage;
 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
 
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeSet;
 
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.KernelCpuUsageAnalysis;
 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.Activator;
@@ -31,6 +33,8 @@ import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts.TmfCommonXLineChartViewer;
 
+import com.google.common.base.Joiner;
+
 /**
  * CPU usage viewer with XY line chart. It displays the total CPU usage and that
  * of the threads selected in the CPU usage tree viewer.
@@ -54,6 +58,8 @@ public class CpuUsageXYViewer extends TmfCommonXLineChartViewer {
 
     private long fSelectedThread = -1;
 
+    private final @NonNull Set<@NonNull Integer> fCpus = new TreeSet<>();
+
     /**
      * Constructor
      *
@@ -118,7 +124,7 @@ public class CpuUsageXYViewer extends TmfCommonXLineChartViewer {
                 currentEnd = ss.getCurrentEndTime();
 
                 /* Initialize the data */
-                Map<String, Long> cpuUsageMap = fModule.getCpuUsageInRange(Collections.EMPTY_SET, Math.max(start, traceStart), Math.min(end, traceEnd));
+                Map<String, Long> cpuUsageMap = fModule.getCpuUsageInRange(fCpus, Math.max(start, traceStart), Math.min(end, traceEnd));
                 Map<String, String> totalEntries = new HashMap<>();
                 fYValues.clear();
                 fYValues.put(Messages.CpuUsageXYViewer_Total, zeroFill(xvalues.length));
@@ -172,7 +178,7 @@ public class CpuUsageXYViewer extends TmfCommonXLineChartViewer {
                         prevTime = time - 1;
                     }
 
-                    cpuUsageMap = fModule.getCpuUsageInRange(Collections.EMPTY_SET, prevTime, time);
+                    cpuUsageMap = fModule.getCpuUsageInRange(fCpus, prevTime, time);
 
                     /*
                      * Calculate the sum of all total entries, and add a data
@@ -222,4 +228,59 @@ public class CpuUsageXYViewer extends TmfCommonXLineChartViewer {
         updateContent();
     }
 
+    /**
+     * Gets the analysis module
+     *
+     * @return the {@link KernelCpuUsageAnalysis}
+     *
+     * @since 2.0
+     */
+    public KernelCpuUsageAnalysis getModule() {
+        return fModule;
+    }
+
+    /**
+     * Add a core
+     *
+     * @param core
+     *            the core to add
+     * @since 2.0
+     */
+    public void addCpu(int core) {
+        fCpus.add(core);
+        cancelUpdate();
+        updateContent();
+        getSwtChart().getTitle().setText(Messages.CpuUsageView_Title + ' ' + getCpuList());
+    }
+
+    /**
+     * Remove a core
+     *
+     * @param core
+     *            the core to remove
+     * @since 2.0
+     */
+    public void removeCpu(int core) {
+        fCpus.remove(core);
+        cancelUpdate();
+        updateContent();
+        getSwtChart().getTitle().setText(Messages.CpuUsageView_Title + ' ' + getCpuList());
+    }
+
+    private String getCpuList() {
+        return Joiner.on(", ").join(fCpus); //$NON-NLS-1$
+    }
+
+    /**
+     * Clears the cores
+     *
+     * @since 2.0
+     */
+    public void clearCpu() {
+        fCpus.clear();
+        cancelUpdate();
+        updateContent();
+        getSwtChart().getTitle().setText(Messages.CpuUsageView_Title);
+    }
+
 }
This page took 0.02842 seconds and 5 git commands to generate.