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
CommitLineData
72c787e2 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2014, 2015 École Polytechnique de Montréal
72c787e2
GB
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
e34d62dc 14package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.analysis.kernel;
72c787e2
GB
15
16import static org.junit.Assert.fail;
72c787e2
GB
17
18import java.io.File;
e34d62dc 19import java.util.Arrays;
72c787e2 20
c4d57ac1 21import org.eclipse.jdt.annotation.NonNull;
72c787e2
GB
22import org.eclipse.test.performance.Dimension;
23import org.eclipse.test.performance.Performance;
24import org.eclipse.test.performance.PerformanceMeter;
0f7a12d3 25import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
9bc60be7 26import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
c4d57ac1 27import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
2bdf0193
AM
28import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
29import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
30import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
31import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
32import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
9722e5d7 33import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
c4d57ac1 34import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
72c787e2 35import org.junit.Test;
e34d62dc
GB
36import org.junit.runner.RunWith;
37import org.junit.runners.Parameterized;
38import org.junit.runners.Parameterized.Parameters;
72c787e2
GB
39
40/**
41 * This is a test of the time to build a kernel state system
42 *
43 * @author Genevieve Bastien
44 */
e34d62dc
GB
45@RunWith(Parameterized.class)
46public class KernelAnalysisBenchmark {
72c787e2 47
613e9594
GB
48 /**
49 * Test test ID for kernel analysis benchmarks
50 */
51 public static final String TEST_ID = "org.eclipse.linuxtools#LTTng kernel analysis#";
f14c2f97 52 private static final int LOOP_COUNT = 25;
72c787e2 53
e34d62dc
GB
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
72c787e2
GB
106 /**
107 * Run the benchmark with "trace2"
108 */
109 @Test
110 public void testTrace2() {
e34d62dc 111 runTest(CtfTestTrace.TRACE2, "Trace2", fTestModule);
72c787e2
GB
112 }
113
613e9594
GB
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
e34d62dc 130 private static void runTest(@NonNull CtfTestTrace testTrace, String testName, TestModule testModule) {
72c787e2 131 Performance perf = Performance.getDefault();
e34d62dc
GB
132 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + testModule.getTestNameString());
133 perf.tagAsSummary(pm, "LTTng Kernel Analysis: " + testName + testModule.getTestNameString(), Dimension.CPU_TIME);
72c787e2 134
e34d62dc 135 if ((testTrace == CtfTestTrace.TRACE2) && (testModule == TestModule.NORMAL_EXECUTION)) {
72c787e2 136 /* Do not show all traces in the global summary */
e34d62dc 137 perf.tagAsGlobalSummary(pm, "LTTng Kernel Analysis" + testModule.getTestNameString() + ": " + testName, Dimension.CPU_TIME);
72c787e2
GB
138 }
139
140 for (int i = 0; i < LOOP_COUNT; i++) {
0ff9e595 141 LttngKernelTrace trace = null;
03f0b0b1 142 IAnalysisModule module = null;
c4d57ac1
AM
143 // TODO Allow the utility method to instantiate trace sub-types
144 // directly.
145 String path = CtfTmfTestTraceUtils.getTrace(testTrace).getPath();
146
0ff9e595
AM
147 try {
148 trace = new LttngKernelTrace();
e34d62dc 149 module = TestModule.getNewModule(testModule);
72c787e2 150 module.setId("test");
c4d57ac1 151 trace.initTrace(null, path, CtfTmfEvent.class);
72c787e2
GB
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());
03f0b0b1
AM
169 } finally {
170 if (module != null) {
171 module.dispose();
172 }
0ff9e595
AM
173 if (trace != null) {
174 trace.dispose();
175 }
72c787e2 176 }
72c787e2
GB
177 }
178 pm.commit();
c4d57ac1 179 CtfTmfTestTraceUtils.dispose(testTrace);
72c787e2
GB
180 }
181}
This page took 0.066176 seconds and 5 git commands to generate.