1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.event
.matchandsync
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assume
.assumeTrue
;
18 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
.TcpEventMatching
;
19 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
.TcpLttngEventMatching
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TmfEventMatching
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.ITmfTimestampTransform
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.SynchronizationAlgorithm
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.TimestampTransformFactory
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.experiment
.TmfExperiment
;
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
;
32 * Tests for experiment syncing
34 * @author Geneviève Bastien
36 @SuppressWarnings("nls")
37 public class ExperimentSyncTest
{
39 private static final String EXPERIMENT
= "MyExperiment";
40 private static int BLOCK_SIZE
= 1000;
43 * Initialize some data
46 public static void setUp() {
47 TmfEventMatching
.registerMatchObject(new TcpEventMatching());
48 TmfEventMatching
.registerMatchObject(new TcpLttngEventMatching());
52 * Testing experiment synchronization
55 public void testExperimentSync() {
56 assumeTrue(CtfTmfTestTrace
.SYNC_SRC
.exists());
57 assumeTrue(CtfTmfTestTrace
.SYNC_DEST
.exists());
58 try (CtfTmfTrace trace1
= CtfTmfTestTrace
.SYNC_SRC
.getTrace();
59 CtfTmfTrace trace2
= CtfTmfTestTrace
.SYNC_DEST
.getTrace();) {
61 ITmfTrace
[] traces
= { trace1
, trace2
};
62 TmfExperiment experiment
= new TmfExperiment(traces
[0].getEventType(), EXPERIMENT
, traces
, BLOCK_SIZE
, null);
64 SynchronizationAlgorithm syncAlgo
= experiment
.synchronizeTraces(true);
66 ITmfTimestampTransform tt1
= syncAlgo
.getTimestampTransform(trace1
);
67 ITmfTimestampTransform tt2
= syncAlgo
.getTimestampTransform(trace2
);
69 trace1
.setTimestampTransform(tt1
);
70 trace2
.setTimestampTransform(tt2
);
72 assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999413783703139011056845831168394, offset = 79796507913179.33347660124688298171 ]", tt1
.toString());
73 assertEquals(TimestampTransformFactory
.getDefaultTransform(), tt2
);
75 assertEquals(syncAlgo
.getTimestampTransform(trace1
.getHostId()), trace1
.getTimestampTransform());
76 assertEquals(syncAlgo
.getTimestampTransform(trace2
.getHostId()), trace2
.getTimestampTransform());
82 * Testing synchronization with 3 traces, one of which synchronizes with
86 public void testDjangoExperimentSync() {
87 assumeTrue(CtfTmfTestTrace
.DJANGO_CLIENT
.exists());
88 assumeTrue(CtfTmfTestTrace
.DJANGO_DB
.exists());
89 assumeTrue(CtfTmfTestTrace
.DJANGO_HTTPD
.exists());
90 try (CtfTmfTrace trace1
= CtfTmfTestTrace
.DJANGO_CLIENT
.getTrace();
91 CtfTmfTrace trace2
= CtfTmfTestTrace
.DJANGO_DB
.getTrace();
92 CtfTmfTrace trace3
= CtfTmfTestTrace
.DJANGO_HTTPD
.getTrace();) {
93 ITmfTrace
[] traces
= { trace1
, trace2
, trace3
};
94 TmfExperiment experiment
= new TmfExperiment(traces
[0].getEventType(), EXPERIMENT
, traces
, BLOCK_SIZE
, null);
96 SynchronizationAlgorithm syncAlgo
= experiment
.synchronizeTraces(true);
98 ITmfTimestampTransform tt1
= syncAlgo
.getTimestampTransform(trace1
);
99 ITmfTimestampTransform tt2
= syncAlgo
.getTimestampTransform(trace2
);
100 ITmfTimestampTransform tt3
= syncAlgo
.getTimestampTransform(trace3
);
102 trace1
.setTimestampTransform(tt1
);
103 trace2
.setTimestampTransform(tt2
);
104 trace3
.setTimestampTransform(tt3
);
106 assertEquals(TimestampTransformFactory
.getDefaultTransform(), tt1
);
107 assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999996313017589597204633828681240, offset = 498490309972.0038068817738527724192 ]", tt2
.toString());
108 assertEquals("TmfTimestampTransformLinearFast [ slope = 1.000000119014882262265342419815932, offset = -166652893534.6189900382736187431134 ]", tt3
.toString());