analysis.os: Benchmark some typical usages of Kernel Analysis
[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.kernel.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 /**
49 * Test test ID for kernel analysis benchmarks
50 */
51 public static final String TEST_ID = "org.eclipse.linuxtools#LTTng kernel analysis#";
52 private static final int LOOP_COUNT = 25;
53
54 private final TestModule fTestModule;
55
56 private enum TestModule {
57
58 NORMAL_EXECUTION(""),
59 NULL_BACKEND("(Data not saved to disk)");
60
61 private final String fName;
62
63 private TestModule(String name) {
64 fName = name;
65 }
66
67 public String getTestNameString() {
68 return fName;
69 }
70
71 public static IAnalysisModule getNewModule(TestModule moduleType) {
72 switch (moduleType) {
73 case NORMAL_EXECUTION:
74 return new KernelAnalysisModule();
75 case NULL_BACKEND:
76 return new KernelAnalysisModuleNullBeStub();
77 default:
78 throw new IllegalStateException();
79 }
80 }
81 }
82
83 /**
84 * Constructor
85 *
86 * @param testName
87 * A name for the test, to display in the header
88 * @param module
89 * A test case parameter for this test
90 */
91 public KernelAnalysisBenchmark(String testName, TestModule module) {
92 fTestModule = module;
93 }
94
95 /**
96 * @return The arrays of parameters
97 */
98 @Parameters(name = "{index}: {0}")
99 public static Iterable<Object[]> getParameters() {
100 return Arrays.asList(new Object[][] {
101 { TestModule.NORMAL_EXECUTION.name(), TestModule.NORMAL_EXECUTION },
102 { TestModule.NULL_BACKEND.name(), TestModule.NULL_BACKEND }
103 });
104 }
105
106 /**
107 * Run the benchmark with "trace2"
108 */
109 @Test
110 public void testTrace2() {
111 runTest(CtfTestTrace.TRACE2, "Trace2", fTestModule);
112 }
113
114 /**
115 * Run the benchmark with "many thread"
116 */
117 @Test
118 public void testManyThreads() {
119 runTest(CtfTestTrace.MANY_THREADS, "Many Threads", fTestModule);
120 }
121
122 /**
123 * Run the benchmark with "django httpd"
124 */
125 @Test
126 public void testDjangoHttpd() {
127 runTest(CtfTestTrace.DJANGO_HTTPD, "Django httpd", fTestModule);
128 }
129
130 private static void runTest(@NonNull CtfTestTrace testTrace, String testName, TestModule testModule) {
131 Performance perf = Performance.getDefault();
132 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + testModule.getTestNameString());
133 perf.tagAsSummary(pm, "LTTng Kernel Analysis: " + testName + testModule.getTestNameString(), Dimension.CPU_TIME);
134
135 if ((testTrace == CtfTestTrace.TRACE2) && (testModule == TestModule.NORMAL_EXECUTION)) {
136 /* Do not show all traces in the global summary */
137 perf.tagAsGlobalSummary(pm, "LTTng Kernel Analysis" + testModule.getTestNameString() + ": " + testName, Dimension.CPU_TIME);
138 }
139
140 for (int i = 0; i < LOOP_COUNT; i++) {
141 LttngKernelTrace trace = null;
142 IAnalysisModule module = null;
143 // TODO Allow the utility method to instantiate trace sub-types
144 // directly.
145 String path = CtfTmfTestTraceUtils.getTrace(testTrace).getPath();
146
147 try {
148 trace = new LttngKernelTrace();
149 module = TestModule.getNewModule(testModule);
150 module.setId("test");
151 trace.initTrace(null, path, CtfTmfEvent.class);
152 module.setTrace(trace);
153
154 pm.start();
155 TmfTestHelper.executeAnalysis(module);
156 pm.stop();
157
158 /*
159 * Delete the supplementary files, so that the next iteration
160 * rebuilds the state system.
161 */
162 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
163 for (File file : suppDir.listFiles()) {
164 file.delete();
165 }
166
167 } catch (TmfAnalysisException | TmfTraceException e) {
168 fail(e.getMessage());
169 } finally {
170 if (module != null) {
171 module.dispose();
172 }
173 if (trace != null) {
174 trace.dispose();
175 }
176 }
177 }
178 pm.commit();
179 CtfTmfTestTraceUtils.dispose(testTrace);
180 }
181 }
This page took 0.034451 seconds and 5 git commands to generate.