1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.tests
.perf
.event
.matching
;
15 import static org
.junit
.Assert
.fail
;
16 import static org
.junit
.Assume
.assumeTrue
;
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
;
35 * Benchmark trace synchronization
37 * @author Geneviève Bastien
39 public class TraceSynchronizationBenchmark
{
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;
48 * Initialize some data
51 public static void setUp() {
52 TmfEventMatching
.registerMatchObject(new TcpEventMatching());
53 TmfEventMatching
.registerMatchObject(new TcpLttngEventMatching());
57 * Run the benchmark with 2 small traces
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);
71 * Run the benchmark with 3 bigger traces
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
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);
91 private static void runCpuTest(ITmfTrace
[] testTraces
, String testName
, int loop_count
) {
92 Performance perf
= Performance
.getDefault();
93 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ TIME
+ '#' + testName
);
94 perf
.tagAsSummary(pm
, TEST_SUMMARY
+ TIME
+ ':' + testName
, Dimension
.CPU_TIME
);
96 for (int i
= 0; i
< loop_count
; i
++) {
97 TmfExperiment experiment
= new TmfExperiment(CtfTmfEvent
.class, "Test experiment", testTraces
, BLOCK_SIZE
);
101 experiment
.synchronizeTraces(true);
102 } catch (TmfTraceException e
) {
103 fail("Failed at iteration " + i
+ " with message: " + e
.getMessage());
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
+ MEMORY
+ '#' + testName
);
116 perf
.tagAsSummary(pm
, TEST_SUMMARY
+ MEMORY
+ ':' + testName
, Dimension
.USED_JAVA_HEAP
);
118 for (int i
= 0; i
< loop_count
; i
++) {
119 TmfExperiment experiment
= new TmfExperiment(CtfTmfEvent
.class, "Test experiment", testTraces
, BLOCK_SIZE
);
124 experiment
.synchronizeTraces(true);
125 } catch (TmfTraceException e
) {
126 fail("Failed at iteration " + i
+ " with message: " + e
.getMessage());