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