4e7f3788131007426567d228863d63ca76e653f6
[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.fail;
16 import static org.junit.Assume.assumeTrue;
17
18 import java.io.File;
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.Map.Entry;
22
23 import org.eclipse.test.performance.Dimension;
24 import org.eclipse.test.performance.Performance;
25 import org.eclipse.test.performance.PerformanceMeter;
26 import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
27 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
28 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
29 import org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics;
30 import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule;
31 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
32 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
33 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
34 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
35 import org.junit.Assert;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38
39 /**
40 * This is a test of the time to build a statistics module
41 *
42 * @author Alexis Cabana-Loriaux
43 */
44 public class StatisticsAnalysisBenchmark {
45
46 private static final String TEST_ID = "org.eclipse.linuxtools#Statistics analysis";
47 private static final int LOOP_COUNT = 25;
48
49 /* Event Tests */
50 private static final Map<String, Long> fDjangoClientEntriesToTest = new HashMap<>();
51 private static final Map<String, Long> fDjangoHttpdEntriesToTest = new HashMap<>();
52
53 /**
54 * Build the tests
55 */
56 @BeforeClass
57 public static void buildTest() {
58 /*
59 * test cases map for the Django-client trace
60 */
61 fDjangoClientEntriesToTest.put("exit_syscall", 234013L);
62 fDjangoClientEntriesToTest.put("sys_recvfrom", 133517L);
63 fDjangoClientEntriesToTest.put("irq_handler_exit", 62743L);
64 fDjangoClientEntriesToTest.put("irq_handler_entry", 62743L);
65 fDjangoClientEntriesToTest.put("softirq_entry", 39627L);
66
67 /*
68 * test cases map for the Django-Httpd trace
69 */
70 fDjangoHttpdEntriesToTest.put("exit_syscall", 174802L);
71 fDjangoHttpdEntriesToTest.put("inet_sock_local_out", 36195L);
72 fDjangoHttpdEntriesToTest.put("irq_handler_exit", 93040L);
73 fDjangoHttpdEntriesToTest.put("irq_handler_entry", 93040L);
74 fDjangoHttpdEntriesToTest.put("softirq_entry", 63062L);
75 }
76
77 /**
78 * Run the benchmark with "django-client"
79 */
80 @Test
81 public void testDjangoClient() {
82 runTest(CtfTmfTestTrace.DJANGO_CLIENT, "Django-client trace", fDjangoClientEntriesToTest);
83 }
84
85 /**
86 * Run the benchmark with "django-Httpd"
87 */
88 @Test
89 public void testDjangoHttpd() {
90 runTest(CtfTmfTestTrace.DJANGO_HTTPD, "Django-Httpd trace", fDjangoHttpdEntriesToTest);
91 }
92
93 private static void runTest(CtfTmfTestTrace testTrace, String testName, Map<String, Long> testCases) {
94 assumeTrue(testTrace.exists());
95
96 Performance perf = Performance.getDefault();
97 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName);
98 perf.tagAsSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
99
100 if (testTrace == CtfTmfTestTrace.DJANGO_CLIENT) {
101 /* Do not show all traces in the global summary */
102 perf.tagAsGlobalSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
103 }
104
105 for (int i = 0; i < LOOP_COUNT; i++) {
106 TmfStatisticsModule module = null;
107 try (LttngKernelTrace trace = new LttngKernelTrace()) {
108 module = new TmfStatisticsModule();
109 module.setId("test");
110 trace.initTrace(null, testTrace.getPath(), CtfTmfEvent.class);
111 module.setTrace(trace);
112
113 pm.start();
114 TmfTestHelper.executeAnalysis(module);
115 pm.stop();
116 ITmfStatistics stats = module.getStatistics();
117 if (stats == null) {
118 throw new IllegalStateException();
119 }
120 Map<String, Long> map = stats.getEventTypesTotal();
121 /*
122 * Test each of the entries
123 */
124 try {
125 for (Entry<String, Long> entry : testCases.entrySet()) {
126 Assert.assertTrue(map.get(entry.getKey()).equals(entry.getValue()));
127 }
128 } catch (NullPointerException e) {
129 fail(e.getMessage());
130 }
131 /*
132 * Delete the supplementary files, so that the next iteration
133 * rebuilds the state system.
134 */
135 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
136 for (File file : suppDir.listFiles()) {
137 file.delete();
138 }
139
140 } catch (TmfAnalysisException | TmfTraceException e) {
141 fail(e.getMessage());
142 } finally {
143 if (module != null) {
144 module.dispose();
145 }
146 }
147 }
148 pm.commit();
149 testTrace.dispose();
150 }
151 }
This page took 0.034284 seconds and 4 git commands to generate.