lttng: Add latency statistics
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Thu, 15 Oct 2015 12:55:28 +0000 (08:55 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Fri, 23 Oct 2015 20:02:07 +0000 (16:02 -0400)
Change-Id: I49863b3046717b3bba81443fc05305d78a80b302
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/58262
Reviewed-by: Hudson CI
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
21 files changed:
analysis/org.eclipse.tracecompass.analysis.os.linux.core/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.os.linux.core/plugin.properties
analysis/org.eclipse.tracecompass.analysis.os.linux.core/plugin.xml
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/LatencyStatistics.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/LatencyStatisticsAnalysisModule.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/package-info.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/icons/eview16/statistics_view.gif [new file with mode: 0755]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/plugin.properties
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/plugin.xml
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/LatencyTableViewer.java
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/Messages.java
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/messages.properties
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/AbstractLatencyStatisticsView.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/AbstractLatencyStatisticsViewer.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/LatencyStatisticsView.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/LatencyStatisticsViewer.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/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/latency/statistics/messages.properties [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/package-info.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF

index 231d9caf5777b4962e67e35a94c9412dfe3dc597..fc552e92aff265ea3aaa9388e98943d6d3713cac 100644 (file)
@@ -24,4 +24,5 @@ Export-Package: org.eclipse.tracecompass.analysis.os.linux.core.cpuusage,
  org.eclipse.tracecompass.analysis.os.linux.core.model,
  org.eclipse.tracecompass.analysis.os.linux.core.trace,
  org.eclipse.tracecompass.internal.analysis.os.linux.core;x-internal:=true,
- org.eclipse.tracecompass.internal.analysis.os.linux.core.kernelanalysis;x-friends:="org.eclipse.tracecompass.analysis.os.linux.core.tests"
+ org.eclipse.tracecompass.internal.analysis.os.linux.core.kernelanalysis;x-friends:="org.eclipse.tracecompass.analysis.os.linux.core.tests",
+ org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics;x-friends:="org.eclipse.tracecompass.analysis.os.linux.ui"
index 8866c02db35af0af006d383c8c10908a00e9b76d..588a285f7969e8aa37bb59e9bfa3035f44efe990 100644 (file)
@@ -18,4 +18,3 @@ analysis.linuxkernel = Linux Kernel Analysis
 
 analysis.cpuusage = CPU usage
 analysis.latency = Latency Analysis
-
index e431977e9f67d3b529d103db8a9e85bdc1b8a67b..87658e64e6c36123f12f33d755d05ea10df1bd0c 100644 (file)
@@ -25,7 +25,7 @@
       </module>
       <module
             analysis_module="org.eclipse.tracecompass.analysis.os.linux.core.latency.LatencyAnalysis"
-            automatic="false"
+            automatic="true"
             id="org.eclipse.tracecompass.analysis.os.linux.latency"
             name="%analysis.latency">
          <tracetype
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/LatencyStatistics.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/LatencyStatistics.java
new file mode 100644 (file)
index 0000000..a705a44
--- /dev/null
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * 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:
+ *     Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics;
+
+import org.eclipse.tracecompass.segmentstore.core.ISegment;
+
+/**
+ * Class to calculate simple latency statistics (min, max, average)
+ *
+ * @author Bernd Hufmann
+ */
+public class LatencyStatistics {
+    private long fMin;
+    private long fMax;
+    private long fSum;
+    private long fNbSegments;
+
+    /**
+     * Constructor
+     */
+    public LatencyStatistics() {
+        this.fMin = Long.MAX_VALUE;
+        this.fMax = Long.MIN_VALUE;
+        this.fSum = 0;
+        this.fNbSegments = 0;
+    }
+
+    /**
+     * Get minimum value
+     *
+     * @return minimum value
+     */
+    public long getMin() {
+        return fMin;
+    }
+
+    /**
+     * Get maximum value
+     *
+     * @return maximum value
+     */
+    public long getMax() {
+        return fMax;
+    }
+
+    /**
+     * Get number of segments analyzed
+     *
+     * @return number of segments analyzed
+     */
+    public long getNbSegments() {
+        return fNbSegments;
+    }
+
+    /**
+     * Gets the arithmetic average
+     *
+     * @return arithmetic average
+     */
+    public double getAverage() {
+        return ((double) fSum) / fNbSegments;
+    }
+
+    /**
+     * Update the statistics based on a given segment
+     *
+     * @param segment
+     *            the segment used for the update
+     */
+    public void update (ISegment segment) {
+        long value = segment.getLength();
+        fMin = Math.min(fMin, value);
+        fMax = Math.max(fMax, value);
+        fSum += value;
+        fNbSegments++;
+    }
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/LatencyStatisticsAnalysisModule.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/LatencyStatisticsAnalysisModule.java
new file mode 100644 (file)
index 0000000..accb8e3
--- /dev/null
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * 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:
+ *     Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.analysis.os.linux.core.latency.LatencyAnalysis;
+import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCall;
+import org.eclipse.tracecompass.segmentstore.core.ISegment;
+import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Analysis module to calculate statistics of a latency analysis
+ *
+ * @author Bernd Hufmann
+ */
+public class LatencyStatisticsAnalysisModule extends TmfAbstractAnalysisModule {
+
+    /** The analysis module ID */
+    public static String ID = "org.eclipse.tracecompass.analysis.os.linux.core.latency.statistics"; //$NON-NLS-1$
+
+    private @Nullable LatencyAnalysis fLatencyModule;
+
+    private @Nullable LatencyStatistics fTotalStats;
+
+    private Map<String, LatencyStatistics> fPerSyscallStats = new HashMap<>();
+
+    @Override
+    protected Iterable<IAnalysisModule> getDependentAnalyses() {
+        ITmfTrace trace = getTrace();
+        if (trace != null) {
+            LatencyAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(trace, LatencyAnalysis.class, LatencyAnalysis.ID);
+            fLatencyModule = module;
+            return checkNotNull(ImmutableList.of((IAnalysisModule) module));
+        }
+        return super.getDependentAnalyses();
+    }
+
+    @Override
+    protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException {
+        LatencyAnalysis latency = fLatencyModule;
+        ITmfTrace trace = getTrace();
+        if ((latency == null) || (trace == null)) {
+            return false;
+        }
+        latency.waitForCompletion();
+
+        ISegmentStore<ISegment> store = latency.getResults();
+
+        if (store != null) {
+
+            boolean result = calculateTotalManual(store, monitor);
+
+            if (!result) {
+                return false;
+            }
+
+            result = calculateTotalPerSyscall(store, monitor);
+            if (!result) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private boolean calculateTotalManual(ISegmentStore<ISegment> store, IProgressMonitor monitor) {
+        LatencyStatistics total = new LatencyStatistics();
+        Iterator<ISegment> iter = store.iterator();
+        while (iter.hasNext()) {
+            if (monitor.isCanceled()) {
+                return false;
+            }
+            ISegment segment = iter.next();
+            total.update(checkNotNull(segment));
+        }
+
+        fTotalStats = total;
+        return true;
+    }
+
+    private boolean calculateTotalPerSyscall(ISegmentStore<ISegment> store, IProgressMonitor monitor) {
+        fPerSyscallStats = new HashMap<>();
+
+        Iterator<ISegment> iter = store.iterator();
+        while (iter.hasNext()) {
+            if (monitor.isCanceled()) {
+                return false;
+            }
+            ISegment segment = iter.next();
+            if (segment instanceof SystemCall) {
+                SystemCall syscall = (SystemCall) segment;
+                LatencyStatistics values = fPerSyscallStats.get(syscall.getName());
+                if (values == null) {
+                    values = new LatencyStatistics();
+                }
+                values.update(segment);
+                fPerSyscallStats.put(syscall.getName(), values);
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    protected void canceling() {
+    }
+
+    /**
+     * The total statistics
+     *
+     * @return the total statistics
+     */
+    public @Nullable LatencyStatistics getTotalStats() {
+        return fTotalStats;
+    }
+
+    /**
+     * The per syscall statistics
+     *
+     * @return the per syscall statistics
+     */
+    public Map<String, LatencyStatistics> getPerSyscallStats() {
+        return fPerSyscallStats;
+    }
+
+ }
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/package-info.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/package-info.java
new file mode 100644 (file)
index 0000000..3551485
--- /dev/null
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault
+package org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics;
index 38f1d7dcedc8a9b1982f39cdfb00d292eb4b5e18..924a63f025fd5cd414d2e740566c16c778749db6 100644 (file)
@@ -27,4 +27,5 @@ Export-Package: org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow,
  org.eclipse.tracecompass.analysis.os.linux.ui.views.resources,
  org.eclipse.tracecompass.internal.analysis.os.linux.ui;x-internal:=true,
  org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency;x-internal:=true,
- org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.resources;x-internal:=true
+ org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.resources;x-internal:=true,
+ org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics;x-internal:=true
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/icons/eview16/statistics_view.gif b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/icons/eview16/statistics_view.gif
new file mode 100755 (executable)
index 0000000..d11c996
Binary files /dev/null and b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/icons/eview16/statistics_view.gif differ
index cbf32c58757c2e8b5a751d99fc71145f84539e58..2807aa9aab2fdf29ba7b3a2f4b9d71dd6cd2180d 100644 (file)
@@ -19,4 +19,5 @@ controlflow.view.name = Control Flow
 resources.view.name = Resources
 cpuusage.view.name = CPU Usage
 latency.view.name = Latency Analysis
-latency.scatter.view.name = Latency vs Time
\ No newline at end of file
+latency.scatter.view.name = Latency vs Time
+latency.stats.view.name = Latency Statistics
index e9a758c01baef7818f87bb557135217bd8f776a0..18c1a3c6bc357bd217d2155f483f39024d6edc9f 100644 (file)
             id="org.eclipse.tracecompass.analysis.os.linux.views.latency.scatter"
             name="%latency.scatter.view.name"
             restorable="true">
+       </view>
+      <view
+            allowMultiple="false"
+            category="org.eclipse.linuxtools.lttng2.ui.views.category"
+            class="org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics.LatencyStatisticsView"
+            icon="icons/eview16/statistics_view.gif"
+            id="org.eclipse.tracecompass.analysis.os.linux.ui.views.latency.statsview"
+            name="%latency.stats.view.name"
+            restorable="true">
       </view>
    </extension>
    <extension
index 46fcfcdf2c8a5d22c5bb93bb3a326670908941d8..9c21f008c77a4527aef691dd5905ac6b56484619 100644 (file)
 package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency;
 
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.tracecompass.analysis.os.linux.core.latency.LatencyAnalysis;
 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.AbstractSegmentStoreAnalysisModule;
 import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.AbstractSegmentStoreTableViewer;
+import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics.LatencyStatisticsView;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
 
 /**
  * Displays the latency analysis data in a column table
@@ -49,4 +59,23 @@ public class LatencyTableViewer extends AbstractSegmentStoreTableViewer {
     protected @Nullable AbstractSegmentStoreAnalysisModule getSegmentStoreAnalysisModule(ITmfTrace trace) {
           return TmfTraceUtils.getAnalysisModuleOfClass(trace, LatencyAnalysis.class, LatencyAnalysis.ID);
     }
+
+    @Override
+    protected void appendToTablePopupMenu(IMenuManager manager, IStructuredSelection sel) {
+        super.appendToTablePopupMenu(manager, sel);
+        manager.add(new Separator());
+        IAction showStatisticsAction = new Action(Messages.LatencyTable_ShowStatisticsActionName) {
+            @Override
+            public void run() {
+                final IWorkbench wb = PlatformUI.getWorkbench();
+                final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
+                try {
+                    activePage.showView(LatencyStatisticsView.ID);
+                } catch (PartInitException e) {
+                }
+            }
+        };
+
+       manager.add(showStatisticsAction);
+    }
 }
index 65d3b406a684c1c66d45ef03b447136af390cab8..b810aa1975a6d8833915e205d4afa07c0ebaa69d 100644 (file)
@@ -72,6 +72,11 @@ public class Messages extends NLS {
      */
     public static String LatencyView_goToEndEvent;
 
+    /**
+     * Name of show statistics action
+     */
+    public static String LatencyTable_ShowStatisticsActionName;
+
     static {
         // initialize resource bundle
         NLS.initializeMessages(BUNDLE_NAME, Messages.class);
index 3aac0efe657d3109dc7bca98ee25a7141cec58f4..4f4349f2823e1d11002a33a7c95a9b7f0b570194 100644 (file)
@@ -1,3 +1,14 @@
+###############################################################################
+# Copyright (c) 2015 Ericsson
+#
+# 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:
+#     France Lapointe Nguyen - Initial API and implementation
+###############################################################################
 LatencyScatterGraphViewer_legend=Duration
 LatencyScatterView_title=Duration vs Time
 LatencyScatterView_xAxis=Time (ns)
@@ -8,3 +19,5 @@ LatencyTableViewer_endTime=End Time
 LatencyTableViewer_startTime=Start Time
 LatencyView_goToStartEvent=Go to start time
 LatencyView_goToEndEvent=Go to end time
+
+LatencyTable_ShowStatisticsActionName=Show statistics...
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/AbstractLatencyStatisticsView.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/AbstractLatencyStatisticsView.java
new file mode 100644 (file)
index 0000000..9e05966
--- /dev/null
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * 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:
+ *     Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ui.views.TmfView;
+
+/**
+ * Abstract view to to be extended to display latency statistics.
+ *
+ * @author Bernd Hufmann
+ *
+ */
+public abstract class AbstractLatencyStatisticsView extends TmfView {
+
+    @Nullable private AbstractLatencyStatisticsViewer fStatsViewer = null;
+
+    /**
+     * Constructor
+     */
+    public AbstractLatencyStatisticsView() {
+        super("StatisticsView"); //$NON-NLS-1$
+    }
+
+    @Override
+    public void createPartControl(@Nullable Composite parent) {
+        super.createPartControl(parent);
+        AbstractLatencyStatisticsViewer statsViewer = createLatencyStatisticsViewer(NonNullUtils.checkNotNull(parent));
+        ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
+        if (trace != null) {
+            statsViewer.loadTrace(trace);
+        }
+        fStatsViewer = statsViewer;
+    }
+
+    @Override
+    public void setFocus() {
+        AbstractLatencyStatisticsViewer statsViewer = fStatsViewer;
+        if (statsViewer != null) {
+            statsViewer.getControl().setFocus();
+        }
+    }
+
+    @Override
+    public void dispose() {
+        super.dispose();
+        AbstractLatencyStatisticsViewer statsViewer = fStatsViewer;
+        if (statsViewer != null) {
+            statsViewer.dispose();
+        }
+    }
+
+    /**
+     * Creates a latency statistics viewer instance.
+     *
+     * @param parent
+     *            the parent composite to create the viewer in.
+     * @return the latency statistics viewer implementation
+     */
+    protected abstract AbstractLatencyStatisticsViewer createLatencyStatisticsViewer(Composite parent);
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/AbstractLatencyStatisticsViewer.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/AbstractLatencyStatisticsViewer.java
new file mode 100644 (file)
index 0000000..4f65006
--- /dev/null
@@ -0,0 +1,264 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * 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:
+ *     Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics.LatencyStatistics;
+import org.eclipse.tracecompass.internal.analysis.os.linux.ui.Activator;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+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.TmfTreeColumnData;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry;
+
+/**
+ * An abstract tree viewer implementation for displaying latency statistics
+ *
+ * @author Bernd Hufmann
+ *
+ */
+public abstract class AbstractLatencyStatisticsViewer extends AbstractTmfTreeViewer {
+
+    private static final NumberFormat FORMATTER = checkNotNull(NumberFormat.getNumberInstance(Locale.getDefault()));
+
+    @Nullable private TmfAbstractAnalysisModule fModule;
+
+    private static final String[] COLUMN_NAMES = new String[] {
+            checkNotNull(Messages.LatencyStatistics_LevelLabel),
+            checkNotNull(Messages.LatencyStatistics_MinLabel),
+            checkNotNull(Messages.LatencyStatistics_MaxLabel),
+            checkNotNull(Messages.LatencyStatistics_AverageLabel)
+    };
+
+    /**
+     * Constructor
+     *
+     * @param parent
+     *            the parent composite
+     */
+    public AbstractLatencyStatisticsViewer(Composite parent) {
+        super(parent, false);
+        setLabelProvider(new LatencyLabelProvider());
+    }
+
+    /** Provides label for the Latency tree viewer cells */
+    protected static class LatencyLabelProvider extends TreeLabelProvider {
+
+        @Override
+        public String getColumnText(@Nullable Object element, int columnIndex) {
+            String value = "";  //$NON-NLS-1$
+            if (element instanceof HiddenTreeViewerEntry) {
+                if (columnIndex == 0) {
+                    value = ((HiddenTreeViewerEntry) element).getName();
+                }
+            } else {
+                LatencyTreeViewerEntry obj = (LatencyTreeViewerEntry) element;
+                if (obj != null) {
+                    if (columnIndex == 0) {
+                        value = String.valueOf(obj.getName());
+                    } else if (columnIndex == 1) {
+                        value = toFormattedString(obj.getEntry().getMin());
+                    } else if (columnIndex == 2) {
+                        value = String.valueOf(toFormattedString(obj.getEntry().getMax()));
+                    } else if (columnIndex == 3) {
+                        value = String.valueOf(toFormattedString(obj.getEntry().getAverage()));
+                    }
+                }
+            }
+            return checkNotNull(value);
+        }
+    }
+
+    /**
+     * Creates the statistics analysis module
+     *
+     * @return the statistics analysis module
+     */
+    @Nullable protected abstract TmfAbstractAnalysisModule createStatisticsAnalysiModule();
+
+    /**
+     * Gets the statistics analysis module
+     * @return the statistics analysis module
+     */
+    @Nullable public TmfAbstractAnalysisModule getStatisticsAnalysisModule() {
+        return fModule;
+    }
+
+    @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(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) {
+                        if ((e1 == null) || (e2 == null)) {
+                            return 0;
+                        }
+
+                        LatencyTreeViewerEntry n1 = (LatencyTreeViewerEntry) e1;
+                        LatencyTreeViewerEntry n2 = (LatencyTreeViewerEntry) e2;
+
+                        return n1.getName().compareTo(n2.getName());
+
+                    }
+                });
+                columns.add(column);
+                column = new TmfTreeColumnData(COLUMN_NAMES[1]);
+                column.setComparator(new ViewerComparator() {
+                    @Override
+                    public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) {
+                        if ((e1 == null) || (e2 == null)) {
+                            return 0;
+                        }
+
+                        LatencyTreeViewerEntry n1 = (LatencyTreeViewerEntry) e1;
+                        LatencyTreeViewerEntry n2 = (LatencyTreeViewerEntry) e2;
+
+                        return Long.compare(n1.getEntry().getMin(), n2.getEntry().getMin());
+
+                    }
+                });
+                columns.add(column);
+                column = new TmfTreeColumnData(COLUMN_NAMES[2]);
+                column.setComparator(new ViewerComparator() {
+                    @Override
+                    public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) {
+                        if ((e1 == null) || (e2 == null)) {
+                            return 0;
+                        }
+
+                        LatencyTreeViewerEntry n1 = (LatencyTreeViewerEntry) e1;
+                        LatencyTreeViewerEntry n2 = (LatencyTreeViewerEntry) e2;
+
+                        return Long.compare(n1.getEntry().getMax(), n2.getEntry().getMax());
+
+                    }
+                });
+                columns.add(column);
+                column = new TmfTreeColumnData(COLUMN_NAMES[3]);
+                column.setComparator(new ViewerComparator() {
+                    @Override
+                    public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) {
+                        if ((e1 == null) || (e2 == null)) {
+                            return 0;
+                        }
+
+                        LatencyTreeViewerEntry n1 = (LatencyTreeViewerEntry) e1;
+                        LatencyTreeViewerEntry n2 = (LatencyTreeViewerEntry) e2;
+
+                        return Double.compare(n1.getEntry().getAverage(), n2.getEntry().getAverage());
+
+                    }
+                });
+                columns.add(column);
+
+                return columns;
+            }
+
+        };
+    }
+
+
+    @Override
+    public void initializeDataSource() {
+        /* Should not be called while trace is still null */
+        ITmfTrace trace = checkNotNull(getTrace());
+        TmfAbstractAnalysisModule module = createStatisticsAnalysiModule();
+        if (module == null) {
+            return;
+        }
+        try {
+            module.setTrace(trace);
+            module.schedule();
+            fModule = module;
+        } catch (TmfAnalysisException e) {
+            Activator.getDefault().logError("Error initializing statistics analysis module", e); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Formats a double value string
+     *
+     * @param value
+     *            a value to format
+     * @return formatted value
+     */
+    protected static String toFormattedString(double value) {
+        // The cast to long is needed because the formatter cannot truncate the number.
+        String percentageString = checkNotNull(String.format("%s", FORMATTER.format(value))); //$NON-NLS-1$
+        return percentageString;
+    }
+
+    /**
+     * Class for defining an entry in the statistics tree.
+     */
+    protected class LatencyTreeViewerEntry extends TmfTreeViewerEntry  {
+        private LatencyStatistics fEntry;
+
+        /**
+         * Constructor
+         *
+         * @param name
+         *            name of entry
+         *
+         * @param entry
+         *            latency statistics object
+         */
+        public LatencyTreeViewerEntry(String name, LatencyStatistics entry) {
+            super(name);
+            fEntry = entry;
+        }
+
+        /**
+         * Gets the statistics object
+         *
+         * @return statistics object
+         */
+        public LatencyStatistics getEntry() {
+            return fEntry;
+        }
+
+    }
+
+    /**
+     * Class to define a level in the tree that doesn't have any values.
+     */
+    protected class HiddenTreeViewerEntry extends LatencyTreeViewerEntry {
+        /**
+         * Constructor
+         *
+         * @param name
+         *            the name of the level
+         */
+        public HiddenTreeViewerEntry(String name) {
+            super(name, new LatencyStatistics());
+        }
+    }
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/LatencyStatisticsView.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/LatencyStatisticsView.java
new file mode 100644 (file)
index 0000000..d4b8377
--- /dev/null
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * 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:
+ *     Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * View to display latency statistics.
+ *
+ * @author Bernd Hufmann
+ *
+ */
+public class LatencyStatisticsView extends AbstractLatencyStatisticsView {
+
+    /** The view ID*/
+    public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.ui.views.latency.statsview"; //$NON-NLS-1$
+
+    @Override
+    protected AbstractLatencyStatisticsViewer createLatencyStatisticsViewer(Composite parent) {
+        return checkNotNull((AbstractLatencyStatisticsViewer) new LatencyStatisticsViewer(checkNotNull(parent)));
+    }
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/LatencyStatisticsViewer.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/LatencyStatisticsViewer.java
new file mode 100644 (file)
index 0000000..a3443fe
--- /dev/null
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * 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:
+ *     Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics.LatencyStatistics;
+import org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics.LatencyStatisticsAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry;
+
+/**
+ * A tree viewer implementation for displaying latency statistics
+ *
+ * @author Bernd Hufmann
+ *
+ */
+public class LatencyStatisticsViewer extends AbstractLatencyStatisticsViewer {
+
+    private static final String SYSCALL_LEVEL = checkNotNull(Messages.LatencyStatistics_SyscallLevelName);
+
+    /**
+     * Constructor
+     *
+     * @param parent
+     *            the parent composite
+     */
+    public LatencyStatisticsViewer(Composite parent) {
+        super(parent);
+    }
+
+    /**
+     * Gets the statistics analysis module
+     *
+     * @return the statistics analysis module
+     */
+    @Override
+    @Nullable protected TmfAbstractAnalysisModule createStatisticsAnalysiModule() {
+        LatencyStatisticsAnalysisModule module = new LatencyStatisticsAnalysisModule();
+        return module;
+    }
+
+    @Override
+    @Nullable protected ITmfTreeViewerEntry updateElements(long start, long end, boolean isSelection) {
+        if (isSelection || (start == end)) {
+            return null;
+        }
+
+        TmfAbstractAnalysisModule analysisModule = getStatisticsAnalysisModule();
+
+        if (getTrace() == null || !(analysisModule instanceof LatencyStatisticsAnalysisModule)) {
+            return null;
+        }
+
+        LatencyStatisticsAnalysisModule module = (LatencyStatisticsAnalysisModule) analysisModule;
+
+        module.waitForCompletion();
+
+        LatencyStatistics entry = module.getTotalStats();
+
+        TmfTreeViewerEntry root = new TmfTreeViewerEntry(""); //$NON-NLS-1$
+        List<ITmfTreeViewerEntry> entryList = root.getChildren();
+
+        TmfTreeViewerEntry child = new LatencyTreeViewerEntry(checkNotNull(Messages.LatencyStatistics_TotalLabel), checkNotNull(entry));
+        entryList.add(child);
+
+        HiddenTreeViewerEntry syscalls = new HiddenTreeViewerEntry(SYSCALL_LEVEL);
+        child.addChild(syscalls);
+
+        Map<String, LatencyStatistics> perSyscallStats = module.getPerSyscallStats();
+
+        Iterator<Entry<String, LatencyStatistics>> stats = perSyscallStats.entrySet().iterator();
+        while (stats.hasNext()) {
+            Entry<String, LatencyStatistics> statsEntry = stats.next();
+            syscalls.addChild(new LatencyTreeViewerEntry(checkNotNull(statsEntry.getKey()), checkNotNull(statsEntry.getValue())));
+        }
+        return root;
+    }
+
+}
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/Messages.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/Messages.java
new file mode 100644 (file)
index 0000000..9f9d6c8
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * 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:
+ *   Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Messages used in the LTTng kernel CPU usage view and viewers.
+ *
+ * @author Bernd Hufmann
+ */
+@NonNullByDefault(false)
+public class Messages extends NLS {
+
+    private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics.messages"; //$NON-NLS-1$
+
+    /** Name of the system call level in statistics tree */
+    public static String LatencyStatistics_SyscallLevelName;
+    /** Name of level column */
+    public static String LatencyStatistics_LevelLabel;
+    /** Name of the minimum column */
+    public static String LatencyStatistics_MinLabel;
+    /** Name of maximum column */
+    public static String LatencyStatistics_MaxLabel;
+    /** Name of average column */
+    public static String LatencyStatistics_AverageLabel;
+    /** Name of Total statistics */
+    public static String LatencyStatistics_TotalLabel;
+
+    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/latency/statistics/messages.properties b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/messages.properties
new file mode 100644 (file)
index 0000000..e4feb45
--- /dev/null
@@ -0,0 +1,19 @@
+###############################################################################
+# Copyright (c) 2015 Ericsson
+#
+# 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:
+#     Bernd Hufmann - Initial API and implementation
+###############################################################################
+
+LatencyStatistics_SyscallLevelName=System Calls
+LatencyStatistics_LevelLabel=Level
+LatencyStatistics_MinLabel=Minimum
+LatencyStatistics_MaxLabel=Maximum
+LatencyStatistics_AverageLabel=Average
+LatencyStatistics_TotalLabel=Total
\ No newline at end of file
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/package-info.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/package-info.java
new file mode 100644 (file)
index 0000000..74f584d
--- /dev/null
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics;
index cfa50dca6ab96eb4cc5630193f7550f42feba8d8..d871c7893b824b0b8b0ac38ebf2732e59bd2eee1 100644 (file)
@@ -21,7 +21,7 @@ Require-Bundle: org.eclipse.core.expressions,
  org.swtchart,
  com.ibm.icu,
  org.eclipse.linuxtools.dataviewers.piechart,
- org.eclipse.tracecompass.segmentstore.core;bundle-version="1.0.0"
+ org.eclipse.tracecompass.segmentstore.core
 Export-Package: org.eclipse.tracecompass.internal.tmf.ui;x-friends:="org.eclipse.tracecompass.tmf.ui.tests,org.eclipse.tracecompass.tmf.ctf.ui.tests",
  org.eclipse.tracecompass.internal.tmf.ui.commands;x-internal:=true,
  org.eclipse.tracecompass.internal.tmf.ui.dialogs;x-internal:=true,
This page took 0.038123 seconds and 5 git commands to generate.