TMF: Update the benchmark's scenario ID to match our own spec
[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.fail;
16 import static org.junit.Assume.assumeTrue;
17
18 import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpEventMatching;
19 import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
20 import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventMatching;
21 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
22 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
23 import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
24 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent;
25 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
26 import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
27 import org.eclipse.test.performance.Dimension;
28 import org.eclipse.test.performance.Performance;
29 import org.eclipse.test.performance.PerformanceMeter;
30 import org.junit.BeforeClass;
31 import org.junit.Ignore;
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 private static int BLOCK_SIZE = 1000;
46
47 /**
48 * Initialize some data
49 */
50 @BeforeClass
51 public static void setUp() {
52 TmfEventMatching.registerMatchObject(new TcpEventMatching());
53 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
54 }
55
56 /**
57 * Run the benchmark with 2 small traces
58 */
59 @Test
60 public void testSmallTraces() {
61 assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
62 assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
63 try (CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
64 CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();) {
65 ITmfTrace[] traces = { trace1, trace2 };
66 runCpuTest(traces, "Match TCP events", 40);
67 }
68 }
69
70 /**
71 * Run the benchmark with 3 bigger traces
72 *
73 * TODO: For now, this test takes a lot of RAM. To run, remove the @Ignore
74 * and set at least 1024Mb RAM, or else there is OutOfMemoryError exception
75 */
76 @Ignore
77 @Test
78 public void testDjangoTraces() {
79 assumeTrue(CtfTmfTestTrace.DJANGO_CLIENT.exists());
80 assumeTrue(CtfTmfTestTrace.DJANGO_DB.exists());
81 assumeTrue(CtfTmfTestTrace.DJANGO_HTTPD.exists());
82 try (CtfTmfTrace trace1 = CtfTmfTestTrace.DJANGO_CLIENT.getTrace();
83 CtfTmfTrace trace2 = CtfTmfTestTrace.DJANGO_DB.getTrace();
84 CtfTmfTrace trace3 = CtfTmfTestTrace.DJANGO_HTTPD.getTrace();) {
85 ITmfTrace[] traces = { trace1, trace2, trace3 };
86 runCpuTest(traces, "Django traces", 10);
87 runMemoryTest(traces, "Django traces", 10);
88 }
89 }
90
91 private static void runCpuTest(ITmfTrace[] testTraces, String testName, int loop_count) {
92 Performance perf = Performance.getDefault();
93 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + TIME);
94 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + TIME, Dimension.CPU_TIME);
95
96 for (int i = 0; i < loop_count; i++) {
97 TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class, "Test experiment", testTraces, BLOCK_SIZE);
98
99 pm.start();
100 try {
101 experiment.synchronizeTraces(true);
102 } catch (TmfTraceException e) {
103 fail("Failed at iteration " + i + " with message: " + e.getMessage());
104 }
105 pm.stop();
106
107 }
108 pm.commit();
109
110 }
111
112 /* Benchmark memory used by the algorithm */
113 private static void runMemoryTest(ITmfTrace[] testTraces, String testName, int loop_count) {
114 Performance perf = Performance.getDefault();
115 PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY);
116 perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP);
117
118 for (int i = 0; i < loop_count; i++) {
119 TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class, "Test experiment", testTraces, BLOCK_SIZE);
120
121 System.gc();
122 pm.start();
123 try {
124 experiment.synchronizeTraces(true);
125 } catch (TmfTraceException e) {
126 fail("Failed at iteration " + i + " with message: " + e.getMessage());
127 }
128 System.gc();
129 pm.stop();
130
131 }
132 pm.commit();
133 }
134 }
This page took 0.035084 seconds and 6 git commands to generate.