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
.fail
;
16 import static org
.junit
.Assume
.assumeTrue
;
19 import java
.util
.HashMap
;
21 import java
.util
.Map
.Entry
;
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
;
40 * This is a test of the time to build a statistics module
42 * @author Alexis Cabana-Loriaux
44 public class StatisticsAnalysisBenchmark
{
46 private static final String TEST_ID
= "org.eclipse.linuxtools#Statistics analysis";
47 private static final int LOOP_COUNT
= 25;
50 private static final Map
<String
, Long
> fDjangoClientEntriesToTest
= new HashMap
<>();
51 private static final Map
<String
, Long
> fDjangoHttpdEntriesToTest
= new HashMap
<>();
57 public static void buildTest() {
59 * test cases map for the Django-client trace
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);
68 * test cases map for the Django-Httpd trace
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);
78 * Run the benchmark with "django-client"
81 public void testDjangoClient() {
82 runTest(CtfTmfTestTrace
.DJANGO_CLIENT
, "Django-client trace", fDjangoClientEntriesToTest
);
86 * Run the benchmark with "django-Httpd"
89 public void testDjangoHttpd() {
90 runTest(CtfTmfTestTrace
.DJANGO_HTTPD
, "Django-Httpd trace", fDjangoHttpdEntriesToTest
);
93 private static void runTest(CtfTmfTestTrace testTrace
, String testName
, Map
<String
, Long
> testCases
) {
94 assumeTrue(testTrace
.exists());
96 Performance perf
= Performance
.getDefault();
97 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ '#' + testName
);
98 perf
.tagAsSummary(pm
, "Statistics Analysis: " + testName
, Dimension
.CPU_TIME
);
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
);
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
);
114 TmfTestHelper
.executeAnalysis(module
);
116 ITmfStatistics stats
= module
.getStatistics();
118 throw new IllegalStateException();
120 Map
<String
, Long
> map
= stats
.getEventTypesTotal();
122 * Test each of the entries
125 for (Entry
<String
, Long
> entry
: testCases
.entrySet()) {
126 Assert
.assertTrue(map
.get(entry
.getKey()).equals(entry
.getValue()));
128 } catch (NullPointerException e
) {
129 fail(e
.getMessage());
132 * Delete the supplementary files, so that the next iteration
133 * rebuilds the state system.
135 File suppDir
= new File(TmfTraceManager
.getSupplementaryFileDir(trace
));
136 for (File file
: suppDir
.listFiles()) {
140 } catch (TmfAnalysisException
| TmfTraceException e
) {
141 fail(e
.getMessage());
143 if (module
!= null) {