1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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
10 * Alexis Cabana-Loriaux - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.perf
.analysis
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.assertTrue
;
17 import static org
.junit
.Assert
.fail
;
20 import java
.util
.HashMap
;
22 import java
.util
.Map
.Entry
;
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
;
43 * This is a test of the time to build a statistics module
45 * @author Alexis Cabana-Loriaux
48 public class StatisticsAnalysisBenchmark
{
50 private static final String TEST_ID
= "org.eclipse.linuxtools#Statistics analysis";
51 private static final int LOOP_COUNT
= 25;
54 private static final Map
<String
, Long
> fDjangoClientEntriesToTest
= new HashMap
<>();
55 private static final Map
<String
, Long
> fDjangoHttpdEntriesToTest
= new HashMap
<>();
61 public static void buildTest() {
63 * test cases map for the Django-client trace
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);
72 * test cases map for the Django-Httpd trace
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);
82 * Run the benchmark with "django-client"
85 public void testDjangoClient() {
86 runTest(CtfTestTrace
.DJANGO_CLIENT
, "Django-client trace", fDjangoClientEntriesToTest
);
90 * Run the benchmark with "django-Httpd"
93 public void testDjangoHttpd() {
94 runTest(CtfTestTrace
.DJANGO_HTTPD
, "Django-Httpd trace", fDjangoHttpdEntriesToTest
);
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
);
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
);
107 for (int i
= 0; i
< LOOP_COUNT
; i
++) {
108 LttngKernelTrace trace
= null;
109 TmfStatisticsModule module
= null;
111 trace
= new LttngKernelTrace();
112 module
= new TmfStatisticsModule();
113 module
.setId("test");
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
);
121 TmfTestHelper
.executeAnalysis(module
);
123 ITmfStatistics stats
= module
.getStatistics();
125 throw new IllegalStateException();
127 Map
<String
, Long
> map
= stats
.getEventTypesTotal();
129 * Test each of the entries
132 for (Entry
<String
, Long
> entry
: testCases
.entrySet()) {
133 Long value
= map
.get(entry
.getKey());
134 assertNotNull(value
);
135 assertTrue(value
.equals(entry
.getValue()));
137 } catch (NullPointerException e
) {
138 fail(e
.getMessage());
141 * Delete the supplementary files, so that the next iteration
142 * rebuilds the state system.
144 File suppDir
= new File(TmfTraceManager
.getSupplementaryFileDir(trace
));
145 for (File file
: suppDir
.listFiles()) {
149 } catch (TmfAnalysisException
| TmfTraceException e
) {
150 fail(e
.getMessage());
152 if (module
!= null) {
161 CtfTmfTestTraceUtils
.dispose(testTrace
);