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
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 14
ef3a9bfd
GB
15import java.util.Set;
16
aa353506 17import org.eclipse.jdt.annotation.NonNull;
ef3a9bfd
GB
18import org.eclipse.test.performance.Dimension;
19import org.eclipse.test.performance.Performance;
20import org.eclipse.test.performance.PerformanceMeter;
dc327459
GB
21import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpEventMatching;
22import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
c4d57ac1 23import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
2bdf0193 24import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching;
2bdf0193 25import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
c4d57ac1 26import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
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() {
c4d57ac1
AM
59 CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_SRC);
60 CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_DEST);
0ff9e595 61
aa353506 62 Set<@NonNull ITmfTrace> traces = ImmutableSet.of(trace1, trace2);
0ff9e595
AM
63 runCpuTest(traces, "Match TCP events", 100);
64
65 trace1.dispose();
66 trace2.dispose();
67
ef3a9bfd
GB
68 }
69
70 /**
71 * Run the benchmark with 3 bigger traces
ef3a9bfd 72 */
ef3a9bfd
GB
73 @Test
74 public void testDjangoTraces() {
c4d57ac1
AM
75 CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_CLIENT);
76 CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_DB);
77 CtfTmfTrace trace3 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_HTTPD);
0ff9e595 78
aa353506 79 Set<@NonNull ITmfTrace> traces = ImmutableSet.of(trace1, trace2, trace3);
0ff9e595
AM
80 runCpuTest(traces, "Django traces", 10);
81 runMemoryTest(traces, "Django traces", 10);
82
83 trace1.dispose();
84 trace2.dispose();
85 trace3.dispose();
ef3a9bfd
GB
86 }
87
aa353506 88 private static void runCpuTest(Set<@NonNull ITmfTrace> testTraces, String testName, int loop_count) {
ef3a9bfd 89 Performance perf = Performance.getDefault();
b09d20dc
GB
90 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + TIME);
91 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + TIME, Dimension.CPU_TIME);
ef3a9bfd
GB
92
93 for (int i = 0; i < loop_count; i++) {
92bf3802 94 TmfEventMatching traceMatch = new TmfEventMatching(testTraces);
ef3a9bfd
GB
95
96 pm.start();
97 traceMatch.matchEvents();
98 pm.stop();
99 }
100 pm.commit();
101
102 }
103
104 /* Benchmark memory used by the algorithm */
aa353506 105 private static void runMemoryTest(Set<@NonNull ITmfTrace> testTraces, String testName, int loop_count) {
ef3a9bfd 106 Performance perf = Performance.getDefault();
b09d20dc
GB
107 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY);
108 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP);
ef3a9bfd
GB
109
110 for (int i = 0; i < loop_count; i++) {
92bf3802 111 TmfEventMatching traceMatch = new TmfEventMatching(testTraces);
ef3a9bfd
GB
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.057685 seconds and 5 git commands to generate.