ctf: Depend on the tracecompass-test-traces project
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / perf / org / eclipse / tracecompass / lttng2 / kernel / core / tests / perf / analysis / StatisticsAnalysisBenchmark.java
1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Alexis Cabana-Loriaux - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.analysis;
14
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertTrue;
17 import static org.junit.Assert.fail;
18
19 import java.io.File;
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.Map.Entry;
23
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.eclipse.test.performance.Dimension;
26 import org.eclipse.test.performance.Performance;
27 import org.eclipse.test.performance.PerformanceMeter;
28 import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
29 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
30 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
31 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
32 import org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics;
33 import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule;
34 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
35 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
36 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
37 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
38 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41
42 /**
43 * This is a test of the time to build a statistics module
44 *
45 * @author Alexis Cabana-Loriaux
46 */
47 @NonNullByDefault
48 public class StatisticsAnalysisBenchmark {
49
50 private static final String TEST_ID = "org.eclipse.linuxtools#Statistics analysis";
51 private static final int LOOP_COUNT = 25;
52
53 /* Event Tests */
54 private static final Map<String, Long> fDjangoClientEntriesToTest = new HashMap<>();
55 private static final Map<String, Long> fDjangoHttpdEntriesToTest = new HashMap<>();
56
57 /**
58 * Build the tests
59 */
60 @BeforeClass
61 public static void buildTest() {
62 /*
63 * test cases map for the Django-client trace
64 */
65 fDjangoClientEntriesToTest.put("exit_syscall", 234013L);
66 fDjangoClientEntriesToTest.put("sys_recvfrom", 133517L);
67 fDjangoClientEntriesToTest.put("irq_handler_exit", 62743L);
68 fDjangoClientEntriesToTest.put("irq_handler_entry", 62743L);
69 fDjangoClientEntriesToTest.put("softirq_entry", 39627L);
70
71 /*
72 * test cases map for the Django-Httpd trace
73 */
74 fDjangoHttpdEntriesToTest.put("exit_syscall", 174802L);
75 fDjangoHttpdEntriesToTest.put("inet_sock_local_out", 36195L);
76 fDjangoHttpdEntriesToTest.put("irq_handler_exit", 93040L);
77 fDjangoHttpdEntriesToTest.put("irq_handler_entry", 93040L);
78 fDjangoHttpdEntriesToTest.put("softirq_entry", 63062L);
79 }
80
81 /**
82 * Run the benchmark with "django-client"
83 */
84 @Test
85 public void testDjangoClient() {
86 runTest(CtfTestTrace.DJANGO_CLIENT, "Django-client trace", fDjangoClientEntriesToTest);
87 }
88
89 /**
90 * Run the benchmark with "django-Httpd"
91 */
92 @Test
93 public void testDjangoHttpd() {
94 runTest(CtfTestTrace.DJANGO_HTTPD, "Django-Httpd trace", fDjangoHttpdEntriesToTest);
95 }
96
97 private static void runTest(CtfTestTrace testTrace, String testName, Map<String, Long> testCases) {
98 Performance perf = Performance.getDefault();
99 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName);
100 perf.tagAsSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
101
102 if (testTrace == CtfTestTrace.DJANGO_CLIENT || testTrace == CtfTestTrace.DJANGO_HTTPD) {
103 /* Do not show all traces in the global summary */
104 perf.tagAsGlobalSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
105 }
106
107 for (int i = 0; i < LOOP_COUNT; i++) {
108 LttngKernelTrace trace = null;
109 TmfStatisticsModule module = null;
110 try {
111 trace = new LttngKernelTrace();
112 module = new TmfStatisticsModule();
113 module.setId("test");
114
115 // TODO Allow the utility method to return a LttngKernelTrace directly
116 CtfTmfTrace ctfTmfTrace = CtfTmfTestTraceUtils.getTrace(testTrace);
117 trace.initTrace(null, ctfTmfTrace.getPath(), CtfTmfEvent.class);
118 module.setTrace(trace);
119
120 pm.start();
121 TmfTestHelper.executeAnalysis(module);
122 pm.stop();
123 ITmfStatistics stats = module.getStatistics();
124 if (stats == null) {
125 throw new IllegalStateException();
126 }
127 Map<String, Long> map = stats.getEventTypesTotal();
128 /*
129 * Test each of the entries
130 */
131 try {
132 for (Entry<String, Long> entry : testCases.entrySet()) {
133 Long value = map.get(entry.getKey());
134 assertNotNull(value);
135 assertTrue(value.equals(entry.getValue()));
136 }
137 } catch (NullPointerException e) {
138 fail(e.getMessage());
139 }
140 /*
141 * Delete the supplementary files, so that the next iteration
142 * rebuilds the state system.
143 */
144 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
145 for (File file : suppDir.listFiles()) {
146 file.delete();
147 }
148
149 } catch (TmfAnalysisException | TmfTraceException e) {
150 fail(e.getMessage());
151 } finally {
152 if (module != null) {
153 module.dispose();
154 }
155 if (trace != null) {
156 trace.dispose();
157 }
158 }
159 }
160 pm.commit();
161 CtfTmfTestTraceUtils.dispose(testTrace);
162 }
163 }
This page took 0.034284 seconds and 5 git commands to generate.