From: Jean-Christian Kouame Date: Wed, 23 Mar 2016 15:29:32 +0000 (-0400) Subject: tmf : Add latency statistics view for the pattern analysis X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=5b901f94c336f41dd0fd17fb586c4f98f857b96b;p=deliverable%2Ftracecompass.git tmf : Add latency statistics view for the pattern analysis Change-Id: Ie4fe7e7e68e8e3b074ddb5f0b3ec97a554652166 Signed-off-by: Jean-Christian Kouame Reviewed-on: https://git.eclipse.org/r/67842 Reviewed-by: Genevieve Bastien Tested-by: Genevieve Bastien Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam --- diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/SystemCallLatencyStatisticsAnalysisModule.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/SystemCallLatencyStatisticsAnalysisModule.java index 7408a5865a..46da158bbe 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/SystemCallLatencyStatisticsAnalysisModule.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/SystemCallLatencyStatisticsAnalysisModule.java @@ -16,7 +16,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCall; import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCallLatencyAnalysis; import org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider; -import org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.statistics.AbstractSegmentStatisticsAnalysis; +import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.AbstractSegmentStatisticsAnalysis; import org.eclipse.tracecompass.segmentstore.core.ISegment; import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/SystemCallLatencyStatisticsView.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/SystemCallLatencyStatisticsView.java index daf9f9e3d0..509809edb8 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/SystemCallLatencyStatisticsView.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/SystemCallLatencyStatisticsView.java @@ -12,8 +12,8 @@ package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics; import org.eclipse.swt.widgets.Composite; -import org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsView; -import org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsViewer; +import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsView; +import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsViewer; /** * View to display latency statistics. diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/SystemCallLatencyStatisticsViewer.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/SystemCallLatencyStatisticsViewer.java index 013b5c5fbd..49e8b376ff 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/SystemCallLatencyStatisticsViewer.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/SystemCallLatencyStatisticsViewer.java @@ -19,9 +19,9 @@ import java.util.Map.Entry; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.swt.widgets.Composite; +import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics; +import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsViewer; import org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics.SystemCallLatencyStatisticsAnalysisModule; -import org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics; -import org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsViewer; 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; diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core.tests/src/org/eclipse/tracecompass/analysis/timing/core/tests/segmentstore/statistics/SegmentStoreStatisticsTest.java b/analysis/org.eclipse.tracecompass.analysis.timing.core.tests/src/org/eclipse/tracecompass/analysis/timing/core/tests/segmentstore/statistics/SegmentStoreStatisticsTest.java index 67338a319d..2bda6263ac 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.core.tests/src/org/eclipse/tracecompass/analysis/timing/core/tests/segmentstore/statistics/SegmentStoreStatisticsTest.java +++ b/analysis/org.eclipse.tracecompass.analysis.timing.core.tests/src/org/eclipse/tracecompass/analysis/timing/core/tests/segmentstore/statistics/SegmentStoreStatisticsTest.java @@ -19,7 +19,7 @@ import java.util.Random; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCall; import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCall.InitialInfo; -import org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics; +import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics; import org.eclipse.tracecompass.segmentstore.core.ISegment; import org.junit.Test; diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core/META-INF/MANIFEST.MF b/analysis/org.eclipse.tracecompass.analysis.timing.core/META-INF/MANIFEST.MF index 0938c3bfaf..97d6201df7 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.core/META-INF/MANIFEST.MF +++ b/analysis/org.eclipse.tracecompass.analysis.timing.core/META-INF/MANIFEST.MF @@ -15,11 +15,7 @@ Require-Bundle: org.eclipse.ui, org.eclipse.tracecompass.tmf.core, org.eclipse.tracecompass.segmentstore.core Export-Package: org.eclipse.tracecompass.analysis.timing.core.segmentstore, - org.eclipse.tracecompass.internal.analysis.timing.core, - org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.statistics; - x-friends:="org.eclipse.tracecompass.analysis.os.linux.ui, - org.eclipse.tracecompass.analysis.timing.ui, - org.eclipse.tracecompass.analysis.timing.core.tests, - org.eclipse.tracecompass.analysis.os.linux.core" + org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics, + org.eclipse.tracecompass.internal.analysis.timing.core Import-Package: com.google.common.collect, com.google.common.hash diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/AbstractSegmentStatisticsAnalysis.java b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/AbstractSegmentStatisticsAnalysis.java new file mode 100644 index 0000000000..efbd8b43ae --- /dev/null +++ b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/AbstractSegmentStatisticsAnalysis.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (c) 2016 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 + *******************************************************************************/ +package org.eclipse.tracecompass.analysis.timing.core.segmentstore.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.timing.core.segmentstore.ISegmentStoreProvider; +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 com.google.common.collect.ImmutableList; + +/** + * Abstract analysis to build statistics data for a segment store + * + * @author Jean-Christian Kouame + */ +public abstract class AbstractSegmentStatisticsAnalysis extends TmfAbstractAnalysisModule { + + private @Nullable IAnalysisModule fSegmentStoreProviderModule; + + private @Nullable SegmentStoreStatistics fTotalStats; + + private @Nullable Map fPerSegmentTypeStats; + + @Override + protected Iterable getDependentAnalyses() { + ITmfTrace trace = getTrace(); + if (trace != null) { + ISegmentStoreProvider provider = getSegmentProviderAnalysis(trace); + if (provider instanceof IAnalysisModule) { + fSegmentStoreProviderModule = (IAnalysisModule) provider; + return ImmutableList.of((IAnalysisModule) provider); + } + } + return super.getDependentAnalyses(); + } + + @Override + protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException { + IAnalysisModule segmentStoreProviderModule = fSegmentStoreProviderModule; + ITmfTrace trace = getTrace(); + if (!(segmentStoreProviderModule instanceof ISegmentStoreProvider) || (trace == null)) { + return false; + } + segmentStoreProviderModule.waitForCompletion(); + + ISegmentStore segStore = ((ISegmentStoreProvider) segmentStoreProviderModule).getSegmentStore(); + + if (segStore != null) { + + boolean result = calculateTotalManual(segStore, monitor); + + if (!result) { + return false; + } + + result = calculateTotalPerType(segStore, monitor); + if (!result) { + return false; + } + } + return true; + } + + private boolean calculateTotalManual(ISegmentStore store, IProgressMonitor monitor) { + SegmentStoreStatistics total = new SegmentStoreStatistics(); + Iterator 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 calculateTotalPerType(ISegmentStore store, IProgressMonitor monitor) { + Map perSegmentTypeStats = new HashMap<>(); + + Iterator iter = store.iterator(); + while (iter.hasNext()) { + if (monitor.isCanceled()) { + return false; + } + ISegment segment = iter.next(); + String segmentType = getSegmentType(segment); + if (segmentType != null) { + SegmentStoreStatistics values = perSegmentTypeStats.get(segmentType); + if (values == null) { + values = new SegmentStoreStatistics(); + } + values.update(segment); + perSegmentTypeStats.put(segmentType, values); + } + } + fPerSegmentTypeStats = perSegmentTypeStats; + return true; + } + + /** + * Get the type of a segment. Statistics per type will use this type as a + * key + * + * @param segment + * the segment for which to get the type + * @return The type of the segment + */ + protected abstract @Nullable String getSegmentType(ISegment segment); + + /** + * Find the segment store provider used for this analysis + * + * @param trace + * The active trace + * + * @return The segment store provider + */ + protected abstract @Nullable ISegmentStoreProvider getSegmentProviderAnalysis(ITmfTrace trace); + + @Override + protected void canceling() { + } + + /** + * The total statistics + * + * @return the total statistics + */ + public @Nullable SegmentStoreStatistics getTotalStats() { + return fTotalStats; + } + + /** + * The per syscall statistics + * + * @return the per syscall statistics + */ + public @Nullable Map getPerSegmentTypeStats() { + return fPerSegmentTypeStats; + } + +} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/SegmentStoreStatistics.java b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/SegmentStoreStatistics.java new file mode 100644 index 0000000000..d1f4a1dfbd --- /dev/null +++ b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/SegmentStoreStatistics.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 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.analysis.timing.core.segmentstore.statistics; + +import org.eclipse.tracecompass.segmentstore.core.ISegment; + +/** + * Class to calculate simple segment store statistics (min, max, average) + * + * @author Bernd Hufmann + */ +public class SegmentStoreStatistics { + private long fMin; + private long fMax; + private long fNbSegments; + private double fAverage; + private double fVariance; + + /** + * Constructor + */ + public SegmentStoreStatistics() { + fMin = Long.MAX_VALUE; + fMax = Long.MIN_VALUE; + fNbSegments = 0; + fAverage = 0.0; + fVariance = 0.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 fAverage; + } + + /** + * Gets the standard deviation of the segments, uses the online algorithm + * shown here + * Wikipedia article of dec 3 2015 + * + * @return the standard deviation of the segment store, will return NaN if + * there are less than 3 elements + */ + public double getStdDev() { + return fNbSegments > 2 ? Math.sqrt(fVariance / (fNbSegments - 1)) : Double.NaN; + } + + /** + * Update the statistics based on a given segment + *

