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 | |
ef3a9bfd GB |
15 | import java.util.Set; |
16 | ||
ef3a9bfd GB |
17 | import org.eclipse.test.performance.Dimension; |
18 | import org.eclipse.test.performance.Performance; | |
19 | import org.eclipse.test.performance.PerformanceMeter; | |
dc327459 GB |
20 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpEventMatching; |
21 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpLttngEventMatching; | |
c4d57ac1 | 22 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
2bdf0193 | 23 | import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching; |
2bdf0193 | 24 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
c4d57ac1 | 25 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils; |
9722e5d7 | 26 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
ef3a9bfd | 27 | import org.junit.BeforeClass; |
ef3a9bfd GB |
28 | import org.junit.Test; |
29 | ||
30 | import com.google.common.collect.ImmutableSet; | |
31 | ||
32 | /** | |
33 | * Benchmark simple event matching, without trace synchronization | |
34 | * | |
35 | * @author Geneviève Bastien | |
36 | */ | |
37 | public class EventMatchingBenchmark { | |
38 | ||
b09d20dc | 39 | private static final String TEST_ID = "org.eclipse.linuxtools#Event matching#"; |
ef3a9bfd GB |
40 | private static final String TIME = " (time)"; |
41 | private static final String MEMORY = " (memory usage)"; | |
42 | private static final String TEST_SUMMARY = "Event matching"; | |
43 | ||
44 | /** | |
45 | * Initialize some data | |
46 | */ | |
47 | @BeforeClass | |
48 | public static void setUp() { | |
49 | TmfEventMatching.registerMatchObject(new TcpEventMatching()); | |
50 | TmfEventMatching.registerMatchObject(new TcpLttngEventMatching()); | |
51 | } | |
52 | ||
53 | /** | |
54 | * Run the benchmark with 2 small traces | |
55 | */ | |
56 | @Test | |
57 | public void testSmallTraces() { | |
c4d57ac1 AM |
58 | CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_SRC); |
59 | CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_DEST); | |
0ff9e595 AM |
60 | |
61 | Set<ITmfTrace> traces = ImmutableSet.of((ITmfTrace) trace1, trace2); | |
62 | runCpuTest(traces, "Match TCP events", 100); | |
63 | ||
64 | trace1.dispose(); | |
65 | trace2.dispose(); | |
66 | ||
ef3a9bfd GB |
67 | } |
68 | ||
69 | /** | |
70 | * Run the benchmark with 3 bigger traces | |
ef3a9bfd | 71 | */ |
ef3a9bfd GB |
72 | @Test |
73 | public void testDjangoTraces() { | |
c4d57ac1 AM |
74 | CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_CLIENT); |
75 | CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_DB); | |
76 | CtfTmfTrace trace3 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_HTTPD); | |
0ff9e595 AM |
77 | |
78 | Set<ITmfTrace> traces = ImmutableSet.of((ITmfTrace) trace1, trace2, trace3); | |
79 | runCpuTest(traces, "Django traces", 10); | |
80 | runMemoryTest(traces, "Django traces", 10); | |
81 | ||
82 | trace1.dispose(); | |
83 | trace2.dispose(); | |
84 | trace3.dispose(); | |
ef3a9bfd GB |
85 | } |
86 | ||
87 | private static void runCpuTest(Set<ITmfTrace> testTraces, String testName, int loop_count) { | |
88 | Performance perf = Performance.getDefault(); | |
b09d20dc GB |
89 | PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + TIME); |
90 | perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + TIME, Dimension.CPU_TIME); | |
ef3a9bfd GB |
91 | |
92 | for (int i = 0; i < loop_count; i++) { | |
92bf3802 | 93 | TmfEventMatching traceMatch = new TmfEventMatching(testTraces); |
ef3a9bfd GB |
94 | |
95 | pm.start(); | |
96 | traceMatch.matchEvents(); | |
97 | pm.stop(); | |
98 | } | |
99 | pm.commit(); | |
100 | ||
101 | } | |
102 | ||
103 | /* Benchmark memory used by the algorithm */ | |
104 | private static void runMemoryTest(Set<ITmfTrace> testTraces, String testName, int loop_count) { | |
105 | Performance perf = Performance.getDefault(); | |
b09d20dc GB |
106 | PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY); |
107 | perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP); | |
ef3a9bfd GB |
108 | |
109 | for (int i = 0; i < loop_count; i++) { | |
92bf3802 | 110 | TmfEventMatching traceMatch = new TmfEventMatching(testTraces); |
ef3a9bfd GB |
111 | |
112 | System.gc(); | |
113 | pm.start(); | |
114 | traceMatch.matchEvents(); | |
115 | System.gc(); | |
116 | pm.stop(); | |
117 | } | |
118 | pm.commit(); | |
119 | ||
120 | } | |
121 | } |