1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.perf
.event
.matching
;
15 import static org
.junit
.Assume
.assumeTrue
;
19 import org
.eclipse
.test
.performance
.Dimension
;
20 import org
.eclipse
.test
.performance
.Performance
;
21 import org
.eclipse
.test
.performance
.PerformanceMeter
;
22 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
.TcpEventMatching
;
23 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
.TcpLttngEventMatching
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TmfEventMatching
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TmfNetworkEventMatching
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
28 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
29 import org
.junit
.BeforeClass
;
30 import org
.junit
.Test
;
32 import com
.google
.common
.collect
.ImmutableSet
;
35 * Benchmark simple event matching, without trace synchronization
37 * @author Geneviève Bastien
39 public class EventMatchingBenchmark
{
41 private static final String TEST_ID
= "org.eclipse.linuxtools#Event matching#";
42 private static final String TIME
= " (time)";
43 private static final String MEMORY
= " (memory usage)";
44 private static final String TEST_SUMMARY
= "Event matching";
47 * Initialize some data
50 public static void setUp() {
51 TmfEventMatching
.registerMatchObject(new TcpEventMatching());
52 TmfEventMatching
.registerMatchObject(new TcpLttngEventMatching());
56 * Run the benchmark with 2 small traces
59 public void testSmallTraces() {
60 assumeTrue(CtfTmfTestTrace
.SYNC_SRC
.exists());
61 assumeTrue(CtfTmfTestTrace
.SYNC_DEST
.exists());
62 try (CtfTmfTrace trace1
= CtfTmfTestTrace
.SYNC_SRC
.getTrace();
63 CtfTmfTrace trace2
= CtfTmfTestTrace
.SYNC_DEST
.getTrace();) {
64 Set
<ITmfTrace
> traces
= ImmutableSet
.of((ITmfTrace
) trace1
, trace2
);
65 runCpuTest(traces
, "Match TCP events", 100);
70 * Run the benchmark with 3 bigger traces
73 public void testDjangoTraces() {
74 assumeTrue(CtfTmfTestTrace
.DJANGO_CLIENT
.exists());
75 assumeTrue(CtfTmfTestTrace
.DJANGO_DB
.exists());
76 assumeTrue(CtfTmfTestTrace
.DJANGO_HTTPD
.exists());
77 try (CtfTmfTrace trace1
= CtfTmfTestTrace
.DJANGO_CLIENT
.getTrace();
78 CtfTmfTrace trace2
= CtfTmfTestTrace
.DJANGO_DB
.getTrace();
79 CtfTmfTrace trace3
= CtfTmfTestTrace
.DJANGO_HTTPD
.getTrace();) {
80 Set
<ITmfTrace
> traces
= ImmutableSet
.of((ITmfTrace
) trace1
, trace2
, trace3
);
81 runCpuTest(traces
, "Django traces", 10);
82 runMemoryTest(traces
, "Django traces", 10);
86 private static void runCpuTest(Set
<ITmfTrace
> testTraces
, String testName
, int loop_count
) {
87 Performance perf
= Performance
.getDefault();
88 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ testName
+ TIME
);
89 perf
.tagAsSummary(pm
, TEST_SUMMARY
+ ':' + testName
+ TIME
, Dimension
.CPU_TIME
);
91 for (int i
= 0; i
< loop_count
; i
++) {
92 TmfNetworkEventMatching traceMatch
= new TmfNetworkEventMatching(testTraces
);
95 traceMatch
.matchEvents();
102 /* Benchmark memory used by the algorithm */
103 private static void runMemoryTest(Set
<ITmfTrace
> testTraces
, String testName
, int loop_count
) {
104 Performance perf
= Performance
.getDefault();
105 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ testName
+ MEMORY
);
106 perf
.tagAsSummary(pm
, TEST_SUMMARY
+ ':' + testName
+ MEMORY
, Dimension
.USED_JAVA_HEAP
);
108 for (int i
= 0; i
< loop_count
; i
++) {
109 TmfNetworkEventMatching traceMatch
= new TmfNetworkEventMatching(testTraces
);
113 traceMatch
.matchEvents();