ctf: Depend on the tracecompass-test-traces project
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / perf / org / eclipse / tracecompass / lttng2 / kernel / core / tests / perf / analysis / AnalysisBenchmark.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
9bc60be7 14package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.analysis;
72c787e2
GB
15
16import static org.junit.Assert.fail;
72c787e2
GB
17
18import java.io.File;
19
c4d57ac1 20import org.eclipse.jdt.annotation.NonNull;
72c787e2
GB
21import org.eclipse.test.performance.Dimension;
22import org.eclipse.test.performance.Performance;
23import org.eclipse.test.performance.PerformanceMeter;
6d16f5a9 24import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
9bc60be7 25import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
c4d57ac1 26import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
2bdf0193
AM
27import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
28import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
29import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
30import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
31import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
9722e5d7 32import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
c4d57ac1 33import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
72c787e2
GB
34import 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 */
41public class AnalysisBenchmark {
42
43 private static final String TEST_ID = "org.eclipse.linuxtools#LTTng kernel analysis";
f14c2f97 44 private static final int LOOP_COUNT = 25;
72c787e2
GB
45
46 /**
47 * Run the benchmark with "trace2"
48 */
49 @Test
50 public void testTrace2() {
c4d57ac1 51 runTest(CtfTestTrace.TRACE2, "Trace2");
72c787e2
GB
52 }
53
c4d57ac1 54 private static void runTest(@NonNull CtfTestTrace testTrace, String testName) {
72c787e2
GB
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
c4d57ac1 59 if (testTrace == CtfTestTrace.TRACE2) {
72c787e2
GB
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++) {
0ff9e595 65 LttngKernelTrace trace = null;
03f0b0b1 66 IAnalysisModule module = null;
c4d57ac1
AM
67 // TODO Allow the utility method to instantiate trace sub-types
68 // directly.
69 String path = CtfTmfTestTraceUtils.getTrace(testTrace).getPath();
70
0ff9e595
AM
71 try {
72 trace = new LttngKernelTrace();
6d16f5a9 73 module = new KernelAnalysisModule();
72c787e2 74 module.setId("test");
c4d57ac1 75 trace.initTrace(null, path, CtfTmfEvent.class);
72c787e2
GB
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());
03f0b0b1
AM
93 } finally {
94 if (module != null) {
95 module.dispose();
96 }
0ff9e595
AM
97 if (trace != null) {
98 trace.dispose();
99 }
72c787e2 100 }
72c787e2
GB
101 }
102 pm.commit();
c4d57ac1 103 CtfTmfTestTraceUtils.dispose(testTrace);
72c787e2
GB
104 }
105}
This page took 0.060946 seconds and 5 git commands to generate.