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
.tracecompass
.lttng2
.kernel
.core
.tests
.perf
.event
.matching
;
15 import static org
.junit
.Assert
.assertNotNull
;
17 import java
.util
.Collections
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.test
.performance
.Dimension
;
21 import org
.eclipse
.test
.performance
.Performance
;
22 import org
.eclipse
.test
.performance
.PerformanceMeter
;
23 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
.TcpEventMatching
;
24 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
.TcpLttngEventMatching
;
25 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TmfEventMatching
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.SynchronizationAlgorithm
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.SynchronizationManager
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.experiment
.TmfExperiment
;
31 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
32 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
33 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
34 import org
.junit
.BeforeClass
;
35 import org
.junit
.Test
;
38 * Benchmark trace synchronization
40 * @author Geneviève Bastien
42 public class TraceSynchronizationBenchmark
{
44 private static final String TEST_ID
= "org.eclipse.linuxtools#Trace synchronization#";
45 private static final String TIME
= " (time)";
46 private static final String MEMORY
= " (memory usage)";
47 private static final String TEST_SUMMARY
= "Trace synchronization";
50 * Initialize some data
53 public static void setUp() {
54 TmfEventMatching
.registerMatchObject(new TcpEventMatching());
55 TmfEventMatching
.registerMatchObject(new TcpLttngEventMatching());
59 * Run the benchmark with 2 small traces
62 public void testSmallTraces() {
63 CtfTmfTrace trace1
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.SYNC_SRC
);
64 CtfTmfTrace trace2
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.SYNC_DEST
);
66 ITmfTrace
[] traces
= { trace1
, trace2
};
67 TmfExperiment experiment
= new TmfExperiment(CtfTmfEvent
.class, "Test experiment", traces
, TmfExperiment
.DEFAULT_INDEX_PAGE_SIZE
, null);
68 runCpuTest(experiment
, "Match TCP events", 40);
75 * Run the benchmark with 3 bigger traces
78 public void testDjangoTraces() {
79 CtfTmfTrace trace1
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.DJANGO_CLIENT
);
80 CtfTmfTrace trace2
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.DJANGO_DB
);
81 CtfTmfTrace trace3
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.DJANGO_HTTPD
);
83 ITmfTrace
[] traces
= { trace1
, trace2
, trace3
};
84 TmfExperiment experiment
= new TmfExperiment(CtfTmfEvent
.class, "Test experiment", traces
, TmfExperiment
.DEFAULT_INDEX_PAGE_SIZE
, null);
85 runCpuTest(experiment
, "Django traces", 10);
86 runMemoryTest(experiment
, "Django traces", 10);
93 private static void runCpuTest(@NonNull TmfExperiment experiment
, String testName
, int loop_count
) {
94 Performance perf
= Performance
.getDefault();
95 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ testName
+ TIME
);
96 perf
.tagAsSummary(pm
, TEST_SUMMARY
+ ':' + testName
+ TIME
, Dimension
.CPU_TIME
);
98 for (int i
= 0; i
< loop_count
; i
++) {
100 SynchronizationManager
.synchronizeTraces(null, Collections
.singleton(experiment
), true);
107 /* Benchmark memory used by the algorithm */
108 private static void runMemoryTest(@NonNull TmfExperiment experiment
, String testName
, int loop_count
) {
109 Performance perf
= Performance
.getDefault();
110 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ testName
+ MEMORY
);
111 perf
.tagAsSummary(pm
, TEST_SUMMARY
+ ':' + testName
+ MEMORY
, Dimension
.USED_JAVA_HEAP
);
113 for (int i
= 0; i
< loop_count
; i
++) {
117 SynchronizationAlgorithm algo
= SynchronizationManager
.synchronizeTraces(null, Collections
.singleton(experiment
), true);