Fix some null warnings
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / perf / org / eclipse / tracecompass / lttng2 / kernel / core / tests / perf / event / matching / EventMatchingBenchmark.java
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
13 package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.event.matching;
14
15 import java.util.Set;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.test.performance.Dimension;
19 import org.eclipse.test.performance.Performance;
20 import org.eclipse.test.performance.PerformanceMeter;
21 import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpEventMatching;
22 import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
23 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
24 import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching;
25 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
26 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
27 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30
31 import com.google.common.collect.ImmutableSet;
32
33 /**
34 * Benchmark simple event matching, without trace synchronization
35 *
36 * @author Geneviève Bastien
37 */
38 public class EventMatchingBenchmark {
39
40 private static final String TEST_ID = "org.eclipse.linuxtools#Event matching#";
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 CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_SRC);
60 CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_DEST);
61
62 Set<@NonNull ITmfTrace> traces = ImmutableSet.of(trace1, trace2);
63 runCpuTest(traces, "Match TCP events", 100);
64
65 trace1.dispose();
66 trace2.dispose();
67
68 }
69
70 /**
71 * Run the benchmark with 3 bigger traces
72 */
73 @Test
74 public void testDjangoTraces() {
75 CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_CLIENT);
76 CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_DB);
77 CtfTmfTrace trace3 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_HTTPD);
78
79 Set<@NonNull ITmfTrace> traces = ImmutableSet.of(trace1, trace2, trace3);
80 runCpuTest(traces, "Django traces", 10);
81 runMemoryTest(traces, "Django traces", 10);
82
83 trace1.dispose();
84 trace2.dispose();
85 trace3.dispose();
86 }
87
88 private static void runCpuTest(Set<@NonNull ITmfTrace> testTraces, String testName, int loop_count) {
89 Performance perf = Performance.getDefault();
90 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + TIME);
91 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + TIME, Dimension.CPU_TIME);
92
93 for (int i = 0; i < loop_count; i++) {
94 TmfEventMatching traceMatch = new TmfEventMatching(testTraces);
95
96 pm.start();
97 traceMatch.matchEvents();
98 pm.stop();
99 }
100 pm.commit();
101
102 }
103
104 /* Benchmark memory used by the algorithm */
105 private static void runMemoryTest(Set<@NonNull ITmfTrace> testTraces, String testName, int loop_count) {
106 Performance perf = Performance.getDefault();
107 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY);
108 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP);
109
110 for (int i = 0; i < loop_count; i++) {
111 TmfEventMatching traceMatch = new TmfEventMatching(testTraces);
112
113 System.gc();
114 pm.start();
115 traceMatch.matchEvents();
116 System.gc();
117 pm.stop();
118 }
119 pm.commit();
120
121 }
122 }
This page took 0.041694 seconds and 5 git commands to generate.