gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / perf / org / eclipse / linuxtools / lttng2 / kernel / core / tests / perf / event / matching / TraceSynchronizationBenchmark.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.linuxtools.lttng2.kernel.core.tests.perf.event.matching;
14
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assume.assumeTrue;
17
18 import java.util.Arrays;
19
20 import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpEventMatching;
21 import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
22 import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventMatching;
23 import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationAlgorithm;
24 import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationManager;
25 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
26 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
27 import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
28 import org.eclipse.test.performance.Dimension;
29 import org.eclipse.test.performance.Performance;
30 import org.eclipse.test.performance.PerformanceMeter;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33
34 /**
35 * Benchmark trace synchronization
36 *
37 * @author Geneviève Bastien
38 */
39 public class TraceSynchronizationBenchmark {
40
41 private static final String TEST_ID = "org.eclipse.linuxtools#Trace synchronization#";
42 private static final String TIME = " (time)";
43 private static final String MEMORY = " (memory usage)";
44 private static final String TEST_SUMMARY = "Trace synchronization";
45
46 /**
47 * Initialize some data
48 */
49 @BeforeClass
50 public static void setUp() {
51 TmfEventMatching.registerMatchObject(new TcpEventMatching());
52 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
53 }
54
55 /**
56 * Run the benchmark with 2 small traces
57 */
58 @Test
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 ITmfTrace[] traces = { trace1, trace2 };
65 runCpuTest(traces, "Match TCP events", 40);
66 }
67 }
68
69 /**
70 * Run the benchmark with 3 bigger traces
71 */
72 @Test
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 ITmfTrace[] traces = { trace1, trace2, trace3 };
81 runCpuTest(traces, "Django traces", 10);
82 runMemoryTest(traces, "Django traces", 10);
83 }
84 }
85
86 private static void runCpuTest(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);
90
91 for (int i = 0; i < loop_count; i++) {
92 pm.start();
93 SynchronizationManager.synchronizeTraces(null, Arrays.asList(testTraces), true);
94 pm.stop();
95 }
96 pm.commit();
97
98 }
99
100 /* Benchmark memory used by the algorithm */
101 private static void runMemoryTest(ITmfTrace[] testTraces, String testName, int loop_count) {
102 Performance perf = Performance.getDefault();
103 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY);
104 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP);
105
106 for (int i = 0; i < loop_count; i++) {
107
108 System.gc();
109 pm.start();
110 SynchronizationAlgorithm algo = SynchronizationManager.synchronizeTraces(null, Arrays.asList(testTraces), true);
111 assertNotNull(algo);
112
113 System.gc();
114 pm.stop();
115 }
116 pm.commit();
117 }
118 }
This page took 0.033746 seconds and 5 git commands to generate.