ctf: Remove AutoCloseable from CtfTmfTrace
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / perf / org / eclipse / tracecompass / lttng2 / kernel / core / tests / perf / event / matching / TraceSynchronizationBenchmark.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 *******************************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.event.matching;
14
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assume.assumeTrue;
17
18 import java.util.Collections;
19
20 import org.eclipse.test.performance.Dimension;
21 import org.eclipse.test.performance.Performance;
22 import org.eclipse.test.performance.PerformanceMeter;
23 import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpEventMatching;
24 import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
25 import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching;
26 import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
27 import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationManager;
28 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
29 import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
30 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
31 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
32 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35
36 /**
37 * Benchmark trace synchronization
38 *
39 * @author Geneviève Bastien
40 */
41 public class TraceSynchronizationBenchmark {
42
43 private static final String TEST_ID = "org.eclipse.linuxtools#Trace synchronization#";
44 private static final String TIME = " (time)";
45 private static final String MEMORY = " (memory usage)";
46 private static final String TEST_SUMMARY = "Trace synchronization";
47
48 /**
49 * Initialize some data
50 */
51 @BeforeClass
52 public static void setUp() {
53 TmfEventMatching.registerMatchObject(new TcpEventMatching());
54 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
55 }
56
57 /**
58 * Run the benchmark with 2 small traces
59 */
60 @Test
61 public void testSmallTraces() {
62 assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
63 assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
64 CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
65 CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();
66
67 ITmfTrace[] traces = { trace1, trace2 };
68 TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class, "Test experiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
69 runCpuTest(experiment, "Match TCP events", 40);
70
71 trace1.dispose();
72 trace2.dispose();
73 }
74
75 /**
76 * Run the benchmark with 3 bigger traces
77 */
78 @Test
79 public void testDjangoTraces() {
80 assumeTrue(CtfTmfTestTrace.DJANGO_CLIENT.exists());
81 assumeTrue(CtfTmfTestTrace.DJANGO_DB.exists());
82 assumeTrue(CtfTmfTestTrace.DJANGO_HTTPD.exists());
83
84 CtfTmfTrace trace1 = CtfTmfTestTrace.DJANGO_CLIENT.getTrace();
85 CtfTmfTrace trace2 = CtfTmfTestTrace.DJANGO_DB.getTrace();
86 CtfTmfTrace trace3 = CtfTmfTestTrace.DJANGO_HTTPD.getTrace();
87
88 ITmfTrace[] traces = { trace1, trace2, trace3 };
89 TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class, "Test experiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
90 runCpuTest(experiment, "Django traces", 10);
91 runMemoryTest(experiment, "Django traces", 10);
92
93 trace1.dispose();
94 trace2.dispose();
95 trace3.dispose();
96 }
97
98 private static void runCpuTest(TmfExperiment experiment, String testName, int loop_count) {
99 Performance perf = Performance.getDefault();
100 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + TIME);
101 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + TIME, Dimension.CPU_TIME);
102
103 for (int i = 0; i < loop_count; i++) {
104 pm.start();
105 SynchronizationManager.synchronizeTraces(null, Collections.<ITmfTrace> singleton(experiment), true);
106 pm.stop();
107 }
108 pm.commit();
109
110 }
111
112 /* Benchmark memory used by the algorithm */
113 private static void runMemoryTest(TmfExperiment experiment, String testName, int loop_count) {
114 Performance perf = Performance.getDefault();
115 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY);
116 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP);
117
118 for (int i = 0; i < loop_count; i++) {
119
120 System.gc();
121 pm.start();
122 SynchronizationAlgorithm algo = SynchronizationManager.synchronizeTraces(null, Collections.<ITmfTrace> singleton(experiment), true);
123 assertNotNull(algo);
124
125 System.gc();
126 pm.stop();
127 }
128 pm.commit();
129 }
130 }
This page took 0.041318 seconds and 5 git commands to generate.