import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
-import java.util.Arrays;
+import java.util.Collections;
import org.eclipse.test.performance.Dimension;
import org.eclipse.test.performance.Performance;
import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationManager;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.BeforeClass;
try (CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();) {
ITmfTrace[] traces = { trace1, trace2 };
- runCpuTest(traces, "Match TCP events", 40);
+ TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class, "Test experiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
+ runCpuTest(experiment, "Match TCP events", 40);
}
}
CtfTmfTrace trace2 = CtfTmfTestTrace.DJANGO_DB.getTrace();
CtfTmfTrace trace3 = CtfTmfTestTrace.DJANGO_HTTPD.getTrace();) {
ITmfTrace[] traces = { trace1, trace2, trace3 };
- runCpuTest(traces, "Django traces", 10);
- runMemoryTest(traces, "Django traces", 10);
+ TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class, "Test experiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
+ runCpuTest(experiment, "Django traces", 10);
+ runMemoryTest(experiment, "Django traces", 10);
}
}
- private static void runCpuTest(ITmfTrace[] testTraces, String testName, int loop_count) {
+ private static void runCpuTest(TmfExperiment experiment, String testName, int loop_count) {
Performance perf = Performance.getDefault();
PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + TIME);
perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + TIME, Dimension.CPU_TIME);
for (int i = 0; i < loop_count; i++) {
pm.start();
- SynchronizationManager.synchronizeTraces(null, Arrays.asList(testTraces), true);
+ SynchronizationManager.synchronizeTraces(null, Collections.<ITmfTrace> singleton(experiment), true);
pm.stop();
}
pm.commit();
}
/* Benchmark memory used by the algorithm */
- private static void runMemoryTest(ITmfTrace[] testTraces, String testName, int loop_count) {
+ private static void runMemoryTest(TmfExperiment experiment, String testName, int loop_count) {
Performance perf = Performance.getDefault();
PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY);
perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP);
System.gc();
pm.start();
- SynchronizationAlgorithm algo = SynchronizationManager.synchronizeTraces(null, Arrays.asList(testTraces), true);
+ SynchronizationAlgorithm algo = SynchronizationManager.synchronizeTraces(null, Collections.<ITmfTrace> singleton(experiment), true);
assertNotNull(algo);
System.gc();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpEventMatching;
import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
+import org.eclipse.tracecompass.tmf.core.event.matching.IMatchProcessingUnit;
import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching;
import org.eclipse.tracecompass.tmf.core.event.matching.TmfNetworkEventMatching;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
*/
@Test
public void testMatching() {
- final String cr = System.getProperty("line.separator");
assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
try (CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
TmfNetworkEventMatching twoTraceMatch = new TmfNetworkEventMatching(tracearr);
assertTrue(twoTraceMatch.matchEvents());
- String stats = twoTraceMatch.toString();
- assertEquals("TmfEventMatches [ Number of matches found: 46 ]" +
- "Trace 0:" + cr +
- " 3 unmatched incoming events" + cr +
- " 2 unmatched outgoing events" + cr +
- "Trace 1:" + cr +
- " 2 unmatched incoming events" + cr +
- " 1 unmatched outgoing events" + cr, stats);
+ /* Set method and fields accessible to make sure the counts are ok */
+ try {
+ /* Verify number of matches */
+ Method method = TmfEventMatching.class.getDeclaredMethod("getProcessingUnit");
+ method.setAccessible(true);
+ IMatchProcessingUnit procUnit = (IMatchProcessingUnit) method.invoke(twoTraceMatch);
+ assertEquals(46, procUnit.countMatches());
+
+ /* Verify unmatched incoming */
+ Field fieldIn = twoTraceMatch.getClass().getDeclaredField("fUnmatchedIn");
+ fieldIn.setAccessible(true);
+ Map<?, ?> unmatched = (Map<?, ?> ) fieldIn.get(twoTraceMatch);
+ Map<?, ?> unmatchedTrace = (Map<?, ?>) unmatched.get(trace1);
+ assertEquals(3, unmatchedTrace.size());
+ unmatchedTrace = (Map<?, ?>) unmatched.get(trace2);
+ assertEquals(2, unmatchedTrace.size());
+
+ /* Verify unmatched outgoing */
+ Field fieldOut = twoTraceMatch.getClass().getDeclaredField("fUnmatchedOut");
+ fieldOut.setAccessible(true);
+ unmatched = (Map<?, ?> ) fieldOut.get(twoTraceMatch);
+ unmatchedTrace = (Map<?, ?>) unmatched.get(trace1);
+ assertEquals(2, unmatchedTrace.size());
+ unmatchedTrace = (Map<?, ?>) unmatched.get(trace2);
+ assertEquals(1, unmatchedTrace.size());
+
+ } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchFieldException e) {
+ fail(e.getMessage());
+ }
}
}
/**
* IMatchProcessingUnit overrides
*/
-
@Override
public void init(Collection<ITmfTrace> fTraces) {
fMatchCount = 0;
package org.eclipse.tracecompass.tmf.core.event.matching;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
NETWORK
}
+ private static final Multimap<MatchingType, ITmfMatchEventDefinition> MATCH_DEFINITIONS = HashMultimap.create();
+
/**
* The array of traces to match
*/
*/
private final IMatchProcessingUnit fMatches;
- private static final Map<MatchingType, List<ITmfMatchEventDefinition>> fMatchDefinitions = new HashMap<>();
-
private final Multimap<ITmfTrace, ITmfMatchEventDefinition> fMatchMap = HashMultimap.create();
/**
if (tmfEventMatches == null) {
throw new IllegalArgumentException();
}
- fTraces = traces;
+ fTraces = new HashSet<>(traces);
fMatches = tmfEventMatches;
}
/**
- * Returns the traces to process
+ * Returns the traces to synchronize. These are the traces that were
+ * specified in the constructor, they may contain either traces or
+ * experiment.
*
- * @return The traces
+ * @return The traces to synchronize
*/
- protected Collection<? extends ITmfTrace> getTraces() {
- return fTraces;
+ protected Collection<ITmfTrace> getTraces() {
+ return new HashSet<>(fTraces);
+ }
+
+ /**
+ * Returns the individual traces to process. If some of the traces specified
+ * to synchronize in the constructor were experiments, only the traces
+ * contained in this experiment will be returned. No {@link TmfExperiment}
+ * are returned by this method.
+ *
+ * @return The individual traces to synchronize, no experiments
+ */
+ protected Collection<ITmfTrace> getIndividualTraces() {
+ Set<ITmfTrace> traces = new HashSet<>();
+ for (ITmfTrace trace : fTraces) {
+ traces.addAll(Arrays.asList(TmfTraceManager.getTraceSet(trace)));
+ }
+ return traces;
}
/**
*/
protected void initMatching() {
fMatches.init(fTraces);
- List<ITmfMatchEventDefinition> deflist = fMatchDefinitions.get(getMatchingType());
+ Collection<ITmfMatchEventDefinition> deflist = MATCH_DEFINITIONS.get(getMatchingType());
if (deflist == null) {
return;
}
- for (ITmfTrace trace : fTraces) {
+ for (ITmfTrace trace : getIndividualTraces()) {
for (ITmfMatchEventDefinition def : deflist) {
if (def.canMatchTrace(trace)) {
fMatchMap.put(trace, def);
*/
public static void registerMatchObject(ITmfMatchEventDefinition match) {
for (MatchingType type : match.getApplicableMatchingTypes()) {
- if (!fMatchDefinitions.containsKey(type)) {
- fMatchDefinitions.put(type, new ArrayList<ITmfMatchEventDefinition>());
- }
- fMatchDefinitions.get(type).add(match);
+ MATCH_DEFINITIONS.put(type, match);
}
}
// Initialize the matching infrastructure (unmatched event lists)
fUnmatchedIn.clear();
fUnmatchedOut.clear();
- for (ITmfTrace trace : getTraces()) {
+ for (ITmfTrace trace : getIndividualTraces()) {
fUnmatchedIn.put(trace, new HashMap<List<Object>, ITmfEvent>());
fUnmatchedOut.put(trace, new HashMap<List<Object>, ITmfEvent>());
}
* events as value for the unmatched table. Not necessary right now
* though
*/
- if (!unmatchedTbl.get(trace).containsKey(eventKey)) {
- unmatchedTbl.get(trace).put(eventKey, event);
+ if (!unmatchedTbl.get(event.getTrace()).containsKey(eventKey)) {
+ unmatchedTbl.get(event.getTrace()).put(eventKey, event);
}
}
StringBuilder b = new StringBuilder();
b.append(getProcessingUnit());
int i = 0;
- for (ITmfTrace trace : getTraces()) {
+ for (ITmfTrace trace : getIndividualTraces()) {
b.append("Trace " + i++ + ":" + cr +
" " + countEvents(fUnmatchedIn.get(trace)) + " unmatched incoming events" + cr +
" " + countEvents(fUnmatchedOut.get(trace)) + " unmatched outgoing events" + cr);
import java.io.File;
import java.nio.ByteBuffer;
-import java.util.Arrays;
+import java.util.Collections;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
*/
private boolean fInitialized = false;
+ /**
+ * Lock for synchronization methods. These methods cannot be 'synchronized'
+ * since it makes it impossible to use an event request on the experiment
+ * during synchronization (the request thread would block)
+ */
+ private final Lock fSyncLock = new ReentrantLock();
// ------------------------------------------------------------------------
// Construction
* @return The synchronization object
* @since 3.0
*/
- public synchronized SynchronizationAlgorithm synchronizeTraces() {
+ public SynchronizationAlgorithm synchronizeTraces() {
return synchronizeTraces(false);
}
* @return The synchronization object
* @since 3.0
*/
- public synchronized SynchronizationAlgorithm synchronizeTraces(boolean doSync) {
+ public SynchronizationAlgorithm synchronizeTraces(boolean doSync) {
+ fSyncLock.lock();
- String syncDirectory = getSynchronizationFolder(true);
+ try {
+ String syncDirectory = getSynchronizationFolder(true);
- final File syncFile = (syncDirectory != null) ? new File(syncDirectory + File.separator + SYNCHRONIZATION_FILE_NAME) : null;
+ final File syncFile = (syncDirectory != null) ? new File(syncDirectory + File.separator + SYNCHRONIZATION_FILE_NAME) : null;
- final SynchronizationAlgorithm syncAlgo = SynchronizationManager.synchronizeTraces(syncFile, Arrays.asList(fTraces), doSync);
+ final SynchronizationAlgorithm syncAlgo = SynchronizationManager.synchronizeTraces(syncFile, Collections.<ITmfTrace> singleton(this), doSync);
- final TmfTraceSynchronizedSignal signal = new TmfTraceSynchronizedSignal(this, syncAlgo);
+ final TmfTraceSynchronizedSignal signal = new TmfTraceSynchronizedSignal(this, syncAlgo);
- /* Broadcast in separate thread to prevent deadlock */
- new Thread() {
- @Override
- public void run() {
- broadcast(signal);
- }
- }.start();
+ /* Broadcast in separate thread to prevent deadlock */
+ new Thread() {
+ @Override
+ public void run() {
+ broadcast(signal);
+ }
+ }.start();
- return syncAlgo;
+ return syncAlgo;
+ } finally {
+ fSyncLock.unlock();
+ }
}
@Override