+ * This is an online algorithm and must retain a complexity of O(1) + * + * @param segment + * the segment used for the update + */ + public void update(ISegment segment) { + long value = segment.getLength(); + /* + * Min and max are trivial, as well as number of segments + */ + fMin = Math.min(fMin, value); + fMax = Math.max(fMax, value); + + fNbSegments++; + /* + * The running mean is not trivial, see proof in javadoc. + */ + double delta = value - fAverage; + fAverage += delta / fNbSegments; + fVariance += delta * (value - fAverage); + } +} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/package-info.java b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/package-info.java new file mode 100644 index 0000000000..2bb909d0b7 --- /dev/null +++ b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/package-info.java @@ -0,0 +1,11 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 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.analysis.timing.core.segmentstore.statistics; diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/AbstractSegmentStatisticsAnalysis.java b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/AbstractSegmentStatisticsAnalysis.java deleted file mode 100644 index 7a79a340f9..0000000000 --- a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/AbstractSegmentStatisticsAnalysis.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 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 - *******************************************************************************/ -package org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.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.timing.core.segmentstore.ISegmentStoreProvider; -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 com.google.common.collect.ImmutableList; - -/** - * Abstract analysis to build statistics data for a segment store - * - * @author Jean-Christian Kouame - */ -public abstract class AbstractSegmentStatisticsAnalysis extends TmfAbstractAnalysisModule { - - private @Nullable IAnalysisModule fSegmentStoreProviderModule; - - private @Nullable SegmentStoreStatistics fTotalStats; - - private @Nullable Map fPerSegmentTypeStats; - - @Override - protected Iterable getDependentAnalyses() { - ITmfTrace trace = getTrace(); - if (trace != null) { - ISegmentStoreProvider provider = getSegmentProviderAnalysis(trace); - if (provider instanceof IAnalysisModule) { - fSegmentStoreProviderModule = (IAnalysisModule) provider; - return ImmutableList.of((IAnalysisModule) provider); - } - } - return super.getDependentAnalyses(); - } - - @Override - protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException { - IAnalysisModule segmentStoreProviderModule = fSegmentStoreProviderModule; - ITmfTrace trace = getTrace(); - if (!(segmentStoreProviderModule instanceof ISegmentStoreProvider) || (trace == null)) { - return false; - } - segmentStoreProviderModule.waitForCompletion(); - - ISegmentStore segStore = ((ISegmentStoreProvider) segmentStoreProviderModule).getSegmentStore(); - - if (segStore != null) { - - boolean result = calculateTotalManual(segStore, monitor); - - if (!result) { - return false; - } - - result = calculateTotalPerType(segStore, monitor); - if (!result) { - return false; - } - } - return true; - } - - private boolean calculateTotalManual(ISegmentStore store, IProgressMonitor monitor) { - SegmentStoreStatistics total = new SegmentStoreStatistics(); - Iterator 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 calculateTotalPerType(ISegmentStore store, IProgressMonitor monitor) { - Map perSegmentTypeStats = new HashMap<>(); - - Iterator iter = store.iterator(); - while (iter.hasNext()) { - if (monitor.isCanceled()) { - return false; - } - ISegment segment = iter.next(); - String segmentType = getSegmentType(segment); - if (segmentType != null) { - SegmentStoreStatistics values = perSegmentTypeStats.get(segmentType); - if (values == null) { - values = new SegmentStoreStatistics(); - } - values.update(segment); - perSegmentTypeStats.put(segmentType, values); - } - } - fPerSegmentTypeStats = perSegmentTypeStats; - return true; - } - - /** - * Get the type of a segment. Statistics per type will use this type as a - * key - * - * @param segment - * the segment for which to get the type - * @return The type of the segment - */ - protected abstract @Nullable String getSegmentType(ISegment segment); - - /** - * Find the segment store provider used for this analysis - * - * @param trace - * The active trace - * - * @return The segment store provider - */ - protected abstract @Nullable ISegmentStoreProvider getSegmentProviderAnalysis(ITmfTrace trace); - - @Override - protected void canceling() { - } - - /** - * The total statistics - * - * @return the total statistics - */ - public @Nullable SegmentStoreStatistics getTotalStats() { - return fTotalStats; - } - - /** - * The per syscall statistics - * - * @return the per syscall statistics - */ - public @Nullable Map getPerSegmentTypeStats() { - return fPerSegmentTypeStats; - } - -} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/SegmentStoreStatistics.java b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/SegmentStoreStatistics.java deleted file mode 100644 index 892c404735..0000000000 --- a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/SegmentStoreStatistics.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 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.timing.core.segmentstore.statistics; - -import org.eclipse.tracecompass.segmentstore.core.ISegment; - -/** - * Class to calculate simple segment store statistics (min, max, average) - * - * @author Bernd Hufmann - */ -public class SegmentStoreStatistics { - private long fMin; - private long fMax; - private long fNbSegments; - private double fAverage; - private double fVariance; - - /** - * Constructor - */ - public SegmentStoreStatistics() { - fMin = Long.MAX_VALUE; - fMax = Long.MIN_VALUE; - fNbSegments = 0; - fAverage = 0.0; - fVariance = 0.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 fAverage; - } - - /** - * Gets the standard deviation of the segments, uses the online algorithm - * shown here - * Wikipedia article of dec 3 2015 - * - * @return the standard deviation of the segment store, will return NaN if - * there are less than 3 elements - */ - public double getStdDev() { - return fNbSegments > 2 ? Math.sqrt(fVariance / (fNbSegments - 1)) : Double.NaN; - } - - /** - * Update the statistics based on a given segment - *

- * This is an online algorithm and must retain a complexity of O(1) - * - * @param segment - * the segment used for the update - */ - public void update(ISegment segment) { - long value = segment.getLength(); - /* - * Min and max are trivial, as well as number of segments - */ - fMin = Math.min(fMin, value); - fMax = Math.max(fMax, value); - - fNbSegments++; - /* - * The running mean is not trivial, see proof in javadoc. - */ - double delta = value - fAverage; - fAverage += delta / fNbSegments; - fVariance += delta * (value - fAverage); - } -} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/package-info.java b/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/package-info.java deleted file mode 100644 index 8eccbb8b80..0000000000 --- a/analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/package-info.java +++ /dev/null @@ -1,11 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 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.timing.core.segmentstore.statistics; diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/META-INF/MANIFEST.MF b/analysis/org.eclipse.tracecompass.analysis.timing.ui/META-INF/MANIFEST.MF index 1e09c3b392..8a8e5d3483 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/META-INF/MANIFEST.MF +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/META-INF/MANIFEST.MF @@ -20,9 +20,9 @@ Require-Bundle: org.eclipse.ui, Export-Package: org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore, org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.density, org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.scatter, + org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics, org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table, org.eclipse.tracecompass.internal.analysis.timing.ui, org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.density, org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.scatter, - org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.statistics;x-friends:="org.eclipse.tracecompass.analysis.os.linux.ui", org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsView.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsView.java new file mode 100644 index 0000000000..069c67442f --- /dev/null +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsView.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 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.analysis.timing.ui.views.segmentstore.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 segment store statistics. + * + * @author Bernd Hufmann + * + */ +public abstract class AbstractSegmentStoreStatisticsView extends TmfView { + + @Nullable private AbstractSegmentStoreStatisticsViewer fStatsViewer = null; + + /** + * Constructor + */ + public AbstractSegmentStoreStatisticsView() { + super("StatisticsView"); //$NON-NLS-1$ + } + + @Override + public void createPartControl(@Nullable Composite parent) { + super.createPartControl(parent); + AbstractSegmentStoreStatisticsViewer statsViewer = createSegmentStoreStatisticsViewer(NonNullUtils.checkNotNull(parent)); + ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace(); + if (trace != null) { + statsViewer.loadTrace(trace); + } + fStatsViewer = statsViewer; + } + + @Override + public void setFocus() { + AbstractSegmentStoreStatisticsViewer statsViewer = fStatsViewer; + if (statsViewer != null) { + statsViewer.getControl().setFocus(); + } + } + + @Override + public void dispose() { + super.dispose(); + AbstractSegmentStoreStatisticsViewer statsViewer = fStatsViewer; + if (statsViewer != null) { + statsViewer.dispose(); + } + } + + /** + * Creates a segment store statistics viewer instance. + * + * @param parent + * the parent composite to create the viewer in. + * @return the latency statistics viewer implementation + */ + protected abstract AbstractSegmentStoreStatisticsViewer createSegmentStoreStatisticsViewer(Composite parent); + +} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java new file mode 100644 index 0000000000..30cfda37f7 --- /dev/null +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java @@ -0,0 +1,298 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 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.analysis.timing.ui.views.segmentstore.statistics; + +import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; + +import java.text.Format; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics; +import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.SubSecondTimeWithUnitFormat; +import org.eclipse.tracecompass.internal.analysis.timing.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 segment store + * statistics + * + * @author Bernd Hufmann + * + */ +public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTreeViewer { + + private static final Format FORMATTER = new SubSecondTimeWithUnitFormat(); + + @Nullable + private TmfAbstractAnalysisModule fModule; + + private static final String[] COLUMN_NAMES = new String[] { + checkNotNull(Messages.SegmentStoreStatistics_LevelLabel), + checkNotNull(Messages.SegmentStoreStatistics_Statistics_MinLabel), + checkNotNull(Messages.SegmentStoreStatistics_MaxLabel), + checkNotNull(Messages.SegmentStoreStatistics_AverageLabel), + checkNotNull(Messages.SegmentStoreStatisticsViewer_StandardDeviation) + }; + + /** + * Constructor + * + * @param parent + * the parent composite + */ + public AbstractSegmentStoreStatisticsViewer(Composite parent) { + super(parent, false); + setLabelProvider(new SegmentStoreStatisticsLabelProvider()); + } + + /** Provides label for the Segment Store tree viewer cells */ + protected static class SegmentStoreStatisticsLabelProvider 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 if (element instanceof SegmentStoreStatisticsEntry) { + SegmentStoreStatisticsEntry entry = (SegmentStoreStatisticsEntry) element; + if (columnIndex == 0) { + return String.valueOf(entry.getName()); + } + if (entry.getEntry().getNbSegments() > 0) { + if (columnIndex == 1) { + value = toFormattedString(entry.getEntry().getMin()); + } else if (columnIndex == 2) { + value = String.valueOf(toFormattedString(entry.getEntry().getMax())); + } else if (columnIndex == 3) { + value = String.valueOf(toFormattedString(entry.getEntry().getAverage())); + } else if (columnIndex == 4) { + value = String.valueOf(toFormattedString(entry.getEntry().getStdDev())); + } + } + } + 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<@Nullable TmfTreeColumnData> getColumnData() { + /* All columns are sortable */ + List<@Nullable TmfTreeColumnData> columns = new ArrayList<>(); + TmfTreeColumnData column = new TmfTreeColumnData(COLUMN_NAMES[0]); + column.setAlignment(SWT.RIGHT); + column.setComparator(new ViewerComparator() { + @Override + public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { + if ((e1 == null) || (e2 == null)) { + return 0; + } + + SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; + SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; + + return n1.getName().compareTo(n2.getName()); + + } + }); + columns.add(column); + column = new TmfTreeColumnData(COLUMN_NAMES[1]); + column.setAlignment(SWT.RIGHT); + column.setComparator(new ViewerComparator() { + @Override + public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { + if ((e1 == null) || (e2 == null)) { + return 0; + } + + SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; + SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; + + return Long.compare(n1.getEntry().getMin(), n2.getEntry().getMin()); + + } + }); + columns.add(column); + column = new TmfTreeColumnData(COLUMN_NAMES[2]); + column.setAlignment(SWT.RIGHT); + column.setComparator(new ViewerComparator() { + @Override + public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { + if ((e1 == null) || (e2 == null)) { + return 0; + } + + SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; + SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; + + return Long.compare(n1.getEntry().getMax(), n2.getEntry().getMax()); + + } + }); + columns.add(column); + column = new TmfTreeColumnData(COLUMN_NAMES[3]); + column.setAlignment(SWT.RIGHT); + column.setComparator(new ViewerComparator() { + @Override + public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { + if ((e1 == null) || (e2 == null)) { + return 0; + } + + SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; + SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; + + return Double.compare(n1.getEntry().getAverage(), n2.getEntry().getAverage()); + + } + }); + columns.add(column); + column = new TmfTreeColumnData(COLUMN_NAMES[4]); + column.setAlignment(SWT.RIGHT); + column.setComparator(new ViewerComparator() { + @Override + public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { + if ((e1 == null) || (e2 == null)) { + return 0; + } + + SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; + SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; + + return Double.compare(n1.getEntry().getStdDev(), n2.getEntry().getStdDev()); + + } + }); + columns.add(column); + column = new TmfTreeColumnData(""); //$NON-NLS-1$ + columns.add(column); + return columns; + } + + }; + } + + @Override + public void initializeDataSource() { + ITmfTrace trace = getTrace(); + if (trace != null) { + 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 = String.format("%s", FORMATTER.format(value)); //$NON-NLS-1$ + return percentageString; + } + + /** + * Class for defining an entry in the statistics tree. + */ + protected class SegmentStoreStatisticsEntry extends TmfTreeViewerEntry { + + private final SegmentStoreStatistics fEntry; + + /** + * Constructor + * + * @param name + * name of entry + * + * @param entry + * segment store statistics object + */ + public SegmentStoreStatisticsEntry(String name, SegmentStoreStatistics entry) { + super(name); + fEntry = entry; + } + + /** + * Gets the statistics object + * + * @return statistics object + */ + public SegmentStoreStatistics getEntry() { + return fEntry; + } + + } + + /** + * Class to define a level in the tree that doesn't have any values. + */ + protected class HiddenTreeViewerEntry extends SegmentStoreStatisticsEntry { + /** + * Constructor + * + * @param name + * the name of the level + */ + public HiddenTreeViewerEntry(String name) { + super(name, new SegmentStoreStatistics()); + } + } + +} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/Messages.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/Messages.java new file mode 100644 index 0000000000..9752956a28 --- /dev/null +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/Messages.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 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.analysis.timing.ui.views.segmentstore.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({}) +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics.messages"; //$NON-NLS-1$ + + /** Name of level column */ + public static String SegmentStoreStatistics_LevelLabel; + /** Name of the minimum column */ + public static String SegmentStoreStatistics_Statistics_MinLabel; + /** Name of maximum column */ + public static String SegmentStoreStatistics_MaxLabel; + /** Name of average column */ + public static String SegmentStoreStatistics_AverageLabel; + /** Name of average column */ + public static String SegmentStoreStatisticsViewer_StandardDeviation; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/messages.properties b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/messages.properties new file mode 100644 index 0000000000..61c5df5f20 --- /dev/null +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/messages.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2015, 2016 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 +############################################################################### +SegmentStoreStatistics_LevelLabel=Level +SegmentStoreStatistics_Statistics_MinLabel=Minimum +SegmentStoreStatistics_MaxLabel=Maximum +SegmentStoreStatistics_AverageLabel=Average +SegmentStoreStatisticsViewer_StandardDeviation=Standard Deviation \ No newline at end of file diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/package-info.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/package-info.java new file mode 100644 index 0000000000..c352cf5e26 --- /dev/null +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/package-info.java @@ -0,0 +1,11 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 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.analysis.timing.ui.views.segmentstore.statistics; diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsView.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsView.java deleted file mode 100644 index 0091163939..0000000000 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsView.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 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.timing.ui.views.segmentstore.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 segment store statistics. - * - * @author Bernd Hufmann - * - */ -public abstract class AbstractSegmentStoreStatisticsView extends TmfView { - - @Nullable private AbstractSegmentStoreStatisticsViewer fStatsViewer = null; - - /** - * Constructor - */ - public AbstractSegmentStoreStatisticsView() { - super("StatisticsView"); //$NON-NLS-1$ - } - - @Override - public void createPartControl(@Nullable Composite parent) { - super.createPartControl(parent); - AbstractSegmentStoreStatisticsViewer statsViewer = createSegmentStoreStatisticsViewer(NonNullUtils.checkNotNull(parent)); - ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace(); - if (trace != null) { - statsViewer.loadTrace(trace); - } - fStatsViewer = statsViewer; - } - - @Override - public void setFocus() { - AbstractSegmentStoreStatisticsViewer statsViewer = fStatsViewer; - if (statsViewer != null) { - statsViewer.getControl().setFocus(); - } - } - - @Override - public void dispose() { - super.dispose(); - AbstractSegmentStoreStatisticsViewer statsViewer = fStatsViewer; - if (statsViewer != null) { - statsViewer.dispose(); - } - } - - /** - * Creates a segment store statistics viewer instance. - * - * @param parent - * the parent composite to create the viewer in. - * @return the latency statistics viewer implementation - */ - protected abstract AbstractSegmentStoreStatisticsViewer createSegmentStoreStatisticsViewer(Composite parent); - -} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java deleted file mode 100644 index 178ee1f6bb..0000000000 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java +++ /dev/null @@ -1,298 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 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.timing.ui.views.segmentstore.statistics; - -import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; - -import java.text.Format; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.SubSecondTimeWithUnitFormat; -import org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics; -import org.eclipse.tracecompass.internal.analysis.timing.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 segment store - * statistics - * - * @author Bernd Hufmann - * - */ -public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTreeViewer { - - private static final Format FORMATTER = new SubSecondTimeWithUnitFormat(); - - @Nullable - private TmfAbstractAnalysisModule fModule; - - private static final String[] COLUMN_NAMES = new String[] { - checkNotNull(Messages.SegmentStoreStatistics_LevelLabel), - checkNotNull(Messages.SegmentStoreStatistics_Statistics_MinLabel), - checkNotNull(Messages.SegmentStoreStatistics_MaxLabel), - checkNotNull(Messages.SegmentStoreStatistics_AverageLabel), - checkNotNull(Messages.SegmentStoreStatisticsViewer_StandardDeviation) - }; - - /** - * Constructor - * - * @param parent - * the parent composite - */ - public AbstractSegmentStoreStatisticsViewer(Composite parent) { - super(parent, false); - setLabelProvider(new SegmentStoreStatisticsLabelProvider()); - } - - /** Provides label for the Segment Store tree viewer cells */ - protected static class SegmentStoreStatisticsLabelProvider 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 if (element instanceof SegmentStoreStatisticsEntry) { - SegmentStoreStatisticsEntry entry = (SegmentStoreStatisticsEntry) element; - if (columnIndex == 0) { - return String.valueOf(entry.getName()); - } - if (entry.getEntry().getNbSegments() > 0) { - if (columnIndex == 1) { - value = toFormattedString(entry.getEntry().getMin()); - } else if (columnIndex == 2) { - value = String.valueOf(toFormattedString(entry.getEntry().getMax())); - } else if (columnIndex == 3) { - value = String.valueOf(toFormattedString(entry.getEntry().getAverage())); - } else if (columnIndex == 4) { - value = String.valueOf(toFormattedString(entry.getEntry().getStdDev())); - } - } - } - 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<@Nullable TmfTreeColumnData> getColumnData() { - /* All columns are sortable */ - List<@Nullable TmfTreeColumnData> columns = new ArrayList<>(); - TmfTreeColumnData column = new TmfTreeColumnData(COLUMN_NAMES[0]); - column.setAlignment(SWT.RIGHT); - column.setComparator(new ViewerComparator() { - @Override - public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { - if ((e1 == null) || (e2 == null)) { - return 0; - } - - SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; - SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; - - return n1.getName().compareTo(n2.getName()); - - } - }); - columns.add(column); - column = new TmfTreeColumnData(COLUMN_NAMES[1]); - column.setAlignment(SWT.RIGHT); - column.setComparator(new ViewerComparator() { - @Override - public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { - if ((e1 == null) || (e2 == null)) { - return 0; - } - - SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; - SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; - - return Long.compare(n1.getEntry().getMin(), n2.getEntry().getMin()); - - } - }); - columns.add(column); - column = new TmfTreeColumnData(COLUMN_NAMES[2]); - column.setAlignment(SWT.RIGHT); - column.setComparator(new ViewerComparator() { - @Override - public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { - if ((e1 == null) || (e2 == null)) { - return 0; - } - - SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; - SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; - - return Long.compare(n1.getEntry().getMax(), n2.getEntry().getMax()); - - } - }); - columns.add(column); - column = new TmfTreeColumnData(COLUMN_NAMES[3]); - column.setAlignment(SWT.RIGHT); - column.setComparator(new ViewerComparator() { - @Override - public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { - if ((e1 == null) || (e2 == null)) { - return 0; - } - - SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; - SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; - - return Double.compare(n1.getEntry().getAverage(), n2.getEntry().getAverage()); - - } - }); - columns.add(column); - column = new TmfTreeColumnData(COLUMN_NAMES[4]); - column.setAlignment(SWT.RIGHT); - column.setComparator(new ViewerComparator() { - @Override - public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { - if ((e1 == null) || (e2 == null)) { - return 0; - } - - SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; - SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; - - return Double.compare(n1.getEntry().getStdDev(), n2.getEntry().getStdDev()); - - } - }); - columns.add(column); - column = new TmfTreeColumnData(""); //$NON-NLS-1$ - columns.add(column); - return columns; - } - - }; - } - - @Override - public void initializeDataSource() { - ITmfTrace trace = getTrace(); - if (trace != null) { - 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 = String.format("%s", FORMATTER.format(value)); //$NON-NLS-1$ - return percentageString; - } - - /** - * Class for defining an entry in the statistics tree. - */ - protected class SegmentStoreStatisticsEntry extends TmfTreeViewerEntry { - - private SegmentStoreStatistics fEntry; - - /** - * Constructor - * - * @param name - * name of entry - * - * @param entry - * segment store statistics object - */ - public SegmentStoreStatisticsEntry(String name, SegmentStoreStatistics entry) { - super(name); - fEntry = entry; - } - - /** - * Gets the statistics object - * - * @return statistics object - */ - public SegmentStoreStatistics getEntry() { - return fEntry; - } - - } - - /** - * Class to define a level in the tree that doesn't have any values. - */ - protected class HiddenTreeViewerEntry extends SegmentStoreStatisticsEntry { - /** - * Constructor - * - * @param name - * the name of the level - */ - public HiddenTreeViewerEntry(String name) { - super(name, new SegmentStoreStatistics()); - } - } - -} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/Messages.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/Messages.java deleted file mode 100644 index 1494f4b70a..0000000000 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/Messages.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 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.timing.ui.views.segmentstore.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({}) -public class Messages extends NLS { - - private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.statistics.messages"; //$NON-NLS-1$ - - /** Name of level column */ - public static String SegmentStoreStatistics_LevelLabel; - /** Name of the minimum column */ - public static String SegmentStoreStatistics_Statistics_MinLabel; - /** Name of maximum column */ - public static String SegmentStoreStatistics_MaxLabel; - /** Name of average column */ - public static String SegmentStoreStatistics_AverageLabel; - /** Name of average column */ - public static String SegmentStoreStatisticsViewer_StandardDeviation; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/messages.properties b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/messages.properties deleted file mode 100644 index 61c5df5f20..0000000000 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/messages.properties +++ /dev/null @@ -1,16 +0,0 @@ -############################################################################### -# Copyright (c) 2015, 2016 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 -############################################################################### -SegmentStoreStatistics_LevelLabel=Level -SegmentStoreStatistics_Statistics_MinLabel=Minimum -SegmentStoreStatistics_MaxLabel=Maximum -SegmentStoreStatistics_AverageLabel=Average -SegmentStoreStatisticsViewer_StandardDeviation=Standard Deviation \ No newline at end of file diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/package-info.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/package-info.java deleted file mode 100644 index ed72c6edb1..0000000000 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/package-info.java +++ /dev/null @@ -1,11 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 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.timing.ui.views.segmentstore.statistics; diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/pattern/stateprovider/XmlPatternLatencyStatisticsAnalysis.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/pattern/stateprovider/XmlPatternLatencyStatisticsAnalysis.java new file mode 100644 index 0000000000..dd6e5f3ae1 --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/pattern/stateprovider/XmlPatternLatencyStatisticsAnalysis.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2016 É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 + *******************************************************************************/ +package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider; +import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.AbstractSegmentStatisticsAnalysis; +import org.eclipse.tracecompass.segmentstore.core.ISegment; +import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder; +import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment; +import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; + +/** + * Statistic analysis for segments generated by a pattern analysis + * + * @author Jean-Christian Kouame + */ +public class XmlPatternLatencyStatisticsAnalysis extends AbstractSegmentStatisticsAnalysis { + + private final @Nullable String fPatternAnalysisId; + + /** + * Constructor + * + * @param patternAnalysisId + * The pattern analysis ID + */ + public XmlPatternLatencyStatisticsAnalysis(@Nullable String patternAnalysisId) { + fPatternAnalysisId = patternAnalysisId; + } + + @Override + protected @Nullable String getSegmentType(@NonNull ISegment segment) { + if (segment instanceof TmfXmlPatternSegment) { + TmfXmlPatternSegment patternSegment = (TmfXmlPatternSegment) segment; + return patternSegment.getName().substring(TmfXmlPatternSegmentBuilder.PATTERN_SEGMENT_NAME_PREFIX.length()); + } + return null; + } + + @Override + protected @Nullable ISegmentStoreProvider getSegmentProviderAnalysis(@NonNull ITmfTrace trace) { + return fPatternAnalysisId != null ? TmfTraceUtils.getAnalysisModuleOfClass(trace, XmlPatternAnalysis.class, fPatternAnalysisId) : null; + } +} diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/icons/eview16/statistics_view.gif b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/icons/eview16/statistics_view.gif new file mode 100755 index 0000000000..d11c996e57 Binary files /dev/null and b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/icons/eview16/statistics_view.gif differ diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/plugin.properties b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/plugin.properties index be6d59631d..96cb5374e6 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/plugin.properties +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/plugin.properties @@ -24,3 +24,4 @@ xmlxychart.view.name = XML XY Chart View latency.view.name = Latency Table latency.scatter.view.name = Latency vs Time latency.density.view.name = Latency vs Count +latency.statistic.view.name = Latency Statistics diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/plugin.xml b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/plugin.xml index b2dfa942e4..6a834b93b3 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/plugin.xml +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/plugin.xml @@ -105,5 +105,14 @@ name="%latency.density.view.name" restorable="true"> + + diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/Messages.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/Messages.java index 48963e57d8..9d8af588e1 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/Messages.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/Messages.java @@ -19,6 +19,8 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.messages"; //$NON-NLS-1$ /** Density chart title */ public static String TmfXmlAnalysisOutputSource_DensityChartTitle; + /** Statistics Table Title */ + public static String TmfXmlAnalysisOutputSource_LatencyStatisticsTitle; /** Latency table */ public static String TmfXmlAnalysisOutputSource_LatencyTable; /** Scatter graph title */ diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/messages.properties b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/messages.properties index eccaf2331e..80a6ebc831 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/messages.properties +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/messages.properties @@ -7,5 +7,6 @@ # http://www.eclipse.org/legal/epl-v10.html ############################################################################### TmfXmlAnalysisOutputSource_DensityChartTitle=Latency vs Count +TmfXmlAnalysisOutputSource_LatencyStatisticsTitle=Latency Statistics TmfXmlAnalysisOutputSource_LatencyTable=Latency Table TmfXmlAnalysisOutputSource_ScatterGraphTitle=Latency vs Time diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/latency/PatternStatisticsView.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/latency/PatternStatisticsView.java new file mode 100644 index 0000000000..13ca84d1fc --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/latency/PatternStatisticsView.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2016 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 + *******************************************************************************/ +package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsView; +import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsViewer; +import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings; +import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.XmlLatencyViewInfo; + +/** + * The statistic view for pattern latency analysis + * + * @author Jean-Christian Kouame + */ +public class PatternStatisticsView extends AbstractSegmentStoreStatisticsView { + + private PatternStatisticsViewer fViewer; + /** The view's ID */ + public static final @NonNull String ID = "org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.statistics"; //$NON-NLS-1$ + + private final XmlLatencyViewInfo fViewInfo = new XmlLatencyViewInfo(ID); + + /** + * Constructor + */ + public PatternStatisticsView() { + this.addPartPropertyListener(new IPropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent event) { + if (event.getProperty().equals(TmfXmlUiStrings.XML_LATENCY_OUTPUT_DATA)) { + Object newValue = event.getNewValue(); + if (newValue instanceof String) { + String data = (String) newValue; + fViewInfo.setViewData(data); + loadStatisticView(); + } + } + } + }); + } + + private void loadStatisticView() { + if (fViewer != null) { + fViewer.updateViewer(fViewInfo.getViewAnalysisId()); + } + } + + @Override + protected @NonNull AbstractSegmentStoreStatisticsViewer createSegmentStoreStatisticsViewer(@NonNull Composite parent) { + PatternStatisticsViewer viewer = new PatternStatisticsViewer(parent); + fViewer = viewer; + loadStatisticView(); + return viewer; + } +} diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/latency/PatternStatisticsViewer.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/latency/PatternStatisticsViewer.java new file mode 100644 index 0000000000..a0a6f16f4d --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/latency/PatternStatisticsViewer.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2016 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 + *******************************************************************************/ +package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency; + +import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics; +import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics.AbstractSegmentStoreStatisticsViewer; +import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternLatencyStatisticsAnalysis; +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 pattern latency statistics + * + * @author Jean-Christian Kouame + */ +public class PatternStatisticsViewer extends AbstractSegmentStoreStatisticsViewer { + + private String fAnalysisId; + + private static final @NonNull String PATTERN_SEGMENTS_LEVEL = "Pattern Segments"; //$NON-NLS-1$ + + /** + * Constructor + * + * @param parent + * The parent composite + */ + public PatternStatisticsViewer(@NonNull Composite parent) { + super(parent); + } + + @Override + protected @Nullable TmfAbstractAnalysisModule createStatisticsAnalysiModule() { + return new XmlPatternLatencyStatisticsAnalysis(fAnalysisId); + } + + @Override + protected ITmfTreeViewerEntry updateElements(long start, long end, boolean isSelection) { + if (isSelection || (start == end)) { + return null; + } + + TmfAbstractAnalysisModule analysisModule = getStatisticsAnalysisModule(); + + if (getTrace() == null || !(analysisModule instanceof XmlPatternLatencyStatisticsAnalysis)) { + return null; + } + + XmlPatternLatencyStatisticsAnalysis module = (XmlPatternLatencyStatisticsAnalysis) analysisModule; + + module.waitForCompletion(); + + TmfTreeViewerEntry root = new TmfTreeViewerEntry(""); //$NON-NLS-1$ + final SegmentStoreStatistics entry = module.getTotalStats(); + if (entry != null) { + + List entryList = root.getChildren(); + + TmfTreeViewerEntry child = new SegmentStoreStatisticsEntry(checkNotNull("Total"), entry); //$NON-NLS-1$ + entryList.add(child); + HiddenTreeViewerEntry segments = new HiddenTreeViewerEntry(PATTERN_SEGMENTS_LEVEL); + child.addChild(segments); + + final Map<@NonNull String, @NonNull SegmentStoreStatistics> perTypeStats = module.getPerSegmentTypeStats(); + if (perTypeStats != null) { + for (Entry<@NonNull String, @NonNull SegmentStoreStatistics> statsEntry : perTypeStats.entrySet()) { + segments.addChild(new SegmentStoreStatisticsEntry(statsEntry.getKey(), statsEntry.getValue())); + } + } + } + return root; + } + + /** + * Set the analysis ID and update the view + * + * @param analysisId + * The analysis ID + */ + public void updateViewer(String analysisId) { + if (analysisId != null) { + fAnalysisId = analysisId; + initializeDataSource(); + } + } + +} diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java index 197718a66f..c216127ac5 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java @@ -29,6 +29,7 @@ import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.Messages; import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternDensityView; import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternLatencyTableView; import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternScatterGraphView; +import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternStatisticsView; import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.xychart.XmlXYView; import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils; import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; @@ -110,7 +111,12 @@ public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener /** * Latency Density View type */ - DENSITY_VIEW(PatternDensityView.ID, Messages.TmfXmlAnalysisOutputSource_DensityChartTitle); + DENSITY_VIEW(PatternDensityView.ID, Messages.TmfXmlAnalysisOutputSource_DensityChartTitle), + + /** + * Latency Statistic View type + */ + STATISTIC_VIEW(PatternStatisticsView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyStatisticsTitle); private @NonNull String fLatencyViewId; private String fLatencyViewLabel;