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