4e35cf47163bce9c2309776b2033fd6c37d75373
[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 static org.junit.Assume.assumeTrue;
16
17 import java.util.Set;
18
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.trace.ITmfTrace;
26 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
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 assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
60 assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
61 try (CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
62 CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();) {
63 Set<ITmfTrace> traces = ImmutableSet.of((ITmfTrace) trace1, trace2);
64 runCpuTest(traces, "Match TCP events", 100);
65 }
66 }
67
68 /**
69 * Run the benchmark with 3 bigger traces
70 */
71 @Test
72 public void testDjangoTraces() {
73 assumeTrue(CtfTmfTestTrace.DJANGO_CLIENT.exists());
74 assumeTrue(CtfTmfTestTrace.DJANGO_DB.exists());
75 assumeTrue(CtfTmfTestTrace.DJANGO_HTTPD.exists());
76 try (CtfTmfTrace trace1 = CtfTmfTestTrace.DJANGO_CLIENT.getTrace();
77 CtfTmfTrace trace2 = CtfTmfTestTrace.DJANGO_DB.getTrace();
78 CtfTmfTrace trace3 = CtfTmfTestTrace.DJANGO_HTTPD.getTrace();) {
79 Set<ITmfTrace> traces = ImmutableSet.of((ITmfTrace) trace1, trace2, trace3);
80 runCpuTest(traces, "Django traces", 10);
81 runMemoryTest(traces, "Django traces", 10);
82 }
83 }
84
85 private static void runCpuTest(Set<ITmfTrace> testTraces, String testName, int loop_count) {
86 Performance perf = Performance.getDefault();
87 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + TIME);
88 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + TIME, Dimension.CPU_TIME);
89
90 for (int i = 0; i < loop_count; i++) {
91 TmfEventMatching traceMatch = new TmfEventMatching(testTraces);
92
93 pm.start();
94 traceMatch.matchEvents();
95 pm.stop();
96 }
97 pm.commit();
98
99 }
100
101 /* Benchmark memory used by the algorithm */
102 private static void runMemoryTest(Set<ITmfTrace> testTraces, String testName, int loop_count) {
103 Performance perf = Performance.getDefault();
104 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY);
105 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP);
106
107 for (int i = 0; i < loop_count; i++) {
108 TmfEventMatching traceMatch = new TmfEventMatching(testTraces);
109
110 System.gc();
111 pm.start();
112 traceMatch.matchEvents();
113 System.gc();
114 pm.stop();
115 }
116 pm.commit();
117
118 }
119 }
This page took 0.035253 seconds and 4 git commands to generate.