analysis : Abstract the latency statistics analysis
authorJean-Christian Kouame <jean-christian.kouame@ericsson.com>
Fri, 4 Mar 2016 21:23:34 +0000 (16:23 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 23 Mar 2016 19:50:59 +0000 (15:50 -0400)
Change-Id: I452cf2f165ea74522dbd3cb98547ad2784324a73
Signed-off-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/67841
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/latency/statistics/SystemCallLatencyStatisticsAnalysisModule.java
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/SystemCallLatencyStatisticsViewer.java
analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/internal/analysis/timing/core/segmentstore/statistics/AbstractSegmentStatisticsAnalysis.java [new file with mode: 0644]

index f7e97cb5ee5d7ffe3b04875b510179426ba3d311..7408a5865a57dd2f3b8644acfaa110099481b87a 100644 (file)
  *******************************************************************************/
 package org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.annotation.NonNull;
 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.internal.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics;
+import org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider;
+import org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.statistics.AbstractSegmentStatisticsAnalysis;
 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 SystemCallLatencyStatisticsAnalysisModule extends TmfAbstractAnalysisModule {
+public class SystemCallLatencyStatisticsAnalysisModule extends AbstractSegmentStatisticsAnalysis {
 
     /** The analysis module ID */
     public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.core.latency.statistics.syscall"; //$NON-NLS-1$
 
-    private @Nullable SystemCallLatencyAnalysis fLatencyModule;
-
-    private @Nullable SegmentStoreStatistics fTotalStats;
-
-    private @Nullable Map<String, SegmentStoreStatistics> fPerSyscallStats;
-
     @Override
-    protected Iterable<IAnalysisModule> getDependentAnalyses() {
-        ITmfTrace trace = getTrace();
-        if (trace != null) {
-            SystemCallLatencyAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(trace, SystemCallLatencyAnalysis.class, SystemCallLatencyAnalysis.ID);
-            if (module != null) {
-                fLatencyModule = module;
-                return ImmutableList.of((IAnalysisModule) module);
-            }
-        }
-        return super.getDependentAnalyses();
-    }
-
-    @Override
-    protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException {
-        SystemCallLatencyAnalysis latency = fLatencyModule;
-        ITmfTrace trace = getTrace();
-        if ((latency == null) || (trace == null)) {
-            return false;
-        }
-        latency.waitForCompletion();
-
-        ISegmentStore<ISegment> segStore = latency.getSegmentStore();
-
-        if (segStore != null) {
-
-            boolean result = calculateTotalManual(segStore, monitor);
-
-            if (!result) {
-                return false;
-            }
-
-            result = calculateTotalPerSyscall(segStore, monitor);
-            if (!result) {
-                return false;
-            }
+    protected @Nullable String getSegmentType(@NonNull ISegment segment) {
+        if (segment instanceof SystemCall) {
+            SystemCall syscall = (SystemCall) segment;
+            return syscall.getName();
         }
-        return true;
-    }
-
-    private boolean calculateTotalManual(ISegmentStore<ISegment> store, IProgressMonitor monitor) {
-        SegmentStoreStatistics total = new SegmentStoreStatistics();
-        Iterator<ISegment> iter = store.iterator();
-        while (iter.hasNext()) {
-            if (monitor.isCanceled()) {
-                return false;
-            }
-            ISegment segment = iter.next();
-            total.update(segment);
-        }
-        fTotalStats = total;
-        return true;
-    }
-
-    private boolean calculateTotalPerSyscall(ISegmentStore<ISegment> store, IProgressMonitor monitor) {
-        Map<String, SegmentStoreStatistics> perSyscallStats = 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;
-                SegmentStoreStatistics values = perSyscallStats.get(syscall.getName());
-                if (values == null) {
-                    values = new SegmentStoreStatistics();
-                }
-                values.update(segment);
-                perSyscallStats.put(syscall.getName(), values);
-            }
-        }
-        fPerSyscallStats = perSyscallStats;
-        return true;
+        return null;
     }
 
     @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<String, SegmentStoreStatistics> getPerSyscallStats() {
-        return fPerSyscallStats;
+    protected @Nullable ISegmentStoreProvider getSegmentProviderAnalysis(@NonNull ITmfTrace trace) {
+        return TmfTraceUtils.getAnalysisModuleOfClass(trace, SystemCallLatencyAnalysis.class, SystemCallLatencyAnalysis.ID);
     }
 
- }
+}
index 45e28fcf5fe68e6228b2939410ea0451bcb51dbd..013b5c5fbdce00ea66200acbbe6af2586c6d82c0 100644 (file)
@@ -84,7 +84,7 @@ public class SystemCallLatencyStatisticsViewer extends AbstractSegmentStoreStati
             HiddenTreeViewerEntry syscalls = new HiddenTreeViewerEntry(SYSCALL_LEVEL);
             child.addChild(syscalls);
 
-            Map<String, SegmentStoreStatistics> perSyscallStats = module.getPerSyscallStats();
+            Map<String, SegmentStoreStatistics> perSyscallStats = module.getPerSegmentTypeStats();
             if (perSyscallStats != null) {
                 for (Entry<String, SegmentStoreStatistics> statsEntry : perSyscallStats.entrySet()) {
                     syscalls.addChild(new SegmentStoreStatisticsEntry(statsEntry.getKey(), statsEntry.getValue()));
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
new file mode 100644 (file)
index 0000000..7a79a34
--- /dev/null
@@ -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.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<String, SegmentStoreStatistics> fPerSegmentTypeStats;
+
+    @Override
+    protected Iterable<IAnalysisModule> 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<ISegment> 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<ISegment> store, IProgressMonitor monitor) {
+        SegmentStoreStatistics total = new SegmentStoreStatistics();
+        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 calculateTotalPerType(ISegmentStore<ISegment> store, IProgressMonitor monitor) {
+        Map<String, SegmentStoreStatistics> perSegmentTypeStats = new HashMap<>();
+
+        Iterator<ISegment> 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<String, SegmentStoreStatistics> getPerSegmentTypeStats() {
+        return fPerSegmentTypeStats;
+    }
+
+}
This page took 0.029528 seconds and 5 git commands to generate.