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