analysis: Introduce syscall statistics analysis test
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Sat, 12 Dec 2015 02:43:55 +0000 (21:43 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 19 May 2016 19:31:44 +0000 (15:31 -0400)
This extracts the kernelCtfTraceStub to allow both tests to use it.

Change-Id: I8cbd51e691d9e9f3ae2d51e2f64e74a9ec6c6176
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/62546
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/plugin.xml
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/latency/KernelCtfTraceStub.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/latency/SyscallAnalysisTest.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/latency/SyscallStatsAnalysisTest.java [new file with mode: 0644]

index fcd34f775542275dd4464f9fa4bb1e35f36ce0ff..e659abf7899797c4e14f35165686dd91fac9ed38 100644 (file)
                class="org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.TmfXmlKernelTraceStub">
          </tracetype>
       </module>
+      <module
+            analysis_module="org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics.SystemCallLatencyStatisticsAnalysisModule"
+            id="org.eclipse.tracecompass.analysis.os.linux.core.latency.statistics.syscall"
+            name="System call stats">
+         <tracetype
+               applies="true"
+               class="org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace">
+         </tracetype>
+      </module>
    </extension>
    <extension
          point="org.eclipse.linuxtools.tmf.core.tracetype">
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/latency/KernelCtfTraceStub.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/latency/KernelCtfTraceStub.java
new file mode 100644 (file)
index 0000000..05177c2
--- /dev/null
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.os.linux.core.tests.latency;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.KernelEventLayoutStub;
+import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
+import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+class KernelCtfTraceStub extends CtfTmfTrace implements IKernelTrace {
+    public KernelCtfTraceStub() {
+        super();
+    }
+
+    public static synchronized KernelCtfTraceStub getTrace(CtfTestTrace ctfTrace) {
+        String tracePath;
+        try {
+            tracePath = FileLocator.toFileURL(ctfTrace.getTraceURL()).getPath();
+        } catch (IOException e) {
+            throw new IllegalStateException();
+        }
+
+        KernelCtfTraceStub trace = new KernelCtfTraceStub();
+        try {
+            trace.initTrace(null, tracePath, CtfTmfEvent.class);
+        } catch (TmfTraceException e) {
+            /* Should not happen if tracesExist() passed */
+            throw new RuntimeException(e);
+        }
+        return trace;
+    }
+
+    @Override
+    public @NonNull IKernelAnalysisEventLayout getKernelEventLayout() {
+        return KernelEventLayoutStub.getInstance();
+    }
+}
\ No newline at end of file
index c8ad17d16e597c922c417908330f92a05b888f39..88859efeb09a46d0302761ae12266ebe3e2d688f 100644 (file)
@@ -12,25 +12,16 @@ package org.eclipse.tracecompass.analysis.os.linux.core.tests.latency;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.io.IOException;
-
-import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCallLatencyAnalysis;
-import org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.KernelEventLayoutStub;
-import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
-import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace;
 import org.eclipse.tracecompass.segmentstore.core.ISegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
-import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -42,35 +33,6 @@ import org.junit.Test;
  */
 public class SyscallAnalysisTest {
 
-    private static class KernelStubTrace extends CtfTmfTrace implements IKernelTrace {
-        public KernelStubTrace() {
-            super();
-        }
-
-        public static synchronized KernelStubTrace getTrace(CtfTestTrace ctfTrace) {
-            String tracePath;
-            try {
-                tracePath = FileLocator.toFileURL(ctfTrace.getTraceURL()).getPath();
-            } catch (IOException e) {
-                throw new IllegalStateException();
-            }
-
-            KernelStubTrace trace = new KernelStubTrace();
-            try {
-                trace.initTrace(null, tracePath, CtfTmfEvent.class);
-            } catch (TmfTraceException e) {
-                /* Should not happen if tracesExist() passed */
-                throw new RuntimeException(e);
-            }
-            return trace;
-        }
-
-        @Override
-        public @NonNull IKernelAnalysisEventLayout getKernelEventLayout() {
-            return KernelEventLayoutStub.getInstance();
-        }
-    }
-
     private SystemCallLatencyAnalysis fSyscallModule;
 
     /**
@@ -78,7 +40,7 @@ public class SyscallAnalysisTest {
      */
     @Before
     public void setUp() {
-        ITmfTrace trace = KernelStubTrace.getTrace(CtfTestTrace.ARM_64_BIT_HEADER);
+        ITmfTrace trace = KernelCtfTraceStub.getTrace(CtfTestTrace.ARM_64_BIT_HEADER);
         /* Make sure the Kernel analysis has run */
         ((TmfTrace) trace).traceOpened(new TmfTraceOpenedSignal(this, trace, null));
         for (IAnalysisModule mod : TmfTraceUtils.getAnalysisModulesOfClass(trace, SystemCallLatencyAnalysis.class)) {
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/latency/SyscallStatsAnalysisTest.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/latency/SyscallStatsAnalysisTest.java
new file mode 100644 (file)
index 0000000..ac39030
--- /dev/null
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.analysis.os.linux.core.tests.latency;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCallLatencyAnalysis;
+import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics;
+import org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics.SystemCallLatencyStatisticsAnalysisModule;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for the system call statistics analysis
+ *
+ * @author Matthew Khouzam
+ */
+public class SyscallStatsAnalysisTest {
+
+    private TmfTrace fTestTrace;
+    private SystemCallLatencyStatisticsAnalysisModule fSyscallStatsModule;
+
+    /**
+     * Create the fixtures
+     */
+    @Before
+    public void setupAnalysis() {
+        ITmfTrace trace = KernelCtfTraceStub.getTrace(CtfTestTrace.ARM_64_BIT_HEADER);
+        /* Make sure the Kernel analysis has run */
+        ((TmfTrace) trace).traceOpened(new TmfTraceOpenedSignal(this, trace, null));
+        IAnalysisModule module = null;
+        for (IAnalysisModule mod : TmfTraceUtils.getAnalysisModulesOfClass(trace, SystemCallLatencyAnalysis.class)) {
+            module = mod;
+        }
+        assertNotNull(module);
+        module.schedule();
+        module.waitForCompletion();
+        SystemCallLatencyStatisticsAnalysisModule syscallStatsModule = null;
+        for (IAnalysisModule mod : TmfTraceUtils.getAnalysisModulesOfClass(trace, SystemCallLatencyStatisticsAnalysisModule.class)) {
+            syscallStatsModule = (SystemCallLatencyStatisticsAnalysisModule) mod;
+        }
+        assertNotNull(syscallStatsModule);
+        syscallStatsModule.schedule();
+        syscallStatsModule.waitForCompletion();
+        fSyscallStatsModule = syscallStatsModule;
+    }
+
+    /**
+     * Dispose everything
+     */
+    @After
+    public void cleanup() {
+        final TmfTrace testTrace = fTestTrace;
+        if (testTrace != null) {
+            testTrace.dispose();
+        }
+    }
+
+    /**
+     * This will load the analysis and test it. as it depends on Kernel, this
+     * test runs the kernel trace first then the analysis
+     */
+    @Test
+    public void testSmallTraceSequential() {
+        final SystemCallLatencyStatisticsAnalysisModule syscallStatsModule = fSyscallStatsModule;
+        assertNotNull(syscallStatsModule);
+        SegmentStoreStatistics totalStats = syscallStatsModule.getTotalStats();
+        assertNotNull(totalStats);
+        assertEquals(1801, totalStats.getNbSegments());
+        assertEquals(5904091700L, totalStats.getMax());
+    }
+}
This page took 0.027732 seconds and 5 git commands to generate.