linux.ui: Add support to show CPU usage per-cpu
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui / src / org / eclipse / tracecompass / analysis / os / linux / ui / views / cpuusage / CpuUsageComposite.java
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);
+    }
+
 }
This page took 0.024752 seconds and 5 git commands to generate.