ae37bf0da18a97911a70c262a5e096e749ab2f17
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / perf / org / eclipse / linuxtools / lttng2 / kernel / core / tests / perf / analysis / AnalysisBenchmark.java
1 /*******************************************************************************
2 * Copyright (c) 2014 É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.linuxtools.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.linuxtools.lttng2.kernel.core.analysis.LttngKernelAnalysisModule;
22 import org.eclipse.linuxtools.lttng2.kernel.core.trace.LttngKernelTrace;
23 import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
24 import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
25 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
26 import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestHelper;
27 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
28 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent;
29 import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
30 import org.eclipse.test.performance.Dimension;
31 import org.eclipse.test.performance.Performance;
32 import org.eclipse.test.performance.PerformanceMeter;
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 try (IAnalysisModule module = new LttngKernelAnalysisModule();
67 LttngKernelTrace trace = new LttngKernelTrace()) {
68 module.setId("test");
69 trace.initTrace(null, testTrace.getPath(), CtfTmfEvent.class);
70 module.setTrace(trace);
71
72 pm.start();
73 TmfTestHelper.executeAnalysis(module);
74 pm.stop();
75
76 /*
77 * Delete the supplementary files, so that the next iteration
78 * rebuilds the state system.
79 */
80 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
81 for (File file : suppDir.listFiles()) {
82 file.delete();
83 }
84
85 } catch (TmfAnalysisException | TmfTraceException e) {
86 fail(e.getMessage());
87 }
88
89 }
90 pm.commit();
91 testTrace.dispose();
92 }
93 }
This page took 0.034422 seconds and 4 git commands to generate.