os.linux: Rename the "kernelanalysis" package to just "kernel"
[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
e34d62dc 48 private static final String TEST_ID = "org.eclipse.linuxtools#LTTng kernel analysis#";
f14c2f97 49 private static final int LOOP_COUNT = 25;
72c787e2 50
e34d62dc
GB
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
72c787e2
GB
103 /**
104 * Run the benchmark with "trace2"
105 */
106 @Test
107 public void testTrace2() {
e34d62dc 108 runTest(CtfTestTrace.TRACE2, "Trace2", fTestModule);
72c787e2
GB
109 }
110
e34d62dc 111 private static void runTest(@NonNull CtfTestTrace testTrace, String testName, TestModule testModule) {
72c787e2 112 Performance perf = Performance.getDefault();
e34d62dc
GB
113 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + testModule.getTestNameString());
114 perf.tagAsSummary(pm, "LTTng Kernel Analysis: " + testName + testModule.getTestNameString(), Dimension.CPU_TIME);
72c787e2 115
e34d62dc 116 if ((testTrace == CtfTestTrace.TRACE2) && (testModule == TestModule.NORMAL_EXECUTION)) {
72c787e2 117 /* Do not show all traces in the global summary */
e34d62dc 118 perf.tagAsGlobalSummary(pm, "LTTng Kernel Analysis" + testModule.getTestNameString() + ": " + testName, Dimension.CPU_TIME);
72c787e2
GB
119 }
120
121 for (int i = 0; i < LOOP_COUNT; i++) {
0ff9e595 122 LttngKernelTrace trace = null;
03f0b0b1 123 IAnalysisModule module = null;
c4d57ac1
AM
124 // TODO Allow the utility method to instantiate trace sub-types
125 // directly.
126 String path = CtfTmfTestTraceUtils.getTrace(testTrace).getPath();
127
0ff9e595
AM
128 try {
129 trace = new LttngKernelTrace();
e34d62dc 130 module = TestModule.getNewModule(testModule);
72c787e2 131 module.setId("test");
c4d57ac1 132 trace.initTrace(null, path, CtfTmfEvent.class);
72c787e2
GB
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());
03f0b0b1
AM
150 } finally {
151 if (module != null) {
152 module.dispose();
153 }
0ff9e595
AM
154 if (trace != null) {
155 trace.dispose();
156 }
72c787e2 157 }
72c787e2
GB
158 }
159 pm.commit();
c4d57ac1 160 CtfTmfTestTraceUtils.dispose(testTrace);
72c787e2
GB
161 }
162}
This page took 0.0625599999999999 seconds and 5 git commands to generate.