TMF: Synchronize an experiment instead of collection of traces
[deliverable/tracecompass.git] / 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
GB
16import static org.junit.Assume.assumeTrue;
17
4d2a4a2c 18import java.util.Collections;
e7e04cb1 19
ef3a9bfd
GB
20import org.eclipse.test.performance.Dimension;
21import org.eclipse.test.performance.Performance;
22import org.eclipse.test.performance.PerformanceMeter;
9bc60be7
AM
23import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpEventMatching;
24import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
2bdf0193
AM
25import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching;
26import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
27import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationManager;
28import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
4d2a4a2c
GB
29import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
30import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
2bdf0193 31import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
9722e5d7 32import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
ef3a9bfd 33import org.junit.BeforeClass;
ef3a9bfd
GB
34import org.junit.Test;
35
36/**
37 * Benchmark trace synchronization
38 *
39 * @author Geneviève Bastien
40 */
41public class TraceSynchronizationBenchmark {
42
b09d20dc 43 private static final String TEST_ID = "org.eclipse.linuxtools#Trace synchronization#";
ef3a9bfd
GB
44 private static final String TIME = " (time)";
45 private static final String MEMORY = " (memory usage)";
46 private static final String TEST_SUMMARY = "Trace synchronization";
ef3a9bfd
GB
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 try (CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
65 CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();) {
66 ITmfTrace[] traces = { trace1, trace2 };
4d2a4a2c
GB
67 TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class, "Test experiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
68 runCpuTest(experiment, "Match TCP events", 40);
ef3a9bfd
GB
69 }
70 }
71
72 /**
73 * Run the benchmark with 3 bigger traces
ef3a9bfd 74 */
ef3a9bfd
GB
75 @Test
76 public void testDjangoTraces() {
77 assumeTrue(CtfTmfTestTrace.DJANGO_CLIENT.exists());
78 assumeTrue(CtfTmfTestTrace.DJANGO_DB.exists());
79 assumeTrue(CtfTmfTestTrace.DJANGO_HTTPD.exists());
80 try (CtfTmfTrace trace1 = CtfTmfTestTrace.DJANGO_CLIENT.getTrace();
81 CtfTmfTrace trace2 = CtfTmfTestTrace.DJANGO_DB.getTrace();
82 CtfTmfTrace trace3 = CtfTmfTestTrace.DJANGO_HTTPD.getTrace();) {
83 ITmfTrace[] traces = { trace1, trace2, trace3 };
4d2a4a2c
GB
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);
ef3a9bfd
GB
87 }
88 }
89
4d2a4a2c 90 private static void runCpuTest(TmfExperiment experiment, String testName, int loop_count) {
ef3a9bfd 91 Performance perf = Performance.getDefault();
b09d20dc
GB
92 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + TIME);
93 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + TIME, Dimension.CPU_TIME);
ef3a9bfd
GB
94
95 for (int i = 0; i < loop_count; i++) {
ef3a9bfd 96 pm.start();
4d2a4a2c 97 SynchronizationManager.synchronizeTraces(null, Collections.<ITmfTrace> singleton(experiment), true);
ef3a9bfd 98 pm.stop();
ef3a9bfd
GB
99 }
100 pm.commit();
101
102 }
103
104 /* Benchmark memory used by the algorithm */
4d2a4a2c 105 private static void runMemoryTest(TmfExperiment experiment, String testName, int loop_count) {
ef3a9bfd 106 Performance perf = Performance.getDefault();
b09d20dc
GB
107 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY);
108 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP);
ef3a9bfd
GB
109
110 for (int i = 0; i < loop_count; i++) {
ef3a9bfd
GB
111
112 System.gc();
113 pm.start();
4d2a4a2c 114 SynchronizationAlgorithm algo = SynchronizationManager.synchronizeTraces(null, Collections.<ITmfTrace> singleton(experiment), true);
e7e04cb1
GB
115 assertNotNull(algo);
116
ef3a9bfd
GB
117 System.gc();
118 pm.stop();
ef3a9bfd
GB
119 }
120 pm.commit();
121 }
122}
This page took 0.036748 seconds and 5 git commands to generate.