analysis: use a null backend for the kernel analysis benchmark
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / perf / org / eclipse / tracecompass / lttng2 / kernel / core / tests / perf / analysis / kernel / KernelAnalysisBenchmark.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 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 * Geneviève Bastien - Initial API and implementation
11 * Alexandre Montplaisir - Convert to org.eclipse.test.performance test
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.analysis.kernel;
15
16 import static org.junit.Assert.fail;
17
18 import java.io.File;
19 import java.util.Arrays;
20
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.eclipse.test.performance.Dimension;
23 import org.eclipse.test.performance.Performance;
24 import org.eclipse.test.performance.PerformanceMeter;
25 import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
26 import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
27 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
28 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
29 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
30 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
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.CtfTmfTestTraceUtils;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.junit.runners.Parameterized;
38 import org.junit.runners.Parameterized.Parameters;
39
40 /**
41 * This is a test of the time to build a kernel state system
42 *
43 * @author Genevieve Bastien
44 */
45 @RunWith(Parameterized.class)
46 public class KernelAnalysisBenchmark {
47
48 private static final String TEST_ID = "org.eclipse.linuxtools#LTTng kernel analysis#";
49 private static final int LOOP_COUNT = 25;
50
51 private final TestModule fTestModule;
52
53 private enum TestModule {
54
55 NORMAL_EXECUTION(""),
56 NULL_BACKEND("(Data not saved to disk)");
57
58 private final String fName;
59
60 private TestModule(String name) {
61 fName = name;
62 }
63
64 public String getTestNameString() {
65 return fName;
66 }
67
68 public static IAnalysisModule getNewModule(TestModule moduleType) {
69 switch (moduleType) {
70 case NORMAL_EXECUTION:
71 return new KernelAnalysisModule();
72 case NULL_BACKEND:
73 return new KernelAnalysisModuleNullBeStub();
74 default:
75 throw new IllegalStateException();
76 }
77 }
78 }
79
80 /**
81 * Constructor
82 *
83 * @param testName
84 * A name for the test, to display in the header
85 * @param module
86 * A test case parameter for this test
87 */
88 public KernelAnalysisBenchmark(String testName, TestModule module) {
89 fTestModule = module;
90 }
91
92 /**
93 * @return The arrays of parameters
94 */
95 @Parameters(name = "{index}: {0}")
96 public static Iterable<Object[]> getParameters() {
97 return Arrays.asList(new Object[][] {
98 { TestModule.NORMAL_EXECUTION.name(), TestModule.NORMAL_EXECUTION },
99 { TestModule.NULL_BACKEND.name(), TestModule.NULL_BACKEND }
100 });
101 }
102
103 /**
104 * Run the benchmark with "trace2"
105 */
106 @Test
107 public void testTrace2() {
108 runTest(CtfTestTrace.TRACE2, "Trace2", fTestModule);
109 }
110
111 private static void runTest(@NonNull CtfTestTrace testTrace, String testName, TestModule testModule) {
112 Performance perf = Performance.getDefault();
113 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + testModule.getTestNameString());
114 perf.tagAsSummary(pm, "LTTng Kernel Analysis: " + testName + testModule.getTestNameString(), Dimension.CPU_TIME);
115
116 if ((testTrace == CtfTestTrace.TRACE2) && (testModule == TestModule.NORMAL_EXECUTION)) {
117 /* Do not show all traces in the global summary */
118 perf.tagAsGlobalSummary(pm, "LTTng Kernel Analysis" + testModule.getTestNameString() + ": " + testName, Dimension.CPU_TIME);
119 }
120
121 for (int i = 0; i < LOOP_COUNT; i++) {
122 LttngKernelTrace trace = null;
123 IAnalysisModule module = null;
124 // TODO Allow the utility method to instantiate trace sub-types
125 // directly.
126 String path = CtfTmfTestTraceUtils.getTrace(testTrace).getPath();
127
128 try {
129 trace = new LttngKernelTrace();
130 module = TestModule.getNewModule(testModule);
131 module.setId("test");
132 trace.initTrace(null, path, CtfTmfEvent.class);
133 module.setTrace(trace);
134
135 pm.start();
136 TmfTestHelper.executeAnalysis(module);
137 pm.stop();
138
139 /*
140 * Delete the supplementary files, so that the next iteration
141 * rebuilds the state system.
142 */
143 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
144 for (File file : suppDir.listFiles()) {
145 file.delete();
146 }
147
148 } catch (TmfAnalysisException | TmfTraceException e) {
149 fail(e.getMessage());
150 } finally {
151 if (module != null) {
152 module.dispose();
153 }
154 if (trace != null) {
155 trace.dispose();
156 }
157 }
158 }
159 pm.commit();
160 CtfTmfTestTraceUtils.dispose(testTrace);
161 }
162 }
This page took 0.047984 seconds and 5 git commands to generate.