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
.execgraph
;
12 import static org
.junit
.Assert
.fail
;
15 import java
.util
.EnumSet
;
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
.internal
.lttng2
.kernel
.core
.analysis
.graph
.building
.LttngKernelExecutionGraph
;
22 import org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.trace
.LttngKernelTrace
;
23 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.shared
.TmfTestHelper
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
29 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
30 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
31 import org
.junit
.Test
;
34 * Benchmarks the kernel execution graph
36 * @author Geneviève Bastien
38 public class KernelExecutionGraphBenchmark
{
41 * Test test ID for kernel analysis benchmarks
43 public static final String TEST_ID
= "org.eclipse.tracecompass#Kernel Execution Graph#";
44 private static final String TEST_BUILD
= "Building Graph (%s)";
45 private static final String TEST_MEMORY
= "Memory Usage (%s)";
47 private static final int LOOP_COUNT
= 25;
49 private interface RunMethod
{
50 void execute(PerformanceMeter pm
, IAnalysisModule module
);
53 private RunMethod cpu
= (pm
, module
) -> {
55 TmfTestHelper
.executeAnalysis(module
);
59 private RunMethod memory
= (pm
, module
) -> {
62 TmfTestHelper
.executeAnalysis(module
);
67 private static final EnumSet
<CtfTestTrace
> fTraceSet
= EnumSet
.of(
69 CtfTestTrace
.MANY_THREADS
,
70 CtfTestTrace
.DJANGO_HTTPD
);
76 public void runAllBenchmarks() {
77 for (CtfTestTrace trace
: fTraceSet
) {
79 runOneBenchmark(trace
,
80 String
.format(TEST_BUILD
, trace
.toString()),
84 runOneBenchmark(trace
,
85 String
.format(TEST_MEMORY
, trace
.toString()),
87 Dimension
.USED_JAVA_HEAP
);
91 private static void runOneBenchmark(@NonNull CtfTestTrace testTrace
, String testName
, RunMethod method
, Dimension dimension
) {
92 Performance perf
= Performance
.getDefault();
93 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ testName
);
94 perf
.tagAsSummary(pm
, "Execution graph " + testName
, dimension
);
96 for (int i
= 0; i
< LOOP_COUNT
; i
++) {
97 LttngKernelTrace trace
= null;
98 IAnalysisModule module
= null;
100 String path
= CtfTmfTestTraceUtils
.getTrace(testTrace
).getPath();
103 trace
= new LttngKernelTrace();
104 module
= new LttngKernelExecutionGraph();
105 module
.setId("test");
106 trace
.initTrace(null, path
, CtfTmfEvent
.class);
107 module
.setTrace(trace
);
109 method
.execute(pm
, module
);
112 * Delete the supplementary files, so that the next iteration
113 * rebuilds the state system.
115 File suppDir
= new File(TmfTraceManager
.getSupplementaryFileDir(trace
));
116 for (File file
: suppDir
.listFiles()) {
120 } catch (TmfAnalysisException
| TmfTraceException e
) {
121 fail(e
.getMessage());
123 if (module
!= null) {
132 CtfTmfTestTraceUtils
.dispose(testTrace
);