lttng: add two benchmarks for TmfStatisticsModule
authorAlexis Cabana-Loriaux <alex021994@gmail.com>
Fri, 5 Jun 2015 20:45:33 +0000 (16:45 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 16 Jun 2015 23:25:56 +0000 (19:25 -0400)
Change-Id: I932e095ee83aa4b0224963cfc8e4cd61dfbfda82
Signed-off-by: Alexis Cabana-Loriaux <alex021994@gmail.com>
Reviewed-on: https://git.eclipse.org/r/49675
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/perf/org/eclipse/tracecompass/lttng2/kernel/core/tests/perf/analysis/AllPerfTests.java
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/perf/org/eclipse/tracecompass/lttng2/kernel/core/tests/perf/analysis/StatisticsAnalysisBenchmark.java [new file with mode: 0644]

index cd949ecba3bf62020ae49cf96907d88f31034c70..d6cce5556c6f25027c2266acf8fc28872fcd8d94 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Ericsson
+ * 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
@@ -20,7 +20,8 @@ import org.junit.runners.Suite;
  */
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
-        AnalysisBenchmark.class
+        AnalysisBenchmark.class,
+        StatisticsAnalysisBenchmark.class
 })
 public class AllPerfTests {
 }
diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/perf/org/eclipse/tracecompass/lttng2/kernel/core/tests/perf/analysis/StatisticsAnalysisBenchmark.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/perf/org/eclipse/tracecompass/lttng2/kernel/core/tests/perf/analysis/StatisticsAnalysisBenchmark.java
new file mode 100644 (file)
index 0000000..4e7f378
--- /dev/null
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Alexis Cabana-Loriaux - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.analysis;
+
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.test.performance.Dimension;
+import org.eclipse.test.performance.Performance;
+import org.eclipse.test.performance.PerformanceMeter;
+import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule;
+import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * This is a test of the time to build a statistics module
+ *
+ * @author Alexis Cabana-Loriaux
+ */
+public class StatisticsAnalysisBenchmark {
+
+    private static final String TEST_ID = "org.eclipse.linuxtools#Statistics analysis";
+    private static final int LOOP_COUNT = 25;
+
+    /* Event Tests */
+    private static final Map<String, Long> fDjangoClientEntriesToTest = new HashMap<>();
+    private static final Map<String, Long> fDjangoHttpdEntriesToTest = new HashMap<>();
+
+    /**
+     * Build the tests
+     */
+    @BeforeClass
+    public static void buildTest() {
+        /*
+         * test cases map for the Django-client trace
+         */
+        fDjangoClientEntriesToTest.put("exit_syscall", 234013L);
+        fDjangoClientEntriesToTest.put("sys_recvfrom", 133517L);
+        fDjangoClientEntriesToTest.put("irq_handler_exit", 62743L);
+        fDjangoClientEntriesToTest.put("irq_handler_entry", 62743L);
+        fDjangoClientEntriesToTest.put("softirq_entry", 39627L);
+
+        /*
+         * test cases map for the Django-Httpd trace
+         */
+        fDjangoHttpdEntriesToTest.put("exit_syscall", 174802L);
+        fDjangoHttpdEntriesToTest.put("inet_sock_local_out", 36195L);
+        fDjangoHttpdEntriesToTest.put("irq_handler_exit", 93040L);
+        fDjangoHttpdEntriesToTest.put("irq_handler_entry", 93040L);
+        fDjangoHttpdEntriesToTest.put("softirq_entry", 63062L);
+    }
+
+    /**
+     * Run the benchmark with "django-client"
+     */
+    @Test
+    public void testDjangoClient() {
+        runTest(CtfTmfTestTrace.DJANGO_CLIENT, "Django-client trace", fDjangoClientEntriesToTest);
+    }
+
+    /**
+     * Run the benchmark with "django-Httpd"
+     */
+    @Test
+    public void testDjangoHttpd() {
+        runTest(CtfTmfTestTrace.DJANGO_HTTPD, "Django-Httpd trace", fDjangoHttpdEntriesToTest);
+    }
+
+    private static void runTest(CtfTmfTestTrace testTrace, String testName, Map<String, Long> testCases) {
+        assumeTrue(testTrace.exists());
+
+        Performance perf = Performance.getDefault();
+        PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName);
+        perf.tagAsSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
+
+        if (testTrace == CtfTmfTestTrace.DJANGO_CLIENT) {
+            /* Do not show all traces in the global summary */
+            perf.tagAsGlobalSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
+        }
+
+        for (int i = 0; i < LOOP_COUNT; i++) {
+            TmfStatisticsModule module = null;
+            try (LttngKernelTrace trace = new LttngKernelTrace()) {
+                module = new TmfStatisticsModule();
+                module.setId("test");
+                trace.initTrace(null, testTrace.getPath(), CtfTmfEvent.class);
+                module.setTrace(trace);
+
+                pm.start();
+                TmfTestHelper.executeAnalysis(module);
+                pm.stop();
+                ITmfStatistics stats = module.getStatistics();
+                if (stats == null) {
+                    throw new IllegalStateException();
+                }
+                Map<String, Long> map = stats.getEventTypesTotal();
+                /*
+                 * Test each of the entries
+                 */
+                try {
+                    for (Entry<String, Long> entry : testCases.entrySet()) {
+                        Assert.assertTrue(map.get(entry.getKey()).equals(entry.getValue()));
+                    }
+                } catch (NullPointerException e) {
+                    fail(e.getMessage());
+                }
+                /*
+                 * Delete the supplementary files, so that the next iteration
+                 * rebuilds the state system.
+                 */
+                File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
+                for (File file : suppDir.listFiles()) {
+                    file.delete();
+                }
+
+            } catch (TmfAnalysisException | TmfTraceException e) {
+                fail(e.getMessage());
+            } finally {
+                if (module != null) {
+                    module.dispose();
+                }
+            }
+        }
+        pm.commit();
+        testTrace.dispose();
+    }
+}
This page took 0.040497 seconds and 5 git commands to generate.