Commit | Line | Data |
---|---|---|
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 | 13 | package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.event.matching; |
ef3a9bfd | 14 | |
e7e04cb1 | 15 | import static org.junit.Assert.assertNotNull; |
ef3a9bfd | 16 | |
4d2a4a2c | 17 | import java.util.Collections; |
e7e04cb1 | 18 | |
ef3a9bfd GB |
19 | import org.eclipse.test.performance.Dimension; |
20 | import org.eclipse.test.performance.Performance; | |
21 | import org.eclipse.test.performance.PerformanceMeter; | |
dc327459 GB |
22 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpEventMatching; |
23 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpLttngEventMatching; | |
c4d57ac1 | 24 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
2bdf0193 AM |
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; | |
4d2a4a2c GB |
29 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
30 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; | |
c4d57ac1 | 31 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils; |
9722e5d7 | 32 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
ef3a9bfd | 33 | import org.junit.BeforeClass; |
ef3a9bfd GB |
34 | import org.junit.Test; |
35 | ||
36 | /** | |
37 | * Benchmark trace synchronization | |
38 | * | |
39 | * @author Geneviève Bastien | |
40 | */ | |
41 | public 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() { | |
c4d57ac1 AM |
62 | CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_SRC); |
63 | CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_DEST); | |
0ff9e595 AM |
64 | |
65 | ITmfTrace[] traces = { trace1, trace2 }; | |
66 | TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class, "Test experiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null); | |
67 | runCpuTest(experiment, "Match TCP events", 40); | |
68 | ||
69 | trace1.dispose(); | |
70 | trace2.dispose(); | |
ef3a9bfd GB |
71 | } |
72 | ||
73 | /** | |
74 | * Run the benchmark with 3 bigger traces | |
ef3a9bfd | 75 | */ |
ef3a9bfd GB |
76 | @Test |
77 | public void testDjangoTraces() { | |
c4d57ac1 AM |
78 | CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_CLIENT); |
79 | CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_DB); | |
80 | CtfTmfTrace trace3 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_HTTPD); | |
0ff9e595 AM |
81 | |
82 | ITmfTrace[] traces = { trace1, trace2, trace3 }; | |
83 | TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class, "Test experiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null); | |
84 | runCpuTest(experiment, "Django traces", 10); | |
85 | runMemoryTest(experiment, "Django traces", 10); | |
86 | ||
87 | trace1.dispose(); | |
88 | trace2.dispose(); | |
89 | trace3.dispose(); | |
ef3a9bfd GB |
90 | } |
91 | ||
4d2a4a2c | 92 | private static void runCpuTest(TmfExperiment experiment, String testName, int loop_count) { |
ef3a9bfd | 93 | Performance perf = Performance.getDefault(); |
b09d20dc GB |
94 | PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + TIME); |
95 | perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + TIME, Dimension.CPU_TIME); | |
ef3a9bfd GB |
96 | |
97 | for (int i = 0; i < loop_count; i++) { | |
ef3a9bfd | 98 | pm.start(); |
4d2a4a2c | 99 | SynchronizationManager.synchronizeTraces(null, Collections.<ITmfTrace> singleton(experiment), true); |
ef3a9bfd | 100 | pm.stop(); |
ef3a9bfd GB |
101 | } |
102 | pm.commit(); | |
103 | ||
104 | } | |
105 | ||
106 | /* Benchmark memory used by the algorithm */ | |
4d2a4a2c | 107 | private static void runMemoryTest(TmfExperiment experiment, String testName, int loop_count) { |
ef3a9bfd | 108 | Performance perf = Performance.getDefault(); |
b09d20dc GB |
109 | PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY); |
110 | perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP); | |
ef3a9bfd GB |
111 | |
112 | for (int i = 0; i < loop_count; i++) { | |
ef3a9bfd GB |
113 | |
114 | System.gc(); | |
115 | pm.start(); | |
4d2a4a2c | 116 | SynchronizationAlgorithm algo = SynchronizationManager.synchronizeTraces(null, Collections.<ITmfTrace> singleton(experiment), true); |
e7e04cb1 GB |
117 | assertNotNull(algo); |
118 | ||
ef3a9bfd GB |
119 | System.gc(); |
120 | pm.stop(); | |
ef3a9bfd GB |
121 | } |
122 | pm.commit(); | |
123 | } | |
124 | } |