analysis: Bug 489573: Internalize CPU Usage view implementation
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Tue, 22 Mar 2016 11:37:39 +0000 (07:37 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Thu, 14 Apr 2016 13:27:45 +0000 (09:27 -0400)
Change-Id: I45e930b51b718f0fd469096f968b8484965b0971
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/69009
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Hudson CI
14 files changed:
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/plugin.xml
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageComposite.java [deleted file]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageEntry.java [deleted file]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java [deleted file]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageXYViewer.java [deleted file]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/Messages.java [deleted file]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/messages.properties [deleted file]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageComposite.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageEntry.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageXYViewer.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/Messages.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/messages.properties [new file with mode: 0644]

index 84c4d0125009c50f9793889e40b91085e5c34f36..2d3907dfbb895de63fdcec72f25cebc7848d33fb 100644 (file)
@@ -24,13 +24,13 @@ 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,
  org.eclipse.tracecompass.analysis.os.linux.ui.views.resources,
  org.eclipse.tracecompass.internal.analysis.os.linux.ui;x-friends:="org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests",
  org.eclipse.tracecompass.internal.analysis.os.linux.ui.actions;x-internal:=true,
  org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow;x-friends:="org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests,org.eclipse.tracecompass.analysis.os.linux.ui.tests",
  org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.io.diskioactivity;x-internal:=true,
  org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.kernelmemoryusage;x-internal:=true,
+ org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.cpuusage;x-internal:=true,
  org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency;x-friends:="org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests",
  org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics;x-friends:="org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests",
  org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.resources;x-friends:="org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests"
index e3bcef7c9c2309c734f48207e1fd0ab30210b4c6..00275929c6b18c8976c4265a4753ab297bca3154 100644 (file)
@@ -24,7 +24,7 @@
       <view
             allowMultiple="false"
             category="org.eclipse.linuxtools.lttng2.ui.views.category"
-            class="org.eclipse.tracecompass.analysis.os.linux.ui.views.cpuusage.CpuUsageView"
+            class="org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.cpuusage.CpuUsageView"
             icon="icons/eview16/cpu-usage.png"
             id="org.eclipse.tracecompass.analysis.os.linux.views.cpuusage"
             name="%cpuusage.view.name"
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageComposite.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageComposite.java
deleted file mode 100644 (file)
index 1962d1b..0000000
+++ /dev/null
@@ -1,368 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 É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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.analysis.os.linux.ui.views.cpuusage;
-
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
-import java.util.ArrayList;
-import java.util.Collections;
-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;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.KernelCpuUsageAnalysis;
-import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
-import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
-import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
-import org.eclipse.tracecompass.tmf.ui.viewers.tree.AbstractTmfTreeViewer;
-import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeColumnDataProvider;
-import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry;
-import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeColumnData;
-import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeColumnData.ITmfColumnPercentageProvider;
-import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry;
-
-/**
- * Tree viewer to display CPU usage information in a specified time range. It
- * shows the process's TID, its name, the time spent on the CPU during that
- * range, in % and absolute value.
- *
- * @author Geneviève Bastien
- */
-public class CpuUsageComposite extends AbstractTmfTreeViewer {
-
-    // Timeout between to wait for in the updateElements method
-    private static final long BUILD_UPDATE_TIMEOUT = 500;
-
-    private KernelCpuUsageAnalysis fModule = null;
-    private String fSelectedThread = null;
-
-    private static final String[] COLUMN_NAMES = new String[] {
-            Messages.CpuUsageComposite_ColumnTID,
-            Messages.CpuUsageComposite_ColumnProcess,
-            Messages.CpuUsageComposite_ColumnPercent,
-            Messages.CpuUsageComposite_ColumnTime
-    };
-
-    /* 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 {
-
-        @Override
-        public String getColumnText(Object element, int columnIndex) {
-            CpuUsageEntry obj = (CpuUsageEntry) element;
-            if (columnIndex == 0) {
-                return obj.getTid();
-            } else if (columnIndex == 1) {
-                return obj.getProcessName();
-            } else if (columnIndex == 2) {
-                return String.format(Messages.CpuUsageComposite_TextPercent, obj.getPercent());
-            } else if (columnIndex == 3) {
-                return NLS.bind(Messages.CpuUsageComposite_TextTime, obj.getTime());
-            }
-
-            return element.toString();
-        }
-
-    }
-
-    /**
-     * Constructor
-     *
-     * @param parent
-     *            The parent composite that holds this viewer
-     */
-    public CpuUsageComposite(Composite parent) {
-        super(parent, false);
-        setLabelProvider(new CpuLabelProvider());
-    }
-
-    @Override
-    protected ITmfTreeColumnDataProvider getColumnDataProvider() {
-        return new ITmfTreeColumnDataProvider() {
-
-            @Override
-            public List<TmfTreeColumnData> getColumnData() {
-                /* All columns are sortable */
-                List<TmfTreeColumnData> columns = new ArrayList<>();
-                TmfTreeColumnData column = new TmfTreeColumnData(COLUMN_NAMES[0]);
-                column.setComparator(new ViewerComparator() {
-                    @Override
-                    public int compare(Viewer viewer, Object e1, Object e2) {
-                        CpuUsageEntry n1 = (CpuUsageEntry) e1;
-                        CpuUsageEntry n2 = (CpuUsageEntry) e2;
-
-                        return n1.getTid().compareTo(n2.getTid());
-
-                    }
-                });
-                columns.add(column);
-                column = new TmfTreeColumnData(COLUMN_NAMES[1]);
-                column.setComparator(new ViewerComparator() {
-                    @Override
-                    public int compare(Viewer viewer, Object e1, Object e2) {
-                        CpuUsageEntry n1 = (CpuUsageEntry) e1;
-                        CpuUsageEntry n2 = (CpuUsageEntry) e2;
-
-                        return n1.getProcessName().compareTo(n2.getProcessName());
-
-                    }
-                });
-                columns.add(column);
-                column = new TmfTreeColumnData(COLUMN_NAMES[2]);
-                column.setComparator(new ViewerComparator() {
-                    @Override
-                    public int compare(Viewer viewer, Object e1, Object e2) {
-                        CpuUsageEntry n1 = (CpuUsageEntry) e1;
-                        CpuUsageEntry n2 = (CpuUsageEntry) e2;
-
-                        return n1.getPercent().compareTo(n2.getPercent());
-
-                    }
-                });
-                column.setPercentageProvider(new ITmfColumnPercentageProvider() {
-
-                    @Override
-                    public double getPercentage(Object data) {
-                        CpuUsageEntry parent = (CpuUsageEntry) data;
-                        return parent.getPercent() / 100;
-                    }
-                });
-                columns.add(column);
-                column = new TmfTreeColumnData(COLUMN_NAMES[3]);
-                column.setComparator(new ViewerComparator() {
-                    @Override
-                    public int compare(Viewer viewer, Object e1, Object e2) {
-                        CpuUsageEntry n1 = (CpuUsageEntry) e1;
-                        CpuUsageEntry n2 = (CpuUsageEntry) e2;
-
-                        return n1.getTime().compareTo(n2.getTime());
-
-                    }
-                });
-                columns.add(column);
-
-                return columns;
-            }
-
-        };
-    }
-
-    // ------------------------------------------------------------------------
-    // Operations
-    // ------------------------------------------------------------------------
-
-    @Override
-    protected void contentChanged(ITmfTreeViewerEntry rootEntry) {
-        String selectedThread = fSelectedThread;
-        if (selectedThread != null) {
-            /* Find the selected thread among the inputs */
-            for (ITmfTreeViewerEntry entry : rootEntry.getChildren()) {
-                if (entry instanceof CpuUsageEntry) {
-                    if (selectedThread.equals(((CpuUsageEntry) entry).getTid())) {
-                        List<ITmfTreeViewerEntry> list = Collections.singletonList(entry);
-                        super.setSelection(list);
-                        return;
-                    }
-                }
-            }
-        }
-    }
-
-    @Override
-    public void initializeDataSource() {
-        /* Should not be called while trace is still null */
-        ITmfTrace trace = checkNotNull(getTrace());
-
-        fModule = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelCpuUsageAnalysis.class, KernelCpuUsageAnalysis.ID);
-        if (fModule == null) {
-            return;
-        }
-        fModule.schedule();
-        fModule.waitForInitialization();
-        fProcessNameMap.clear();
-    }
-
-    @Override
-    protected ITmfTreeViewerEntry updateElements(long start, long end, boolean isSelection) {
-        if (isSelection || (start == end)) {
-            return null;
-        }
-        if (getTrace() == null || fModule == null) {
-            return null;
-        }
-        fModule.waitForInitialization();
-        ITmfStateSystem ss = fModule.getStateSystem();
-        if (ss == null) {
-            return null;
-        }
-
-        boolean complete = false;
-        long currentEnd = start;
-
-        while (!complete && currentEnd < end) {
-            complete = ss.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
-            currentEnd = ss.getCurrentEndTime();
-        }
-
-        /* Initialize the data */
-        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();
-
-        for (Entry<String, Long> entry : cpuUsageMap.entrySet()) {
-            /*
-             * Process only entries representing the total of all CPUs and that
-             * have time on CPU
-             */
-            if (entry.getValue() == 0) {
-                continue;
-            }
-            if (!entry.getKey().startsWith(KernelCpuUsageAnalysis.TOTAL)) {
-                continue;
-            }
-            String[] strings = entry.getKey().split(KernelCpuUsageAnalysis.SPLIT_STRING, 2);
-
-            if ((strings.length > 1) && !(strings[1].equals(KernelCpuUsageAnalysis.TID_ZERO))) {
-                CpuUsageEntry obj = new CpuUsageEntry(strings[1], getProcessName(strings[1]), (double) entry.getValue() / (double) (end - start) * 100, entry.getValue());
-                entryList.add(obj);
-            }
-        }
-
-        return root;
-    }
-
-    /*
-     * Get the process name from its TID by using the LTTng kernel analysis
-     * module
-     */
-    private String getProcessName(String tid) {
-        String execName = fProcessNameMap.get(tid);
-        if (execName != null) {
-            return execName;
-        }
-        ITmfTrace trace = getTrace();
-        if (trace == null) {
-            return tid;
-        }
-        ITmfStateSystem kernelSs = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
-        if (kernelSs == null) {
-            return tid;
-        }
-
-        try {
-            int cpusNode = kernelSs.getQuarkAbsolute(Attributes.THREADS);
-
-            /* Get the quarks for each cpu */
-            List<Integer> cpuNodes = kernelSs.getSubAttributes(cpusNode, false);
-
-            for (Integer tidQuark : cpuNodes) {
-                if (kernelSs.getAttributeName(tidQuark).equals(tid)) {
-                    int execNameQuark;
-                    List<ITmfStateInterval> execNameIntervals;
-                    try {
-                        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
-                         */
-                        continue;
-                    } catch (StateSystemDisposedException e) {
-                        /* State system is closing down, no point continuing */
-                        break;
-                    }
-
-                    for (ITmfStateInterval execNameInterval : execNameIntervals) {
-                        if (!execNameInterval.getStateValue().isNull() &&
-                                execNameInterval.getStateValue().getType() == ITmfStateValue.Type.STRING) {
-                            execName = execNameInterval.getStateValue().unboxStr();
-                            fProcessNameMap.put(tid, execName);
-                            return execName;
-                        }
-                    }
-                }
-            }
-
-        } catch (AttributeNotFoundException e) {
-            /* can't find the process name, just return the tid instead */
-        }
-        return tid;
-    }
-
-    /**
-     * Set the currently selected thread ID
-     *
-     * @param tid
-     *            The selected thread ID
-     */
-    public void setSelectedThread(String tid) {
-        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);
-    }
-
-}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageEntry.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageEntry.java
deleted file mode 100644 (file)
index 94ac77a..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 É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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.analysis.os.linux.ui.views.cpuusage;
-
-import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry;
-
-/**
- * Represents an entry in the tree viewer of the CPU usage view. An entry is a
- * thread that occupied part of the CPU in the selected time range.
- *
- * @author Geneviève Bastien
- */
-public class CpuUsageEntry extends TmfTreeViewerEntry {
-    private final String fTid;
-    private final String fProcessName;
-    private final Double fPercent;
-    private final Long fTime;
-
-    /**
-     * Constructor
-     *
-     * @param tid
-     *            The TID of the process
-     * @param name
-     *            The thread's name
-     * @param percent
-     *            The percentage CPU usage
-     * @param time
-     *            The total amount of time spent on CPU
-     */
-    public CpuUsageEntry(String tid, String name, double percent, long time) {
-        super(tid);
-        fTid = tid;
-        fProcessName = name;
-        fPercent = percent;
-        fTime = time;
-    }
-
-    /**
-     * Get the TID of the thread represented by this entry
-     *
-     * @return The thread's TID
-     */
-    public String getTid() {
-        return fTid;
-    }
-
-    /**
-     * Get the process name
-     *
-     * @return The process name
-     */
-    public String getProcessName() {
-        return fProcessName;
-    }
-
-    /**
-     * Get the percentage of time spent on CPU in the time interval represented
-     * by this entry.
-     *
-     * @return The percentage of time spent on CPU
-     */
-    public Double getPercent() {
-        return fPercent;
-    }
-
-    /**
-     * Get the total time spent on CPU in the time interval represented by this
-     * entry.
-     *
-     * @return The total time spent on CPU
-     */
-    public Long getTime() {
-        return fTime;
-    }
-}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java
deleted file mode 100644 (file)
index 2aba6ec..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others
- *
- * 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:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.analysis.os.linux.ui.views.cpuusage;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-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;
-import org.eclipse.tracecompass.tmf.ui.viewers.TmfViewer;
-import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.TmfXYChartViewer;
-import org.eclipse.tracecompass.tmf.ui.views.TmfChartView;
-
-/**
- * CPU usage view. It contains 2 viewers: one tree viewer showing all the
- * threads who were on the CPU in the time range, and one XY chart viewer
- * plotting the total time spent on CPU and the time of the threads selected in
- * the tree viewer.
- *
- * @author Geneviève Bastien
- */
-public class CpuUsageView extends TmfChartView {
-
-    /** ID string */
-    public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.views.cpuusage"; //$NON-NLS-1$
-
-    private @Nullable CpuUsageComposite fTreeViewer = null;
-    private @Nullable CpuUsageXYViewer fXYViewer = null;
-
-    /**
-     * Constructor
-     */
-    public CpuUsageView() {
-        super(Messages.CpuUsageView_Title);
-    }
-
-    @Override
-    public void createPartControl(Composite parent) {
-        super.createPartControl(parent);
-
-        /* Initialize the viewers with the currently selected trace */
-        ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
-        if (trace != null) {
-            TmfTraceSelectedSignal signal = new TmfTraceSelectedSignal(this, trace);
-            if (fTreeViewer != null) {
-                fTreeViewer.traceSelected(signal);
-            }
-            if (fXYViewer != null) {
-                fXYViewer.traceSelected(signal);
-            }
-        }
-    }
-
-    @Override
-    protected TmfXYChartViewer createChartViewer(Composite parent) {
-        CpuUsageXYViewer viewer = new CpuUsageXYViewer(parent);
-        viewer.setSendTimeAlignSignals(true);
-        fXYViewer = viewer;
-        return viewer;
-    }
-
-    @Override
-    public TmfViewer createLeftChildViewer(Composite parent) {
-        final CpuUsageComposite viewer = new CpuUsageComposite(parent);
-
-        /* Add selection listener to tree viewer */
-        viewer.addSelectionChangeListener(new ISelectionChangedListener() {
-            @Override
-            public void selectionChanged(SelectionChangedEvent event) {
-                ISelection selection = event.getSelection();
-                if (selection instanceof IStructuredSelection) {
-                    Object structSelection = ((IStructuredSelection) selection).getFirstElement();
-                    if (structSelection instanceof CpuUsageEntry) {
-                        CpuUsageEntry entry = (CpuUsageEntry) structSelection;
-                        if (fTreeViewer != null) {
-                            fTreeViewer.setSelectedThread(entry.getTid());
-                        }
-                        if (fXYViewer != null) {
-                            fXYViewer.setSelectedThread(Long.valueOf(entry.getTid()));
-                        }
-                    }
-                }
-            }
-        });
-
-        viewer.getControl().addControlListener(new ControlAdapter() {
-            @Override
-            public void controlResized(ControlEvent e) {
-                super.controlResized(e);
-            }
-        });
-
-        fTreeViewer = viewer;
-        return fTreeViewer;
-    }
-
-    @Override
-    public void setFocus() {
-        if (fXYViewer != null) {
-            fXYViewer.getControl().setFocus();
-        }
-    }
-
-    /**
-     * 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();
-            }
-        }
-    }
-
-}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageXYViewer.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageXYViewer.java
deleted file mode 100644 (file)
index 8d1ace1..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 É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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-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.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;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-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.
- *
- * @author Geneviève Bastien
- */
-public class CpuUsageXYViewer extends TmfCommonXLineChartViewer {
-
-    private KernelCpuUsageAnalysis fModule = null;
-
-    /* Maps a thread ID to a list of y values */
-    private final Map<String, double[]> fYValues = new LinkedHashMap<>();
-    /*
-     * To avoid up and downs CPU usage when process is in and out of CPU
-     * frequently, use a smaller resolution to get better averages.
-     */
-    private static final double RESOLUTION = 0.4;
-
-    // Timeout between updates in the updateData thread
-    private static final long BUILD_UPDATE_TIMEOUT = 500;
-
-    private long fSelectedThread = -1;
-
-    private final @NonNull Set<@NonNull Integer> fCpus = new TreeSet<>();
-
-    /**
-     * Constructor
-     *
-     * @param parent
-     *            parent composite
-     */
-    public CpuUsageXYViewer(Composite parent) {
-        super(parent, Messages.CpuUsageXYViewer_Title, Messages.CpuUsageXYViewer_TimeXAxis, Messages.CpuUsageXYViewer_CpuYAxis);
-        setResolution(RESOLUTION);
-    }
-
-    @Override
-    protected void initializeDataSource() {
-        ITmfTrace trace = getTrace();
-        if (trace != null) {
-            fModule = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelCpuUsageAnalysis.class, KernelCpuUsageAnalysis.ID);
-            if (fModule == null) {
-                return;
-            }
-            fModule.schedule();
-        }
-    }
-
-    private static double[] zeroFill(int nb) {
-        double[] arr = new double[nb];
-        Arrays.fill(arr, 0.0);
-        return arr;
-    }
-
-    @Override
-    protected void updateData(long start, long end, int nb, IProgressMonitor monitor) {
-        try {
-            if (getTrace() == null || fModule == null) {
-                return;
-            }
-            fModule.waitForInitialization();
-            ITmfStateSystem ss = fModule.getStateSystem();
-            if (ss == null) {
-                return;
-            }
-            double[] xvalues = getXAxis(start, end, nb);
-            if (xvalues.length == 0) {
-                return;
-            }
-            setXAxis(xvalues);
-
-            boolean complete = false;
-            long currentEnd = start;
-
-            while (!complete && currentEnd < end) {
-
-                if (monitor.isCanceled()) {
-                    return;
-                }
-
-                long traceStart = getStartTime();
-                long traceEnd = getEndTime();
-                long offset = getTimeOffset();
-                long selectedThread = fSelectedThread;
-
-                complete = ss.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
-                currentEnd = ss.getCurrentEndTime();
-
-                /* Initialize the data */
-                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));
-                String stringSelectedThread = Long.toString(selectedThread);
-                if (selectedThread != -1) {
-                    fYValues.put(stringSelectedThread, zeroFill(xvalues.length));
-                }
-
-                for (Entry<String, Long> entry : cpuUsageMap.entrySet()) {
-                    /*
-                     * Process only entries representing the total of all CPUs
-                     * and that have time on CPU
-                     */
-                    if (entry.getValue() == 0) {
-                        continue;
-                    }
-                    if (!entry.getKey().startsWith(KernelCpuUsageAnalysis.TOTAL)) {
-                        continue;
-                    }
-                    String[] strings = entry.getKey().split(KernelCpuUsageAnalysis.SPLIT_STRING, 2);
-
-                    if ((strings.length > 1) && !(strings[1].equals(KernelCpuUsageAnalysis.TID_ZERO))) {
-                        /* This is the total cpu usage for a thread */
-                        totalEntries.put(strings[1], entry.getKey());
-                    }
-                }
-
-                double prevX = xvalues[0] - 1;
-                long prevTime = (long) prevX + offset;
-                /*
-                 * make sure that time is in the trace range after double to
-                 * long conversion
-                 */
-                prevTime = Math.max(traceStart, prevTime);
-                prevTime = Math.min(traceEnd, prevTime);
-                /* Get CPU usage statistics for each x value */
-                for (int i = 0; i < xvalues.length; i++) {
-                    if (monitor.isCanceled()) {
-                        return;
-                    }
-                    long totalCpu = 0;
-                    double x = xvalues[i];
-                    long time = (long) x + offset;
-                    time = Math.max(traceStart, time);
-                    time = Math.min(traceEnd, time);
-                    if (time == prevTime) {
-                        /*
-                         * we need at least 1 time unit to be able to get cpu
-                         * usage when zoomed in
-                         */
-                        prevTime = time - 1;
-                    }
-
-                    cpuUsageMap = fModule.getCpuUsageInRange(fCpus, prevTime, time);
-
-                    /*
-                     * Calculate the sum of all total entries, and add a data
-                     * point to the selected one
-                     */
-                    for (Entry<String, String> entry : totalEntries.entrySet()) {
-                        Long cpuEntry = cpuUsageMap.get(entry.getValue());
-                        cpuEntry = cpuEntry != null ? cpuEntry : 0L;
-
-                        totalCpu += cpuEntry;
-
-                        if (entry.getKey().equals(stringSelectedThread)) {
-                            /* This is the total cpu usage for a thread */
-                            double[] key = checkNotNull(fYValues.get(entry.getKey()));
-                            key[i] = (double) cpuEntry / (double) (time - prevTime) * 100;
-                        }
-
-                    }
-                    double[] key = checkNotNull(fYValues.get(Messages.CpuUsageXYViewer_Total));
-                    key[i] = (double) totalCpu / (double) (time - prevTime) * 100;
-                    prevTime = time;
-                }
-                for (Entry<String, double[]> entry : fYValues.entrySet()) {
-                    setSeries(entry.getKey(), entry.getValue());
-                }
-                if (monitor.isCanceled()) {
-                    return;
-                }
-                updateDisplay();
-            }
-        } catch (StateValueTypeException e) {
-            Activator.getDefault().logError("Error updating the data of the CPU usage view", e); //$NON-NLS-1$
-        }
-
-    }
-
-    /**
-     * Set the selected thread ID, which will be graphed in this viewer
-     *
-     * @param tid
-     *            The selected thread ID
-     */
-    public void setSelectedThread(long tid) {
-        cancelUpdate();
-        deleteSeries(Long.toString(fSelectedThread));
-        fSelectedThread = tid;
-        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);
-    }
-
-}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/Messages.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/Messages.java
deleted file mode 100644 (file)
index 1460009..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 É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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.analysis.os.linux.ui.views.cpuusage;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Messages used in the LTTng kernel CPU usage view and viewers.
- *
- * @author Geneviève Bastien
- */
-@SuppressWarnings("javadoc")
-public class Messages extends NLS {
-
-    private static final String BUNDLE_NAME = "org.eclipse.tracecompass.analysis.os.linux.ui.views.cpuusage.messages"; //$NON-NLS-1$
-
-    public static String CpuUsageComposite_ColumnPercent;
-    public static String CpuUsageComposite_ColumnProcess;
-    public static String CpuUsageComposite_ColumnTID;
-    public static String CpuUsageComposite_ColumnTime;
-    public static String CpuUsageComposite_TextPercent;
-    public static String CpuUsageComposite_TextTime;
-    public static String CpuUsageView_Title;
-    public static String CpuUsageXYViewer_CpuYAxis;
-    public static String CpuUsageXYViewer_TimeXAxis;
-    public static String CpuUsageXYViewer_Title;
-    public static String CpuUsageXYViewer_Total;
-
-    static {
-        // initialize resource bundle
-        NLS.initializeMessages(BUNDLE_NAME, Messages.class);
-    }
-
-    private Messages() {
-    }
-}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/messages.properties b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/messages.properties
deleted file mode 100644 (file)
index bf8a799..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-###############################################################################
-# Copyright (c) 2014, 2015 É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 accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-#     Geneviève Bastien - Initial API and implementation
-###############################################################################
-
-CpuUsageComposite_ColumnPercent=%
-CpuUsageComposite_ColumnProcess=Process
-CpuUsageComposite_ColumnTID=TID
-CpuUsageComposite_ColumnTime=Time
-CpuUsageComposite_TextPercent=%1$.3f %%
-CpuUsageComposite_TextTime={0} ns
-CpuUsageView_Title=CPU Usage
-CpuUsageXYViewer_CpuYAxis=% CPU
-CpuUsageXYViewer_TimeXAxis=Time
-CpuUsageXYViewer_Title=CPU usage
-CpuUsageXYViewer_Total=Total
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageComposite.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageComposite.java
new file mode 100644 (file)
index 0000000..358f6a7
--- /dev/null
@@ -0,0 +1,368 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 É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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.cpuusage;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+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;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.KernelCpuUsageAnalysis;
+import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
+import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
+import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.AbstractTmfTreeViewer;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeColumnDataProvider;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeColumnData;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeColumnData.ITmfColumnPercentageProvider;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry;
+
+/**
+ * Tree viewer to display CPU usage information in a specified time range. It
+ * shows the process's TID, its name, the time spent on the CPU during that
+ * range, in % and absolute value.
+ *
+ * @author Geneviève Bastien
+ */
+public class CpuUsageComposite extends AbstractTmfTreeViewer {
+
+    // Timeout between to wait for in the updateElements method
+    private static final long BUILD_UPDATE_TIMEOUT = 500;
+
+    private KernelCpuUsageAnalysis fModule = null;
+    private String fSelectedThread = null;
+
+    private static final String[] COLUMN_NAMES = new String[] {
+            Messages.CpuUsageComposite_ColumnTID,
+            Messages.CpuUsageComposite_ColumnProcess,
+            Messages.CpuUsageComposite_ColumnPercent,
+            Messages.CpuUsageComposite_ColumnTime
+    };
+
+    /* 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 {
+
+        @Override
+        public String getColumnText(Object element, int columnIndex) {
+            CpuUsageEntry obj = (CpuUsageEntry) element;
+            if (columnIndex == 0) {
+                return obj.getTid();
+            } else if (columnIndex == 1) {
+                return obj.getProcessName();
+            } else if (columnIndex == 2) {
+                return String.format(Messages.CpuUsageComposite_TextPercent, obj.getPercent());
+            } else if (columnIndex == 3) {
+                return NLS.bind(Messages.CpuUsageComposite_TextTime, obj.getTime());
+            }
+
+            return element.toString();
+        }
+
+    }
+
+    /**
+     * Constructor
+     *
+     * @param parent
+     *            The parent composite that holds this viewer
+     */
+    public CpuUsageComposite(Composite parent) {
+        super(parent, false);
+        setLabelProvider(new CpuLabelProvider());
+    }
+
+    @Override
+    protected ITmfTreeColumnDataProvider getColumnDataProvider() {
+        return new ITmfTreeColumnDataProvider() {
+
+            @Override
+            public List<TmfTreeColumnData> getColumnData() {
+                /* All columns are sortable */
+                List<TmfTreeColumnData> columns = new ArrayList<>();
+                TmfTreeColumnData column = new TmfTreeColumnData(COLUMN_NAMES[0]);
+                column.setComparator(new ViewerComparator() {
+                    @Override
+                    public int compare(Viewer viewer, Object e1, Object e2) {
+                        CpuUsageEntry n1 = (CpuUsageEntry) e1;
+                        CpuUsageEntry n2 = (CpuUsageEntry) e2;
+
+                        return n1.getTid().compareTo(n2.getTid());
+
+                    }
+                });
+                columns.add(column);
+                column = new TmfTreeColumnData(COLUMN_NAMES[1]);
+                column.setComparator(new ViewerComparator() {
+                    @Override
+                    public int compare(Viewer viewer, Object e1, Object e2) {
+                        CpuUsageEntry n1 = (CpuUsageEntry) e1;
+                        CpuUsageEntry n2 = (CpuUsageEntry) e2;
+
+                        return n1.getProcessName().compareTo(n2.getProcessName());
+
+                    }
+                });
+                columns.add(column);
+                column = new TmfTreeColumnData(COLUMN_NAMES[2]);
+                column.setComparator(new ViewerComparator() {
+                    @Override
+                    public int compare(Viewer viewer, Object e1, Object e2) {
+                        CpuUsageEntry n1 = (CpuUsageEntry) e1;
+                        CpuUsageEntry n2 = (CpuUsageEntry) e2;
+
+                        return n1.getPercent().compareTo(n2.getPercent());
+
+                    }
+                });
+                column.setPercentageProvider(new ITmfColumnPercentageProvider() {
+
+                    @Override
+                    public double getPercentage(Object data) {
+                        CpuUsageEntry parent = (CpuUsageEntry) data;
+                        return parent.getPercent() / 100;
+                    }
+                });
+                columns.add(column);
+                column = new TmfTreeColumnData(COLUMN_NAMES[3]);
+                column.setComparator(new ViewerComparator() {
+                    @Override
+                    public int compare(Viewer viewer, Object e1, Object e2) {
+                        CpuUsageEntry n1 = (CpuUsageEntry) e1;
+                        CpuUsageEntry n2 = (CpuUsageEntry) e2;
+
+                        return n1.getTime().compareTo(n2.getTime());
+
+                    }
+                });
+                columns.add(column);
+
+                return columns;
+            }
+
+        };
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    @Override
+    protected void contentChanged(ITmfTreeViewerEntry rootEntry) {
+        String selectedThread = fSelectedThread;
+        if (selectedThread != null) {
+            /* Find the selected thread among the inputs */
+            for (ITmfTreeViewerEntry entry : rootEntry.getChildren()) {
+                if (entry instanceof CpuUsageEntry) {
+                    if (selectedThread.equals(((CpuUsageEntry) entry).getTid())) {
+                        List<ITmfTreeViewerEntry> list = Collections.singletonList(entry);
+                        super.setSelection(list);
+                        return;
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public void initializeDataSource() {
+        /* Should not be called while trace is still null */
+        ITmfTrace trace = checkNotNull(getTrace());
+
+        fModule = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelCpuUsageAnalysis.class, KernelCpuUsageAnalysis.ID);
+        if (fModule == null) {
+            return;
+        }
+        fModule.schedule();
+        fModule.waitForInitialization();
+        fProcessNameMap.clear();
+    }
+
+    @Override
+    protected ITmfTreeViewerEntry updateElements(long start, long end, boolean isSelection) {
+        if (isSelection || (start == end)) {
+            return null;
+        }
+        if (getTrace() == null || fModule == null) {
+            return null;
+        }
+        fModule.waitForInitialization();
+        ITmfStateSystem ss = fModule.getStateSystem();
+        if (ss == null) {
+            return null;
+        }
+
+        boolean complete = false;
+        long currentEnd = start;
+
+        while (!complete && currentEnd < end) {
+            complete = ss.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
+            currentEnd = ss.getCurrentEndTime();
+        }
+
+        /* Initialize the data */
+        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();
+
+        for (Entry<String, Long> entry : cpuUsageMap.entrySet()) {
+            /*
+             * Process only entries representing the total of all CPUs and that
+             * have time on CPU
+             */
+            if (entry.getValue() == 0) {
+                continue;
+            }
+            if (!entry.getKey().startsWith(KernelCpuUsageAnalysis.TOTAL)) {
+                continue;
+            }
+            String[] strings = entry.getKey().split(KernelCpuUsageAnalysis.SPLIT_STRING, 2);
+
+            if ((strings.length > 1) && !(strings[1].equals(KernelCpuUsageAnalysis.TID_ZERO))) {
+                CpuUsageEntry obj = new CpuUsageEntry(strings[1], getProcessName(strings[1]), (double) entry.getValue() / (double) (end - start) * 100, entry.getValue());
+                entryList.add(obj);
+            }
+        }
+
+        return root;
+    }
+
+    /*
+     * Get the process name from its TID by using the LTTng kernel analysis
+     * module
+     */
+    private String getProcessName(String tid) {
+        String execName = fProcessNameMap.get(tid);
+        if (execName != null) {
+            return execName;
+        }
+        ITmfTrace trace = getTrace();
+        if (trace == null) {
+            return tid;
+        }
+        ITmfStateSystem kernelSs = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
+        if (kernelSs == null) {
+            return tid;
+        }
+
+        try {
+            int cpusNode = kernelSs.getQuarkAbsolute(Attributes.THREADS);
+
+            /* Get the quarks for each cpu */
+            List<Integer> cpuNodes = kernelSs.getSubAttributes(cpusNode, false);
+
+            for (Integer tidQuark : cpuNodes) {
+                if (kernelSs.getAttributeName(tidQuark).equals(tid)) {
+                    int execNameQuark;
+                    List<ITmfStateInterval> execNameIntervals;
+                    try {
+                        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
+                         */
+                        continue;
+                    } catch (StateSystemDisposedException e) {
+                        /* State system is closing down, no point continuing */
+                        break;
+                    }
+
+                    for (ITmfStateInterval execNameInterval : execNameIntervals) {
+                        if (!execNameInterval.getStateValue().isNull() &&
+                                execNameInterval.getStateValue().getType() == ITmfStateValue.Type.STRING) {
+                            execName = execNameInterval.getStateValue().unboxStr();
+                            fProcessNameMap.put(tid, execName);
+                            return execName;
+                        }
+                    }
+                }
+            }
+
+        } catch (AttributeNotFoundException e) {
+            /* can't find the process name, just return the tid instead */
+        }
+        return tid;
+    }
+
+    /**
+     * Set the currently selected thread ID
+     *
+     * @param tid
+     *            The selected thread ID
+     */
+    public void setSelectedThread(String tid) {
+        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);
+    }
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageEntry.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageEntry.java
new file mode 100644 (file)
index 0000000..9075959
--- /dev/null
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 É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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.cpuusage;
+
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry;
+
+/**
+ * Represents an entry in the tree viewer of the CPU usage view. An entry is a
+ * thread that occupied part of the CPU in the selected time range.
+ *
+ * @author Geneviève Bastien
+ */
+public class CpuUsageEntry extends TmfTreeViewerEntry {
+    private final String fTid;
+    private final String fProcessName;
+    private final Double fPercent;
+    private final Long fTime;
+
+    /**
+     * Constructor
+     *
+     * @param tid
+     *            The TID of the process
+     * @param name
+     *            The thread's name
+     * @param percent
+     *            The percentage CPU usage
+     * @param time
+     *            The total amount of time spent on CPU
+     */
+    public CpuUsageEntry(String tid, String name, double percent, long time) {
+        super(tid);
+        fTid = tid;
+        fProcessName = name;
+        fPercent = percent;
+        fTime = time;
+    }
+
+    /**
+     * Get the TID of the thread represented by this entry
+     *
+     * @return The thread's TID
+     */
+    public String getTid() {
+        return fTid;
+    }
+
+    /**
+     * Get the process name
+     *
+     * @return The process name
+     */
+    public String getProcessName() {
+        return fProcessName;
+    }
+
+    /**
+     * Get the percentage of time spent on CPU in the time interval represented
+     * by this entry.
+     *
+     * @return The percentage of time spent on CPU
+     */
+    public Double getPercent() {
+        return fPercent;
+    }
+
+    /**
+     * Get the total time spent on CPU in the time interval represented by this
+     * entry.
+     *
+     * @return The total time spent on CPU
+     */
+    public Long getTime() {
+        return fTime;
+    }
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java
new file mode 100644 (file)
index 0000000..1ce79b1
--- /dev/null
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others
+ *
+ * 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:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.cpuusage;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+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;
+import org.eclipse.tracecompass.tmf.ui.viewers.TmfViewer;
+import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.TmfXYChartViewer;
+import org.eclipse.tracecompass.tmf.ui.views.TmfChartView;
+
+/**
+ * CPU usage view. It contains 2 viewers: one tree viewer showing all the
+ * threads who were on the CPU in the time range, and one XY chart viewer
+ * plotting the total time spent on CPU and the time of the threads selected in
+ * the tree viewer.
+ *
+ * @author Geneviève Bastien
+ */
+public class CpuUsageView extends TmfChartView {
+
+    /** ID string */
+    public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.views.cpuusage"; //$NON-NLS-1$
+
+    private @Nullable CpuUsageComposite fTreeViewer = null;
+    private @Nullable CpuUsageXYViewer fXYViewer = null;
+
+    /**
+     * Constructor
+     */
+    public CpuUsageView() {
+        super(Messages.CpuUsageView_Title);
+    }
+
+    @Override
+    public void createPartControl(Composite parent) {
+        super.createPartControl(parent);
+
+        /* Initialize the viewers with the currently selected trace */
+        ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
+        if (trace != null) {
+            TmfTraceSelectedSignal signal = new TmfTraceSelectedSignal(this, trace);
+            if (fTreeViewer != null) {
+                fTreeViewer.traceSelected(signal);
+            }
+            if (fXYViewer != null) {
+                fXYViewer.traceSelected(signal);
+            }
+        }
+    }
+
+    @Override
+    protected TmfXYChartViewer createChartViewer(Composite parent) {
+        CpuUsageXYViewer viewer = new CpuUsageXYViewer(parent);
+        viewer.setSendTimeAlignSignals(true);
+        fXYViewer = viewer;
+        return viewer;
+    }
+
+    @Override
+    public TmfViewer createLeftChildViewer(Composite parent) {
+        final CpuUsageComposite viewer = new CpuUsageComposite(parent);
+
+        /* Add selection listener to tree viewer */
+        viewer.addSelectionChangeListener(new ISelectionChangedListener() {
+            @Override
+            public void selectionChanged(SelectionChangedEvent event) {
+                ISelection selection = event.getSelection();
+                if (selection instanceof IStructuredSelection) {
+                    Object structSelection = ((IStructuredSelection) selection).getFirstElement();
+                    if (structSelection instanceof CpuUsageEntry) {
+                        CpuUsageEntry entry = (CpuUsageEntry) structSelection;
+                        if (fTreeViewer != null) {
+                            fTreeViewer.setSelectedThread(entry.getTid());
+                        }
+                        if (fXYViewer != null) {
+                            fXYViewer.setSelectedThread(Long.valueOf(entry.getTid()));
+                        }
+                    }
+                }
+            }
+        });
+
+        viewer.getControl().addControlListener(new ControlAdapter() {
+            @Override
+            public void controlResized(ControlEvent e) {
+                super.controlResized(e);
+            }
+        });
+
+        fTreeViewer = viewer;
+        return fTreeViewer;
+    }
+
+    @Override
+    public void setFocus() {
+        if (fXYViewer != null) {
+            fXYViewer.getControl().setFocus();
+        }
+    }
+
+    /**
+     * 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();
+            }
+        }
+    }
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageXYViewer.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/CpuUsageXYViewer.java
new file mode 100644 (file)
index 0000000..be5c552
--- /dev/null
@@ -0,0 +1,286 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 É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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.cpuusage;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.Arrays;
+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;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+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.
+ *
+ * @author Geneviève Bastien
+ */
+public class CpuUsageXYViewer extends TmfCommonXLineChartViewer {
+
+    private KernelCpuUsageAnalysis fModule = null;
+
+    /* Maps a thread ID to a list of y values */
+    private final Map<String, double[]> fYValues = new LinkedHashMap<>();
+    /*
+     * To avoid up and downs CPU usage when process is in and out of CPU
+     * frequently, use a smaller resolution to get better averages.
+     */
+    private static final double RESOLUTION = 0.4;
+
+    // Timeout between updates in the updateData thread
+    private static final long BUILD_UPDATE_TIMEOUT = 500;
+
+    private long fSelectedThread = -1;
+
+    private final @NonNull Set<@NonNull Integer> fCpus = new TreeSet<>();
+
+    /**
+     * Constructor
+     *
+     * @param parent
+     *            parent composite
+     */
+    public CpuUsageXYViewer(Composite parent) {
+        super(parent, Messages.CpuUsageXYViewer_Title, Messages.CpuUsageXYViewer_TimeXAxis, Messages.CpuUsageXYViewer_CpuYAxis);
+        setResolution(RESOLUTION);
+    }
+
+    @Override
+    protected void initializeDataSource() {
+        ITmfTrace trace = getTrace();
+        if (trace != null) {
+            fModule = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelCpuUsageAnalysis.class, KernelCpuUsageAnalysis.ID);
+            if (fModule == null) {
+                return;
+            }
+            fModule.schedule();
+        }
+    }
+
+    private static double[] zeroFill(int nb) {
+        double[] arr = new double[nb];
+        Arrays.fill(arr, 0.0);
+        return arr;
+    }
+
+    @Override
+    protected void updateData(long start, long end, int nb, IProgressMonitor monitor) {
+        try {
+            if (getTrace() == null || fModule == null) {
+                return;
+            }
+            fModule.waitForInitialization();
+            ITmfStateSystem ss = fModule.getStateSystem();
+            if (ss == null) {
+                return;
+            }
+            double[] xvalues = getXAxis(start, end, nb);
+            if (xvalues.length == 0) {
+                return;
+            }
+            setXAxis(xvalues);
+
+            boolean complete = false;
+            long currentEnd = start;
+
+            while (!complete && currentEnd < end) {
+
+                if (monitor.isCanceled()) {
+                    return;
+                }
+
+                long traceStart = getStartTime();
+                long traceEnd = getEndTime();
+                long offset = getTimeOffset();
+                long selectedThread = fSelectedThread;
+
+                complete = ss.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
+                currentEnd = ss.getCurrentEndTime();
+
+                /* Initialize the data */
+                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));
+                String stringSelectedThread = Long.toString(selectedThread);
+                if (selectedThread != -1) {
+                    fYValues.put(stringSelectedThread, zeroFill(xvalues.length));
+                }
+
+                for (Entry<String, Long> entry : cpuUsageMap.entrySet()) {
+                    /*
+                     * Process only entries representing the total of all CPUs
+                     * and that have time on CPU
+                     */
+                    if (entry.getValue() == 0) {
+                        continue;
+                    }
+                    if (!entry.getKey().startsWith(KernelCpuUsageAnalysis.TOTAL)) {
+                        continue;
+                    }
+                    String[] strings = entry.getKey().split(KernelCpuUsageAnalysis.SPLIT_STRING, 2);
+
+                    if ((strings.length > 1) && !(strings[1].equals(KernelCpuUsageAnalysis.TID_ZERO))) {
+                        /* This is the total cpu usage for a thread */
+                        totalEntries.put(strings[1], entry.getKey());
+                    }
+                }
+
+                double prevX = xvalues[0] - 1;
+                long prevTime = (long) prevX + offset;
+                /*
+                 * make sure that time is in the trace range after double to
+                 * long conversion
+                 */
+                prevTime = Math.max(traceStart, prevTime);
+                prevTime = Math.min(traceEnd, prevTime);
+                /* Get CPU usage statistics for each x value */
+                for (int i = 0; i < xvalues.length; i++) {
+                    if (monitor.isCanceled()) {
+                        return;
+                    }
+                    long totalCpu = 0;
+                    double x = xvalues[i];
+                    long time = (long) x + offset;
+                    time = Math.max(traceStart, time);
+                    time = Math.min(traceEnd, time);
+                    if (time == prevTime) {
+                        /*
+                         * we need at least 1 time unit to be able to get cpu
+                         * usage when zoomed in
+                         */
+                        prevTime = time - 1;
+                    }
+
+                    cpuUsageMap = fModule.getCpuUsageInRange(fCpus, prevTime, time);
+
+                    /*
+                     * Calculate the sum of all total entries, and add a data
+                     * point to the selected one
+                     */
+                    for (Entry<String, String> entry : totalEntries.entrySet()) {
+                        Long cpuEntry = cpuUsageMap.get(entry.getValue());
+                        cpuEntry = cpuEntry != null ? cpuEntry : 0L;
+
+                        totalCpu += cpuEntry;
+
+                        if (entry.getKey().equals(stringSelectedThread)) {
+                            /* This is the total cpu usage for a thread */
+                            double[] key = checkNotNull(fYValues.get(entry.getKey()));
+                            key[i] = (double) cpuEntry / (double) (time - prevTime) * 100;
+                        }
+
+                    }
+                    double[] key = checkNotNull(fYValues.get(Messages.CpuUsageXYViewer_Total));
+                    key[i] = (double) totalCpu / (double) (time - prevTime) * 100;
+                    prevTime = time;
+                }
+                for (Entry<String, double[]> entry : fYValues.entrySet()) {
+                    setSeries(entry.getKey(), entry.getValue());
+                }
+                if (monitor.isCanceled()) {
+                    return;
+                }
+                updateDisplay();
+            }
+        } catch (StateValueTypeException e) {
+            Activator.getDefault().logError("Error updating the data of the CPU usage view", e); //$NON-NLS-1$
+        }
+
+    }
+
+    /**
+     * Set the selected thread ID, which will be graphed in this viewer
+     *
+     * @param tid
+     *            The selected thread ID
+     */
+    public void setSelectedThread(long tid) {
+        cancelUpdate();
+        deleteSeries(Long.toString(fSelectedThread));
+        fSelectedThread = tid;
+        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);
+    }
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/Messages.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/Messages.java
new file mode 100644 (file)
index 0000000..3e81d0c
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 É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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.cpuusage;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Messages used in the LTTng kernel CPU usage view and viewers.
+ *
+ * @author Geneviève Bastien
+ */
+@SuppressWarnings("javadoc")
+public class Messages extends NLS {
+
+    private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.cpuusage.messages"; //$NON-NLS-1$
+
+    public static String CpuUsageComposite_ColumnPercent;
+    public static String CpuUsageComposite_ColumnProcess;
+    public static String CpuUsageComposite_ColumnTID;
+    public static String CpuUsageComposite_ColumnTime;
+    public static String CpuUsageComposite_TextPercent;
+    public static String CpuUsageComposite_TextTime;
+    public static String CpuUsageView_Title;
+    public static String CpuUsageXYViewer_CpuYAxis;
+    public static String CpuUsageXYViewer_TimeXAxis;
+    public static String CpuUsageXYViewer_Title;
+    public static String CpuUsageXYViewer_Total;
+
+    static {
+        // initialize resource bundle
+        NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+    }
+
+    private Messages() {
+    }
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/messages.properties b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/cpuusage/messages.properties
new file mode 100644 (file)
index 0000000..bf8a799
--- /dev/null
@@ -0,0 +1,23 @@
+###############################################################################
+# Copyright (c) 2014, 2015 É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 accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Geneviève Bastien - Initial API and implementation
+###############################################################################
+
+CpuUsageComposite_ColumnPercent=%
+CpuUsageComposite_ColumnProcess=Process
+CpuUsageComposite_ColumnTID=TID
+CpuUsageComposite_ColumnTime=Time
+CpuUsageComposite_TextPercent=%1$.3f %%
+CpuUsageComposite_TextTime={0} ns
+CpuUsageView_Title=CPU Usage
+CpuUsageXYViewer_CpuYAxis=% CPU
+CpuUsageXYViewer_TimeXAxis=Time
+CpuUsageXYViewer_Title=CPU usage
+CpuUsageXYViewer_Total=Total
This page took 0.060634 seconds and 5 git commands to generate.