1 /*******************************************************************************
2 * Copyright (c) 2016 É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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.perf
.analysis
.syscall
;
12 import static org
.junit
.Assert
.assertNotNull
;
13 import static org
.junit
.Assert
.fail
;
17 import org
.eclipse
.jdt
.annotation
.NonNull
;
18 import org
.eclipse
.test
.performance
.Dimension
;
19 import org
.eclipse
.test
.performance
.Performance
;
20 import org
.eclipse
.test
.performance
.PerformanceMeter
;
21 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.tid
.TidAnalysisModule
;
22 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.latency
.SystemCallLatencyAnalysis
;
23 import org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.trace
.LttngKernelTrace
;
24 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.shared
.TmfTestHelper
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
31 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
32 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
33 import org
.junit
.Test
;
36 * Benchmarks the system call latency analysis
38 * @author Geneviève Bastien
40 public class SystemCallAnalysisBenchmark
{
43 * Test test ID for the system call analysis benchmarks
45 public static final String TEST_ID
= "org.eclipse.tracecompass#System Call Analysis#";
46 private static final String TEST_BUILD
= "Building Analysis (%s)";
47 private static final String TEST_MEMORY
= "Memory Usage (%s)";
49 private static final int LOOP_COUNT
= 25;
51 private interface RunMethod
{
52 void execute(PerformanceMeter pm
, IAnalysisModule module
);
55 private RunMethod cpu
= (pm
, module
) -> {
57 TmfTestHelper
.executeAnalysis(module
);
61 private RunMethod memory
= (pm
, module
) -> {
64 TmfTestHelper
.executeAnalysis(module
);
70 * Run the benchmark with "trace2"
73 public void testTrace2() {
74 runTest(CtfTestTrace
.TRACE2
, String
.format(TEST_BUILD
, "Trace2"), cpu
, Dimension
.CPU_TIME
);
75 runTest(CtfTestTrace
.TRACE2
, String
.format(TEST_MEMORY
, "Trace2"), memory
, Dimension
.USED_JAVA_HEAP
);
79 * Run the benchmark with "many thread"
82 public void testManyThreads() {
83 runTest(CtfTestTrace
.MANY_THREADS
, String
.format(TEST_BUILD
, "Many threads"), cpu
, Dimension
.CPU_TIME
);
84 runTest(CtfTestTrace
.MANY_THREADS
, String
.format(TEST_MEMORY
, "Many threads"), memory
, Dimension
.USED_JAVA_HEAP
);
88 * Run the benchmark with "django httpd"
91 public void testDjangoHttpd() {
92 runTest(CtfTestTrace
.DJANGO_HTTPD
, String
.format(TEST_BUILD
, "Django HTTPD"), cpu
, Dimension
.CPU_TIME
);
93 runTest(CtfTestTrace
.DJANGO_HTTPD
, String
.format(TEST_MEMORY
, "Django HTTPD"), memory
, Dimension
.USED_JAVA_HEAP
);
96 private static void runTest(@NonNull CtfTestTrace testTrace
, String testName
, RunMethod method
, Dimension dimension
) {
97 Performance perf
= Performance
.getDefault();
98 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ testName
);
99 perf
.tagAsSummary(pm
, "Syscall " + testName
, dimension
);
101 for (int i
= 0; i
< LOOP_COUNT
; i
++) {
102 LttngKernelTrace trace
= null;
103 IAnalysisModule module
= null;
105 String path
= CtfTmfTestTraceUtils
.getTrace(testTrace
).getPath();
108 // Make sure the TID analysis has run on this trace
109 trace
= new LttngKernelTrace();
110 trace
.initTrace(null, path
, CtfTmfEvent
.class);
111 trace
.traceOpened(new TmfTraceOpenedSignal(trace
, trace
, null));
112 module
= trace
.getAnalysisModule(TidAnalysisModule
.ID
);
113 assertNotNull(module
);
115 module
.waitForCompletion();
117 module
= new SystemCallLatencyAnalysis();
118 module
.setId("test");
119 module
.setTrace(trace
);
121 method
.execute(pm
, module
);
124 * Delete the supplementary files, so that the next iteration
125 * rebuilds the state system.
127 File suppDir
= new File(TmfTraceManager
.getSupplementaryFileDir(trace
));
128 for (File file
: suppDir
.listFiles()) {
132 } catch (TmfAnalysisException
| TmfTraceException e
) {
133 fail(e
.getMessage());
135 if (module
!= null) {
144 CtfTmfTestTraceUtils
.dispose(testTrace
);