af1da77c22ea302064254e8c05765b43b403b73b
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / perf / org / eclipse / tracecompass / lttng2 / kernel / core / tests / perf / analysis / AnalysisBenchmark.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;
15
16 import static org.junit.Assert.fail;
17
18 import java.io.File;
19
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.eclipse.test.performance.Dimension;
22 import org.eclipse.test.performance.Performance;
23 import org.eclipse.test.performance.PerformanceMeter;
24 import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
25 import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
26 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
27 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
28 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
29 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
30 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
31 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
32 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
33 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
34 import org.junit.Test;
35
36 /**
37 * This is a test of the time to build a kernel state system
38 *
39 * @author Genevieve Bastien
40 */
41 public class AnalysisBenchmark {
42
43 private static final String TEST_ID = "org.eclipse.linuxtools#LTTng kernel analysis";
44 private static final int LOOP_COUNT = 25;
45
46 /**
47 * Run the benchmark with "trace2"
48 */
49 @Test
50 public void testTrace2() {
51 runTest(CtfTestTrace.TRACE2, "Trace2");
52 }
53
54 private static void runTest(@NonNull CtfTestTrace testTrace, String testName) {
55 Performance perf = Performance.getDefault();
56 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName);
57 perf.tagAsSummary(pm, "LTTng Kernel Analysis: " + testName, Dimension.CPU_TIME);
58
59 if (testTrace == CtfTestTrace.TRACE2) {
60 /* Do not show all traces in the global summary */
61 perf.tagAsGlobalSummary(pm, "LTTng Kernel Analysis: " + testName, Dimension.CPU_TIME);
62 }
63
64 for (int i = 0; i < LOOP_COUNT; i++) {
65 LttngKernelTrace trace = null;
66 IAnalysisModule module = null;
67 // TODO Allow the utility method to instantiate trace sub-types
68 // directly.
69 String path = CtfTmfTestTraceUtils.getTrace(testTrace).getPath();
70
71 try {
72 trace = new LttngKernelTrace();
73 module = new KernelAnalysisModule();
74 module.setId("test");
75 trace.initTrace(null, path, CtfTmfEvent.class);
76 module.setTrace(trace);
77
78 pm.start();
79 TmfTestHelper.executeAnalysis(module);
80 pm.stop();
81
82 /*
83 * Delete the supplementary files, so that the next iteration
84 * rebuilds the state system.
85 */
86 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
87 for (File file : suppDir.listFiles()) {
88 file.delete();
89 }
90
91 } catch (TmfAnalysisException | TmfTraceException e) {
92 fail(e.getMessage());
93 } finally {
94 if (module != null) {
95 module.dispose();
96 }
97 if (trace != null) {
98 trace.dispose();
99 }
100 }
101 }
102 pm.commit();
103 CtfTmfTestTraceUtils.dispose(testTrace);
104 }
105 }
This page took 0.032878 seconds and 4 git commands to generate.