import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.CtfConstants;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.eclipse.ui.PlatformUI;
/**
import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTimestamp;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.timestamp.CtfTmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
/**
* Consumer of the relay d.
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
import org.junit.Test;
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;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.BeforeClass;
import org.junit.Test;
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.ctf.core.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.BeforeClass;
import org.junit.Test;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.eclipse.tracecompass.tmf.core.synchronization.TimestampTransformFactory;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.BeforeClass;
import org.junit.Test;
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;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.Test;
/**
import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
/**
* Small program to regenerate the values used in "TestValues.java"Â from the
import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.After;
import org.junit.Test;
import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.After;
import org.junit.Test;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.After;
/**
point="org.eclipse.linuxtools.tmf.core.tracetype">
<type
category="org.eclipse.linuxtools.tmf.ctf.core.category.ctf"
- event_type="org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent"
+ event_type="org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent"
id="org.eclipse.linuxtools.lttng2.kernel.tracetype"
isDirectory="true"
name="%tracetype.type.kernel"
import org.eclipse.tracecompass.tmf.core.event.matching.TmfNetworkEventMatching.Direction;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import com.google.common.collect.ImmutableSet;
import org.eclipse.tracecompass.tmf.core.event.matching.TmfNetworkEventMatching.Direction;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import com.google.common.collect.ImmutableSet;
import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
import org.eclipse.tracecompass.internal.lttng2.kernel.core.Activator;
import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
/**
* This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+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.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.SWTBotUtil;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.conditions.ConditionHelpers;
import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
point="org.eclipse.linuxtools.tmf.core.tracetype">
<type
category="org.eclipse.linuxtools.tmf.ctf.core.category.ctf"
- event_type="org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent"
+ event_type="org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent"
id="org.eclipse.linuxtools.lttng2.ust.tracetype"
isDirectory="true"
name="%tracetype.type.ust"
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
/**
* State provider to track the memory of the threads using the UST libc wrapper
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
/**
* Callstack provider for LTTng-UST traces.
import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
import org.eclipse.tracecompass.internal.lttng2.ust.core.Activator;
import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
/**
* Class to contain LTTng-UST traces
import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
org.eclipse.tracecompass.ctf.core,
org.eclipse.tracecompass.ctf.core.tests
Export-Package: org.eclipse.tracecompass.tmf.ctf.core.tests,
- org.eclipse.tracecompass.tmf.ctf.core.tests.headless;x-internal:=true,
org.eclipse.tracecompass.tmf.ctf.core.tests.perf,
org.eclipse.tracecompass.tmf.ctf.core.tests.perf.experiment;x-internal:=true,
- org.eclipse.tracecompass.tmf.ctf.core.tests.request;x-internal:=true,
org.eclipse.tracecompass.tmf.ctf.core.tests.shared,
- org.eclipse.tracecompass.tmf.ctf.core.tests.statistics;x-internal:=true,
org.eclipse.tracecompass.tmf.ctf.core.tests.stubs,
- org.eclipse.tracecompass.tmf.ctf.core.tests.tracemanager;x-internal:=true
+ org.eclipse.tracecompass.tmf.ctf.core.tests.temp.headless;x-internal:=true,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.temp.request;x-internal:=true,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.temp.statistics;x-internal:=true,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.temp.tracemanager;x-internal:=true
Import-Package: com.google.common.collect,
org.eclipse.test.performance
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub;
import org.junit.Test;
point="org.eclipse.linuxtools.tmf.core.tracetype">
<type
category="org.eclipse.linuxtools.tmf.core.tests.category"
- event_type="org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent"
+ event_type="org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent"
id="org.eclipse.linuxtools.tmf.ctf.core.tests.ctf.tracetype"
isDirectory="true"
name="CTF Test Trace"
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
import org.eclipse.tracecompass.tmf.ctf.core.tests.stubs.CtfTmfTraceStub;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
/**
* Available CTF TMF test traces. Kind-of-extends {@link CtfTestTrace}.
import org.junit.runner.RunWith;
/**
- * The class <code>TestAll</code> builds a suite that can be used to run all
- * of the tests within its package as well as within any subpackages of its
+ * The class <code>TestAll</code> builds a suite that can be used to run all of
+ * the tests within its package as well as within any subpackages of its
* package.
*
* @author ematkho
*/
@RunWith(DebugSuite.class)
@DebugSuite.SuiteClasses({
- CtfIteratorTest.class,
- CtfLocationDataTest.class,
- CtfLocationTest.class,
- CtfTmfContextTest.class,
- CtfTmfEventFieldTest.class,
- CtfTmfEventTest.class,
- CtfTmfEventTypeTest.class,
- CtfTmfLostEventsTest.class,
- CtfTmfTimestampTest.class,
- CtfTmfTraceTest.class,
- EventContextTest.class,
- FunkyTraceTest.class,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.context.AllTests.class,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.event.AllTests.class,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.iterator.AllTests.class,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.timestamp.AllTests.class,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.trace.AllTests.class,
- /* Tests in other packages (that are there because of CTF) */
- org.eclipse.tracecompass.tmf.ctf.core.tests.request.AllTests.class,
- org.eclipse.tracecompass.tmf.ctf.core.tests.statistics.AllTests.class,
- org.eclipse.tracecompass.tmf.ctf.core.tests.tracemanager.AllTests.class
+ /* Tests in other packages (that are there because of CTF) */
+ org.eclipse.tracecompass.tmf.ctf.core.tests.temp.request.AllTests.class,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.temp.statistics.AllTests.class,
+ org.eclipse.tracecompass.tmf.ctf.core.tests.temp.tracemanager.AllTests.class
})
public class AllTests {
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial generation with CodePro tools
- * Alexandre Montplaisir - Clean up, consolidate redundant tests
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
-import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfIterator;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfLocation;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfLocationInfo;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>CtfIteratorTest</code> contains tests for the class
- * <code>{@link CtfIterator}</code>.
- *
- * @author ematkho
- * @version 1.0
- */
-public class CtfIteratorTest {
-
- private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
-
- private CtfTmfTrace trace;
- private CtfIterator iterator;
-
- /**
- * Perform pre-test initialization.
- * @throws CTFReaderException error
- */
- @Before
- public void setUp() throws CTFReaderException {
- assumeTrue(testTrace.exists());
- trace = testTrace.getTrace();
- iterator = new CtfIterator(trace);
- CtfLocation ctfLocation = new CtfLocation(new CtfLocationInfo(1, 0));
- iterator.setLocation(ctfLocation);
- iterator.increaseRank();
- }
-
- /**
- * Perform post-test clean-up.
- */
- @After
- public void tearDown() {
- if (trace != null) {
- trace.dispose();
- }
- if (iterator != null) {
- iterator.dispose();
- }
- }
-
- /**
- * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
- * @throws CTFReaderException error
- */
- @Test
- public void testCtfIterator_noinit() throws CTFReaderException {
- try (CtfIterator result = new CtfIterator(trace);) {
- assertNotNull(result);
- }
- }
-
- /**
- * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
- * @throws CTFReaderException error
- */
- @Test
- public void testCtfIterator_init() throws CTFReaderException {
- trace.init("test");
- try (CtfIterator result = new CtfIterator(trace);) {
- assertNotNull(result);
- }
- }
-
- /**
- * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
- * specifies an initial position for the iterator.
- * @throws CTFReaderException error
- */
- @Test
- public void testCtfIterator_position() throws CTFReaderException {
- long timestampValue = 1L;
- long rank = 1L;
- try (CtfIterator result = new CtfIterator(trace, new CtfLocationInfo(timestampValue, 0), rank);) {
- assertNotNull(result);
- }
- }
-
-
- /**
- * Run the boolean advance() method test.
- */
- @Test
- public void testAdvance() {
- boolean result = iterator.advance();
- assertTrue(result);
- }
-
- /**
- * Run the int compareTo(CtfIterator) method test.
- * @throws CTFReaderException error
- */
- @Test
- public void testCompareTo() throws CTFReaderException {
- try (CtfIterator o = new CtfIterator(trace);) {
- int result = iterator.compareTo(o);
- assertEquals(1L, result);
- }
- }
-
- /**
- * Run the boolean equals(Object) method test. Compare with another iterator
- * on the same trace.
- * @throws CTFReaderException error
- */
- @Test
- public void testEquals_other() throws CTFReaderException {
- try (CtfIterator obj = new CtfIterator(trace);) {
- CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
- obj.setLocation(ctfLocation1);
- obj.increaseRank();
-
- boolean result = iterator.equals(obj);
- assertTrue(result);
- }
- }
-
- /**
- * Run the boolean equals(Object) method test. Compare with an empty object.
- */
- @Test
- public void testEquals_empty() {
- Object obj = new Object();
- boolean result = iterator.equals(obj);
-
- assertFalse(result);
- }
-
- /**
- * Run the CtfTmfTrace getCtfTmfTrace() method test.
- */
- @Test
- public void testGetCtfTmfTrace() {
- try (CtfTmfTrace result = iterator.getCtfTmfTrace();) {
- assertNotNull(result);
- }
- }
-
- /**
- * Run the CtfTmfEvent getCurrentEvent() method test.
- */
- @Test
- public void testGetCurrentEvent() {
- CtfTmfEvent result = iterator.getCurrentEvent();
- assertNotNull(result);
- }
-
- /**
- * Run the CtfLocation getLocation() method test.
- */
- @Test
- public void testGetLocation() {
- CtfLocation result = iterator.getLocation();
- assertNotNull(result);
- }
-
- /**
- * Run the long getRank() method test.
- */
- @Test
- public void testGetRank() {
- long result = iterator.getRank();
- assertEquals(1L, result);
- }
-
- /**
- * Run the boolean hasValidRank() method test.
- */
- @Test
- public void testHasValidRank() {
- boolean result = iterator.hasValidRank();
- assertTrue(result);
- }
-
- /**
- * Run the int hashCode() method test.
- */
- @Test
- public void testHashCode() {
- int result = iterator.hashCode();
- int result2 = iterator.hashCode();
- assertEquals(result, result2);
- }
-
- /**
- * Run the void increaseRank() method test.
- */
- @Test
- public void testIncreaseRank() {
- iterator.increaseRank();
- }
-
- /**
- * Run the boolean seek(long) method test.
- */
- @Test
- public void testSeek() {
- long timestamp = 1L;
- boolean result = iterator.seek(timestamp);
- assertTrue(result);
- }
-
- /**
- * Run the void setLocation(ITmfLocation<?>) method test.
- */
- @Test
- public void testSetLocation() {
- CtfLocation location = new CtfLocation(new CtfLocationInfo(1, 0));
- iterator.setLocation(location);
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.eclipse.tracecompass.tmf.ctf.core.CtfLocationInfo;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Collection of tests for the {@link CtfLocationInfo}
- *
- * @author alexmont
- */
-public class CtfLocationDataTest {
-
- private CtfLocationInfo fixture;
-
- /**
- * Perform pre-test initialization.
- */
- @Before
- public void setUp() {
- fixture = new CtfLocationInfo(1, 0);
- }
-
- /**
- * Test for the .getTimestamp() and .getIndex() methods
- */
- @Test
- public void testGetters() {
- long timestamp = fixture.getTimestamp();
- long index = fixture.getIndex();
-
- assertEquals(1, timestamp);
- assertEquals(0, index);
- }
-
- /**
- * Test for the .hashCode() method
- */
- @Test
- public void testHashCode() {
- int code = fixture.hashCode();
- assertEquals(962, code);
- }
-
- /**
- * Test for the .equals() method
- */
- @Test
- public void testEquals() {
- CtfLocationInfo same = new CtfLocationInfo(1, 0);
- CtfLocationInfo diff1 = new CtfLocationInfo(100, 0);
- CtfLocationInfo diff2 = new CtfLocationInfo(1, 10);
-
- assertTrue(fixture.equals(same));
- assertFalse(fixture.equals(diff1));
- assertFalse(fixture.equals(diff2));
- }
-
- /**
- * Test for the .compareTo() method
- */
- @Test
- public void testCompareTo() {
- CtfLocationInfo same = new CtfLocationInfo(1, 0);
- CtfLocationInfo smaller = new CtfLocationInfo(0, 0);
- CtfLocationInfo bigger1 = new CtfLocationInfo(1000, 500);
- CtfLocationInfo bigger2 = new CtfLocationInfo(1, 1);
-
- assertEquals(0, same.compareTo(fixture));
- assertEquals(-1, smaller.compareTo(fixture));
- assertEquals(1, bigger1.compareTo(fixture));
- assertEquals(1, bigger2.compareTo(fixture));
- }
-
- /**
- * Test for the .toString() method
- */
- @Test
- public void testToString() {
- String expected = "Element [1/0]";
- assertEquals(expected, fixture.toString());
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial generation with CodePro tools
- * Alexandre Montplaisir - Clean up, consolidate redundant tests
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfLocation;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfLocationInfo;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>CtfLocationTest</code> contains tests for the class
- * <code>{@link CtfLocation}</code>.
- *
- * @author ematkho
- * @version 1.0
- */
-public class CtfLocationTest {
-
- private CtfLocation fixture;
-
- /**
- * Perform pre-test initialization.
- */
- @Before
- public void setUp() {
- fixture = new CtfLocation(new CtfLocationInfo(1, 0));
- }
-
- /**
- * Run the CtfLocation(Long) constructor test.
- */
- @Test
- public void testCtfLocation_long() {
- CtfLocationInfo location = new CtfLocationInfo(1, 0);
- CtfLocation result = new CtfLocation(location);
-
- assertNotNull(result);
- assertEquals(1L, result.getLocationInfo().getTimestamp());
- }
-
- /**
- * Run the CtfLocation(ITmfTimestamp) constructor test.
- */
- @Test
- public void testCtfLocation_timestamp() {
- ITmfTimestamp timestamp = new TmfTimestamp();
- CtfLocation result = new CtfLocation(timestamp);
-
- assertNotNull(result);
- assertEquals(0L, result.getLocationInfo().getTimestamp());
- }
-
- /**
- * Run the Long getLocation() method test.
- */
- @Test
- public void testGetLocation() {
- CtfLocationInfo location = fixture.getLocationInfo();
- long result = location.getTimestamp();
- assertEquals(1L, result);
- }
-
- /**
- * Run the void setLocation(Long) method test.
- */
- @Test
- public void testSetLocation() {
- CtfLocationInfo location = new CtfLocationInfo(1337, 7331);
- fixture = new CtfLocation(location);
- }
-
- /**
- * Test the toString() method with a valid location.
- */
- @Test
- public void testToString_valid(){
- CtfLocation fixture2 = new CtfLocation(new CtfLocationInfo(1337, 7331));
- assertEquals("CtfLocation [fLocationInfo=Element [1337/7331]]", fixture2.toString());
- }
-
- /**
- * Test the toString() method with an invalid location.
- */
- @Test
- public void testToString_invalid(){
- CtfLocation fixture2 = new CtfLocation(new CtfLocationInfo(-1, -1));
- assertEquals("CtfLocation [INVALID]", fixture2.toString());
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial implementation
- * Alexandre Montplaisir
- * Patrick Tasse - Updated for removal of context clone
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfContext;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Tests for the CtfTmfLightweightContext class
- *
- * @author Matthew Khouzam
- * @version 1.1
- */
-public class CtfTmfContextTest {
-
- private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
- private static final long begin = 1332170682440133097L; /* Trace start time */
- private static final long end = 1332170692664579801L; /* Trace end time */
-
- private CtfTmfTrace trace;
-
- private class SeekerThread extends Thread {
- long val;
-
- public void setVal(long val) {
- this.val = val;
- }
- }
-
- /**
- * Pre-test initialization
- *
- * @throws TmfTraceException
- * If the trace couldn't be init'ed, which shouldn't happen.
- */
- @Before
- public void setUp() throws TmfTraceException {
- assumeTrue(testTrace.exists());
- trace = new CtfTmfTrace();
- String path = testTrace.getPath();
- trace.initTrace((IResource) null, path, CtfTmfEvent.class);
- }
-
- /**
- * Index all the events in the test trace.
- */
- @Test
- public void testIndexing() {
- CtfTmfContext context = new CtfTmfContext(trace);
- context.seek(0);
-
- int count = 0;
- while (trace.getNext(context) != null) {
- count++;
- }
- assertTrue(count > 0);
- }
-
- /**
- * Context fuzzer. Use an amount of contexts greater than the size of the
- * iterator cache and have them access the trace in parallel.
- *
- * @throws InterruptedException
- * Would fail the test
- */
- @Test
- public void testTooManyContexts() throws InterruptedException {
- final int lwcCount = 101;
- double increment = (end - begin) / lwcCount;
- final ArrayList<Long> vals = new ArrayList<>();
- final ArrayList<Thread> threads = new ArrayList<>();
- final ArrayList<CtfTmfContext> tooManyContexts = new ArrayList<>();
-
- for (double i = begin; i < end; i += increment) {
- SeekerThread thread = new SeekerThread() {
- @Override
- public void run() {
- CtfTmfContext lwc = new CtfTmfContext(trace);
- lwc.seek(val);
- trace.getNext(lwc);
- synchronized(trace){
- if (lwc.getCurrentEvent() != null) {
- vals.add(lwc.getCurrentEvent().getTimestamp().getValue());
- }
- tooManyContexts.add(lwc);
- }
- }
- };
- thread.setVal((long)i);
- threads.add(thread);
- thread.start();
- }
-
- for (Thread t: threads){
- t.join();
- }
-
- for (long val : vals){
- assertTrue(val >= begin);
- assertTrue(val <= end);
- }
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial generation with CodePro tools
- * Alexandre Montplaisir - Clean up, consolidate redundant tests
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
-import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.FloatDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.FloatDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.StringDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.VariantDeclaration;
-import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
-import org.eclipse.tracecompass.internal.ctf.core.event.types.ArrayDeclaration;
-import org.eclipse.tracecompass.internal.ctf.core.event.types.SequenceDeclaration;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEventField;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>CtfTmfEventFieldTest</code> contains tests for the class
- * <code>{@link CtfTmfEventField}</code>.
- *
- * @author Matthew Khouzam
- * @version 1.0
- */
-public class CtfTmfEventFieldTest {
-
- private static final @NonNull String ROOT = "root";
- private static final String SEQ = "seq";
- private static final @NonNull String ARRAY_STR = "array_str";
- private static final @NonNull String ARRAY_FLOAT = "array_float";
- private static final @NonNull String ARRAY_INT = "array_int";
- private static final @NonNull String ARRAY_STRUCT = "array_struct";
- private static final @NonNull String ARRAY_VARIANT = "array_variant";
- private static final @NonNull String ARRAY_ENUM = "array_enum";
- private static final String STR = "str";
- private static final String FLOAT = "float";
- private static final String LEN = "len";
- private static final String INT = "int";
- private static final String NAME = "test";
- private static final String STRUCT = "struct";
- private static final String VARIANT = "variant";
- private static final String ENUM = "enum";
-
- private static final byte TEST_NUMBER = 2;
- private static final String TEST_STRING = "two";
-
- private static final int ARRAY_SIZE = 2;
-
- private StructDefinition fixture;
-
- /**
- * Perform pre-test initialization.
- *
- * @throws UnsupportedEncodingException
- * Thrown when UTF-8 encoding is not available.
- * @throws CTFReaderException
- * error
- */
- @Before
- public void setUp() throws UnsupportedEncodingException, CTFReaderException {
- final byte[] testStringBytes = TEST_STRING.getBytes("UTF-8");
-
- int capacity = 2048;
- ByteBuffer bb = ByteBuffer.allocateDirect(capacity);
-
- StructDeclaration sDec = new StructDeclaration(1l);
- StringDeclaration strDec = new StringDeclaration();
- IntegerDeclaration intDec = IntegerDeclaration.UINT_8_DECL;
- FloatDeclaration flDec = new FloatDeclaration(8, 24,
- ByteOrder.BIG_ENDIAN, 8);
- SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec);
- StructDeclaration structDec = new StructDeclaration(8);
- EnumDeclaration enumDec = new EnumDeclaration(intDec);
- VariantDeclaration varDec = new VariantDeclaration();
- ArrayDeclaration arrStrDec = new ArrayDeclaration(ARRAY_SIZE, strDec);
- ArrayDeclaration arrFloatDec = new ArrayDeclaration(ARRAY_SIZE, flDec);
- ArrayDeclaration arrIntDec = new ArrayDeclaration(ARRAY_SIZE, intDec);
- ArrayDeclaration arrStructDec = new ArrayDeclaration(ARRAY_SIZE, structDec);
- ArrayDeclaration arrVariantDec = new ArrayDeclaration(ARRAY_SIZE, varDec);
- ArrayDeclaration arrEnumDec = new ArrayDeclaration(ARRAY_SIZE, enumDec);
-
- sDec.addField(INT, intDec);
- bb.put(TEST_NUMBER);
-
- sDec.addField(ARRAY_INT, arrIntDec);
- for (int i = 0; i < ARRAY_SIZE; ++i) {
- bb.put(TEST_NUMBER);
- }
-
- sDec.addField(LEN, intDec);
- bb.put(TEST_NUMBER);
-
- sDec.addField(FLOAT, flDec);
- bb.putFloat(TEST_NUMBER);
-
- sDec.addField(ARRAY_FLOAT, arrFloatDec);
- for (int i = 0; i < ARRAY_SIZE; ++i) {
- bb.putFloat(TEST_NUMBER);
- }
-
- sDec.addField(STR, strDec);
- bb.put(testStringBytes);
- bb.put((byte) 0);
-
- sDec.addField(ARRAY_STR, arrStrDec);
- for (int i = 0; i < ARRAY_SIZE; ++i) {
- bb.put(testStringBytes);
- bb.put((byte) 0);
- }
-
- sDec.addField(SEQ, seqDec);
- bb.put(TEST_NUMBER);
- bb.put(TEST_NUMBER);
-
- structDec.addField(STR, strDec);
- structDec.addField(INT, intDec);
- sDec.addField(STRUCT, structDec);
- bb.put(testStringBytes);
- bb.put((byte) 0);
- bb.put(TEST_NUMBER);
-
- sDec.addField(ARRAY_STRUCT, arrStructDec);
- for (int i = 0; i < ARRAY_SIZE; ++i) {
- bb.put(testStringBytes);
- bb.put((byte) 0);
- bb.put(TEST_NUMBER);
- }
-
- enumDec.add(0, 1, LEN);
- enumDec.add(2, 3, FLOAT);
- sDec.addField(ENUM, enumDec);
- bb.put(TEST_NUMBER);
-
- sDec.addField(ARRAY_ENUM, arrEnumDec);
- for (int i = 0; i < ARRAY_SIZE; ++i) {
- bb.put(TEST_NUMBER);
- }
-
- varDec.addField(LEN, intDec);
- varDec.addField(FLOAT, flDec);
- varDec.setTag(ENUM);
- sDec.addField(VARIANT, varDec);
- bb.putFloat(TEST_NUMBER);
-
- sDec.addField(ARRAY_VARIANT, arrVariantDec);
- for (int i = 0; i < ARRAY_SIZE; ++i) {
- bb.putFloat(TEST_NUMBER);
- }
-
- fixture = sDec.createDefinition(fixture, ROOT, new BitBuffer(bb));
-
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_float() {
- FloatDefinition fieldDef = (FloatDefinition) fixture.lookupDefinition(FLOAT);
- CtfTmfEventField result = CtfTmfEventField.parseField((IDefinition)fieldDef, "_" + NAME);
- assertEquals("test=2.0", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test for an
- * array of floats field.
- */
- @Test
- public void testParseField_array_float() {
- IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_FLOAT);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[2.0, 2.0]", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_int() {
- IDefinition fieldDef = fixture.lookupDefinition(INT);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=2", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test for an
- * array of integers field.
- */
- @Test
- public void testParseField_array_int() {
- IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_INT);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[2, 2]", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_sequence() {
- IDefinition fieldDef = fixture.lookupDefinition(SEQ);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[2, 2]", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_sequence_value() {
- IDefinition fieldDef = fixture.lookupDefinition(SEQ);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- long[] values = (long[]) result.getValue();
- long[] expected = new long[] { 2, 2 };
- assertArrayEquals(expected, values);
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_string() {
- IDefinition fieldDef = fixture.lookupDefinition(STR);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=two", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test for an
- * array of strings field.
- */
- @Test
- public void testParseField_array_string() {
- IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_STR);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[two, two]", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_struct() {
- IDefinition fieldDef = fixture.lookupDefinition(STRUCT);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[str=two, int=2]", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test for an
- * array of structs field.
- */
- @Test
- public void testParseField_array_struct() {
- IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_STRUCT);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[[str=two, int=2], [str=two, int=2]]", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_enum() {
- IDefinition fieldDef = fixture.lookupDefinition(ENUM);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=float", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test for an
- * array of enums field.
- */
- @Test
- public void testParseField_array_enum() {
- IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_ENUM);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[float, float]", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_variant() {
- IDefinition fieldDef = fixture.lookupDefinition(VARIANT);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=float=2.0", result.toString());
- }
-
- /**
- * Run the CtfTmfEventField parseField(Definition,String) method test for an
- * array of variants field.
- */
- @Test
- public void testParseField_array_variant() {
- IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_VARIANT);
- CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[float=2.0, float=2.0]", result.toString());
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial generation with CodePro tools
- * Alexandre Montplaisir - Clean up, consolidate redundant tests
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assume.assumeTrue;
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfIterator;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEventFactory;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>CtfTmfEventTest</code> contains tests for the class
- * <code>{@link CtfTmfEvent}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-public class CtfTmfEventTest {
-
- private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
-
- private static CtfTmfEvent nullEvent;
- private CtfTmfEvent fixture;
-
- /**
- * Perform pre-test initialization.
- *
- * @throws CTFReaderException
- * error
- */
- @Before
- public void setUp() throws CTFReaderException {
- assumeTrue(testTrace.exists());
- try (CtfTmfTrace trace = testTrace.getTrace();
- CtfIterator tr = new CtfIterator(trace);) {
- tr.advance();
- fixture = tr.getCurrentEvent();
- nullEvent = CtfTmfEventFactory.getNullEvent(trace);
- }
- }
-
- /**
- * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
- */
- @Test
- public void testCTFEvent_read() {
- assertNotNull(fixture);
- }
-
- /**
- * Run the int getCPU() method test.
- */
- @Test
- public void testGetCPU() {
- int result = nullEvent.getCPU();
- assertEquals(-1, result);
- }
-
- /**
- * Run the String getEventName() method test.
- */
- @Test
- public void testGetEventName() {
- String result = nullEvent.getType().getName();
- assertEquals("Empty CTF event", result);
- }
-
- /**
- * Run the ArrayList<String> getFieldNames() method test.
- */
- @Test
- public void testGetFieldNames() {
- Collection<String> result = fixture.getContent().getFieldNames();
- assertNotNull(result);
- }
-
- /**
- * Run the Object getFieldValue(String) method test.
- */
- @Test
- public void testGetFieldValue() {
- String fieldName = "pid";
- ITmfEventField result = fixture.getContent().getField(fieldName);
-
- assertNotNull(result);
- assertNotNull(result.getValue());
- }
-
- /**
- * Run the HashMap<String, CTFEventField> getFields() method test.
- */
- @Test
- public void testGetFields() {
- Collection<? extends ITmfEventField> fields = nullEvent.getContent().getFields();
- assertEquals(0, fields.size());
- }
-
- /**
- * Run the ITmfEventField getSubFieldValue(String[]) method test.
- */
- @Test
- public void testGetSubFieldValue() {
- /* Field exists */
- String[] names = { "pid" };
- assertNotNull(fixture.getContent().getSubField(names));
-
- /* First field exists, not the second */
- String[] names2 = { "pid", "abcd" };
- assertNull(fixture.getContent().getSubField(names2));
-
- /* Both field do not exist */
- String[] names3 = { "pfid", "abcd" };
- assertNull(fixture.getContent().getSubField(names3));
-
- /* TODO Missing case of embedded field, need event for it */
- }
-
- /**
- * Run the long getID() method test.
- */
- @Test
- public void testGetID() {
- long result = nullEvent.getID();
- assertEquals(-1L, result);
- }
-
- /**
- * Run the long getTimestamp() method test.
- */
- @Test
- public void testGetTimestamp() {
- long result = nullEvent.getTimestamp().getValue();
- assertEquals(-1L, result);
- }
-
- /**
- * Test the getters for the reference, source and type.
- */
- @Test
- public void testGetters() {
- long rank = fixture.getRank();
- try (CtfTmfTrace trace = fixture.getTrace();) {
- assertEquals("kernel", trace.getName());
- }
- String reference = fixture.getReference();
- String source = fixture.getSource();
- ITmfEventType type = fixture.getType();
- assertEquals(ITmfContext.UNKNOWN_RANK, rank);
-
- assertEquals("channel0_1", reference);
- assertEquals("1", source);
- assertEquals("lttng_statedump_vm_map", type.toString());
- }
-
- /**
- * Test the custom CTF attributes methods. The test trace doesn't have any,
- * so the list of attributes should be empty.
- */
- @Test
- public void testCustomAttributes() {
- Set<String> attributes = fixture.listCustomAttributes();
- assertEquals(0, attributes.size());
-
- String attrib = fixture.getCustomAttribute("bozo");
- assertNull(attrib);
- }
-
- /**
- * Test the toString() method
- */
- @Test
- public void testToString() {
- String s = fixture.getContent().toString();
- assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s);
- }
-
- /**
- * Test the {@link CtfTmfEventFactory#getNullEvent(CtfTmfTrace)} method, and
- * the nullEvent's values.
- */
- @Test
- public void testNullEvent() {
- CtfTmfEvent nullEvent2 = CtfTmfEventFactory.getNullEvent(fixture.getTrace());
- assertSame(nullEvent2, nullEvent);
- assertNotNull(nullEvent);
- assertEquals(-1, nullEvent.getCPU());
- assertEquals("Empty CTF event", nullEvent.getType().getName());
- assertNull(nullEvent.getReference());
- assertEquals(0, nullEvent.getContent().getFields().size());
- assertEquals(-1L, nullEvent.getID());
- assertEquals(-1L, nullEvent.getTimestamp().getValue());
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial generation with CodePro tools
- * Alexandre Montplaisir - Clean up, consolidate redundant tests
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEventType;
-import org.junit.Test;
-
-/**
- * The class <code>CtfTmfEventTypeTest</code> contains tests for the class
- * <code>{@link CtfTmfEventType}</code>.
- *
- * @author ematkho
- * @version 1.0
- */
-public class CtfTmfEventTypeTest {
-
- /**
- * Run the CtfTmfEventType(String,String,ITmfEventField) constructor test.
- */
- @Test
- public void testCtfTmfEventType() {
- String eventName = "";
- ITmfEventField content = new TmfEventField("", null, new ITmfEventField[] {});
- CtfTmfEventType result = new CtfTmfEventType(eventName, content);
-
- assertNotNull(result);
- assertEquals("", result.toString());
- assertEquals("", result.getName());
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToString() {
- ITmfEventField emptyField = new TmfEventField("", null, new ITmfEventField[] {});
- CtfTmfEventType fixture = new CtfTmfEventType("" , emptyField);
-
- String result = fixture.toString();
-
- assertEquals("", result);
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
-
-import java.util.Map;
-
-import org.eclipse.tracecompass.ctf.core.CTFStrings;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
-import org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics;
-import org.eclipse.tracecompass.tmf.core.statistics.TmfStateStatistics;
-import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsEventTypesModule;
-import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsTotalsModule;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestRule;
-import org.junit.rules.Timeout;
-
-/**
- * Unit tests for handling of lost events by the statistics backends.
- *
- * @author Alexandre Montplaisir
- */
-public class CtfTmfLostEventStatisticsTest {
-
- /** Time-out tests after 30 seconds */
- @Rule
- public TestRule globalTimeout= new Timeout(30000);
-
- /**Test trace with lost events */
- private static final CtfTmfTestTrace lostEventsTrace = CtfTmfTestTrace.HELLO_LOST;
-
- private ITmfTrace fTrace;
-
- /** The statistics back-end object for the trace with lost events */
- private ITmfStatistics fStats;
-
- /* The two analysis modules needed for fStats */
- private TmfStatisticsTotalsModule fTotalsMod;
- private TmfStatisticsEventTypesModule fEventTypesMod;
-
- // ------------------------------------------------------------------------
- // Maintenance
- // ------------------------------------------------------------------------
-
- /**
- * Class setup
- */
- @BeforeClass
- public static void setUpClass() {
- assumeTrue(lostEventsTrace.exists());
- }
-
- /**
- * Test setup
- */
- @Before
- public void setUp() {
- fTrace = lostEventsTrace.getTrace();
-
- /* Prepare the two analysis-backed state systems */
- fTotalsMod = new TmfStatisticsTotalsModule();
- fEventTypesMod = new TmfStatisticsEventTypesModule();
- try {
- fTotalsMod.setTrace(fTrace);
- fEventTypesMod.setTrace(fTrace);
- } catch (TmfAnalysisException e) {
- fail();
- }
-
- fTotalsMod.schedule();
- fEventTypesMod.schedule();
- assertTrue(fTotalsMod.waitForCompletion());
- assertTrue(fEventTypesMod.waitForCompletion());
-
- ITmfStateSystem totalsSS = fTotalsMod.getStateSystem();
- ITmfStateSystem eventTypesSS = fEventTypesMod.getStateSystem();
- assertNotNull(totalsSS);
- assertNotNull(eventTypesSS);
-
- fStats = new TmfStateStatistics(totalsSS, eventTypesSS);
- }
-
- /**
- * Test cleanup
- */
- @After
- public void tearDown() {
- fStats.dispose();
- fTotalsMod.dispose();
- fEventTypesMod.dispose();
- fTrace.dispose();
- }
-
- // ------------------------------------------------------------------------
- // Test methods
- // ------------------------------------------------------------------------
-
- /*
- * Trace start = 1376592664828559410
- * Trace end = 1376592665108210547
- */
-
- private static final long rangeStart = 1376592664900000000L;
- private static final long rangeEnd = 1376592665000000000L;
-
- /**
- * Test the total number of "real" events. Make sure the lost events aren't
- * counted in the total.
- */
- @Test
- public void testLostEventsTotals() {
- long realEvents = fStats.getEventsTotal();
- assertEquals(32300, realEvents);
- }
-
- /**
- * Test the number of real events in a given range. Lost events shouldn't be
- * counted.
- */
- @Test
- public void testLostEventsTotalInRange() {
- long realEventsInRange = fStats.getEventsInRange(rangeStart, rangeEnd);
- assertEquals(11209L, realEventsInRange);
- }
-
- /**
- * Test the total number of lost events reported in the trace.
- */
- @Test
- public void testLostEventsTypes() {
- Map<String, Long> events = fStats.getEventTypesTotal();
- Long lostEvents = events.get(CTFStrings.LOST_EVENT_NAME);
- assertEquals(Long.valueOf(967700L), lostEvents);
- }
-
- /**
- * Test the number of lost events reported in a given range.
- */
- @Test
- public void testLostEventsTypesInRange() {
- Map<String, Long> eventsInRange = fStats.getEventTypesInRange(rangeStart, rangeEnd);
- long lostEventsInRange = eventsInRange.get(CTFStrings.LOST_EVENT_NAME);
- assertEquals(363494L, lostEventsInRange);
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent;
-import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTimestamp;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Tests to verify that lost events are handled correctly.
- *
- * Be wary if you are using Babeltrace to cross-check those values. There could
- * be a bug in Babeltrace with regards to lost events. See
- * http://bugs.lttng.org/issues/589
- *
- * It's not 100% sure at this point which implementation is correct, so for now
- * these tests assume the Java implementation is the right one.
- *
- * @author Alexandre Montplaisir
- */
-public class CtfTmfLostEventsTest {
-
- private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.HELLO_LOST;
-
- private CtfTmfTrace fixture = null;
-
- /**
- * Class setup
- */
- @Before
- public void setUp() {
- assumeTrue(testTrace.exists());
- fixture = testTrace.getTrace();
- fixture.indexTrace(true);
- }
-
- /**
- * Clean-up
- */
- @After
- public void tearDown() {
- if (fixture != null) {
- fixture.dispose();
- }
- }
-
- // ------------------------------------------------------------------------
- // Test methods
- // ------------------------------------------------------------------------
-
- /**
- * Test that the number of events is reported correctly (a range of lost
- * events is counted as one event).
- */
- @Test
- public void testNbEvents() {
- final long expectedReal = 32300;
- final long expectedLost = 562;
-
- EventCountRequest req = new EventCountRequest();
- fixture.sendRequest(req);
- try {
- req.waitForCompletion();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- assertEquals(expectedReal, req.getReal());
- assertEquals(expectedLost, req.getLost());
- }
-
- /**
- * Test getting the first lost event from the trace.
- */
- @Test
- public void testFirstLostEvent() {
- final long rank = 153;
- final ITmfTimestamp start = new CtfTmfTimestamp(1376592664828848222L);
- final ITmfTimestamp end = new CtfTmfTimestamp(1376592664828848540L);
- final long nbLost = 859;
-
- final CtfTmfEvent ev = getOneEventTime(start);
- /* Make sure seeking by rank yields the same event */
- final CtfTmfEvent ev2 = getOneEventRank(rank);
- assertEquals(ev, ev2);
-
- assertTrue(ev instanceof ITmfLostEvent);
- ITmfLostEvent event = (ITmfLostEvent) ev;
-
- assertEquals(start, event.getTimestamp());
- assertEquals(start, event.getTimeRange().getStartTime());
- assertEquals(end, event.getTimeRange().getEndTime());
- assertEquals(nbLost, event.getNbLostEvents());
- }
-
- /**
- * Test getting the second lost event from the trace.
- */
- @Test
- public void testSecondLostEvent() {
- final long rank = 191;
- final ITmfTimestamp start = new CtfTmfTimestamp(1376592664829402521L);
- final ITmfTimestamp end = new CtfTmfTimestamp(1376592664829403076L);
- final long nbLost = 488;
-
- final CtfTmfEvent ev = getOneEventTime(start);
- /* Make sure seeking by rank yields the same event */
- final CtfTmfEvent ev2 = getOneEventRank(rank);
- assertEquals(ev, ev2);
-
- assertTrue(ev instanceof ITmfLostEvent);
- ITmfLostEvent event = (ITmfLostEvent) ev;
-
- assertEquals(start, event.getTimestamp());
- assertEquals(start, event.getTimeRange().getStartTime());
- assertEquals(end, event.getTimeRange().getEndTime());
- assertEquals(nbLost, event.getNbLostEvents());
- }
-
- /**
- * Test getting one normal event from the trace (lost events should not
- * interfere).
- */
- @Test
- public void testNormalEvent() {
- final long rank = 200;
- final ITmfTimestamp ts = new CtfTmfTimestamp(1376592664829423928L);
-
- final CtfTmfEvent event = getOneEventTime(ts);
- /* Make sure seeking by rank yields the same event */
- final CtfTmfEvent event2 = getOneEventRank(rank);
- assertEquals(event, event2);
-
- assertFalse(event instanceof ITmfLostEvent);
- assertEquals(ts, event.getTimestamp());
- }
-
- // ------------------------------------------------------------------------
- // Event requests
- // ------------------------------------------------------------------------
-
- private CtfTmfEvent getOneEventRank(long rank) {
- OneEventRequestPerRank req = new OneEventRequestPerRank(rank);
- fixture.sendRequest(req);
- try {
- req.waitForCompletion();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return req.getEvent();
- }
-
- private CtfTmfEvent getOneEventTime(ITmfTimestamp ts) {
- OneEventRequestPerTs req = new OneEventRequestPerTs(ts);
- fixture.sendRequest(req);
- try {
- req.waitForCompletion();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return req.getEvent();
- }
-
- private class OneEventRequestPerRank extends TmfEventRequest {
-
- private CtfTmfEvent event = null;
-
- public OneEventRequestPerRank(long rank) {
- super(CtfTmfEvent.class, TmfTimeRange.ETERNITY, rank, 1, ExecutionType.FOREGROUND);
- }
-
- @Override
- public void handleData(ITmfEvent ev) {
- /* Type is checked by the request, cast should be safe */
- event = (CtfTmfEvent) ev;
- }
-
- public CtfTmfEvent getEvent() {
- return event;
- }
- }
-
- private class OneEventRequestPerTs extends TmfEventRequest {
-
- private CtfTmfEvent event = null;
-
- public OneEventRequestPerTs(ITmfTimestamp ts) {
- super(CtfTmfEvent.class,
- new TmfTimeRange(ts, TmfTimestamp.PROJECT_IS_CANNED),
- 0, 1, ExecutionType.FOREGROUND);
- }
-
- @Override
- public void handleData(ITmfEvent ev) {
- event = (CtfTmfEvent) ev;
- }
-
- public CtfTmfEvent getEvent() {
- return event;
- }
- }
-
- private class EventCountRequest extends TmfEventRequest {
-
- private long nbReal = 0;
- private long nbLost = 0;
-
- public EventCountRequest() {
- super(CtfTmfEvent.class, TmfTimeRange.ETERNITY, 0,
- ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND);
- }
-
- @Override
- public void handleData(ITmfEvent event) {
- if (event instanceof ITmfLostEvent) {
- nbLost++;
- } else {
- nbReal++;
- }
- }
-
- public long getReal() {
- return nbReal;
- }
-
- public long getLost() {
- return nbLost;
- }
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial generation with CodePro tools
- * Alexandre Montplaisir - Clean up, consolidate redundant tests
- * Patrick Tasse - Fix for local time zone
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTimestamp;
-import org.junit.Test;
-
-/**
- * The class <code>CtfTmfTimestampTest</code> contains tests for the class
- * <code>{@link CtfTmfTimestamp}</code>.
- *
- * @author ematkho
- * @version 1.0
- */
-public class CtfTmfTimestampTest {
-
- /**
- * Run the CtfTmfTimestamp(long) constructor test.
- */
- @Test
- public void testCtfTmfTimestamp() {
- long timestamp = 1L;
- DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS");
- Date d = new Date(timestamp / 1000000);
-
- CtfTmfTimestamp result = new CtfTmfTimestamp(timestamp);
-
- assertNotNull(result);
- assertEquals(df.format(d) + " 000 001", result.toString());
- assertEquals(-9, result.getScale());
- assertEquals(1L, result.getValue());
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial generation with CodePro tools
- * Alexandre Montplaisir - Clean up, consolidate redundant tests
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal;
-import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfLocation;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfLocationInfo;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTimestamp;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>CtfTmfTraceTest</code> contains tests for the class
- * <code>{@link CtfTmfTrace}</code>.
- *
- * @author ematkho
- * @version 1.0
- */
-public class CtfTmfTraceTest {
-
- private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
-
- private CtfTmfTrace fixture;
-
- /**
- * Perform pre-test initialization.
- *
- * @throws TmfTraceException
- * If the test trace is not found
- */
- @Before
- public void setUp() throws TmfTraceException {
- assumeTrue(testTrace.exists());
- fixture = new CtfTmfTrace();
- fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
- }
-
- /**
- * Perform post-test clean-up.
- */
- @After
- public void tearDown() {
- if (fixture != null) {
- fixture.dispose();
- }
- }
-
- /**
- * Run the CtfTmfTrace() constructor test.
- */
- @Test
- public void testCtfTmfTrace() {
- try (CtfTmfTrace result = new CtfTmfTrace();) {
- assertNotNull(result);
- assertEquals(1000, result.getCacheSize());
- assertEquals(0L, result.getNbEvents());
- assertEquals(0L, result.getStreamingInterval());
- assertNull(result.getResource());
- assertNull(result.getType());
- }
- }
-
- /**
- * Test the parseEvent() method
- */
- @Test
- public void testParseEvent() {
- ITmfContext ctx = fixture.seekEvent(0);
- fixture.getNext(ctx);
- CtfTmfEvent event = fixture.parseEvent(ctx);
- assertNotNull(event);
- }
-
- /**
- * Run the void broadcast(TmfSignal) method test.
- */
- @Test
- public void testBroadcast() {
- TmfSignal signal = new TmfEndSynchSignal(1);
- fixture.broadcast(signal);
- }
-
- /**
- * Run the void dispose() method test.
- */
- @Test
- public void testClose() {
- try (CtfTmfTrace emptyFixture = new CtfTmfTrace();) {
- }
- }
-
- /**
- * Run the int getCacheSize() method test.
- */
- @Test
- public void testGetCacheSize() {
- try (CtfTmfTrace emptyFixture = new CtfTmfTrace();) {
- int result = emptyFixture.getCacheSize();
- assertEquals(1000, result);
- }
- }
-
- /**
- * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
- */
- @Test
- public void testGetCurrentLocation() {
- CtfLocation result = (CtfLocation) fixture.getCurrentLocation();
- assertNull(result);
- }
-
- /**
- * Test the seekEvent() method with a null location.
- */
- @Test
- public void testSeekEventLoc_null() {
- CtfLocation loc = null;
- fixture.seekEvent(loc);
- assertNotNull(fixture);
- }
-
- /**
- * Test the seekEvent() method with a location from a timestamp.
- */
- @Test
- public void testSeekEventLoc_timetamp() {
- CtfLocation loc = new CtfLocation(new CtfTmfTimestamp(0L));
- fixture.seekEvent(loc);
- assertNotNull(fixture);
- }
-
- /**
- * Run the ITmfTimestamp getEndTime() method test.
- */
- @Test
- public void testGetEndTime() {
- ITmfTimestamp result = fixture.getEndTime();
- assertNotNull(result);
- }
-
- /**
- * Run the String getEnvironment method test.
- */
- @Test
- public void testGetEnvValue() {
- String key = "tracer_name";
- String result = fixture.getTraceProperties().get(key);
- assertEquals("\"lttng-modules\"", result);
- }
-
- /**
- * Test the {@link CtfTmfTrace#getEventType()} method.
- */
- @Test
- public void testGetEventType() {
- Class<?> result = fixture.getEventType();
- assertNotNull(result);
- assertEquals(CtfTmfEvent.class, result);
- }
-
- /**
- * Run the Class<CtfTmfEvent> getContainedEventTypes() method test.
- */
- @Test
- public void testGetContainedEventTypes() {
- Set<? extends ITmfEventType> result = fixture.getContainedEventTypes();
- assertNotNull(result);
- assertFalse(result.isEmpty());
- }
-
- /**
- * Run the double getLocationRatio(ITmfLocation<?>) method test.
- */
- @Test
- public void testGetLocationRatio() {
- final CtfLocationInfo location2 = new CtfLocationInfo(1, 0);
- CtfLocation location = new CtfLocation(location2);
- double result = fixture.getLocationRatio(location);
-
- assertEquals(Double.NEGATIVE_INFINITY, result, 0.1);
- }
-
- /**
- * Run the String getName() method test.
- */
- @Test
- public void testGetName() {
- String result = fixture.getName();
- assertNotNull(result);
- }
-
- /**
- * Run the getTraceProperties() method test.
- */
- @Test
- public void testGetTraceProperties() {
- int result = fixture.getTraceProperties().size();
- assertEquals(9, result);
- }
-
- /**
- * Run the long getNbEvents() method test.
- */
- @Test
- public void testGetNbEvents() {
- long result = fixture.getNbEvents();
- assertEquals(1L, result);
- }
-
- /**
- * Run the CtfTmfEvent getNext(ITmfContext) method test.
- */
- @Test
- public void testGetNext() {
- ITmfContext context = fixture.seekEvent(0);
- CtfTmfEvent result = fixture.getNext(context);
- assertNotNull(result);
- }
-
- /**
- * Run the String getPath() method test.
- */
- @Test
- public void testGetPath() {
- String result = fixture.getPath();
- assertNotNull(result);
- }
-
- /**
- * Run the IResource getResource() method test.
- */
- @Test
- public void testGetResource() {
- IResource result = fixture.getResource();
- assertNull(result);
- }
-
- /**
- * Run the ITmfTimestamp getStartTime() method test.
- */
- @Test
- public void testGetStartTime() {
- ITmfTimestamp result = fixture.getStartTime();
- assertNotNull(result);
- }
-
- /**
- * Run the long getStreamingInterval() method test.
- */
- @Test
- public void testGetStreamingInterval() {
- long result = fixture.getStreamingInterval();
- assertEquals(0L, result);
- }
-
- /**
- * Run the TmfTimeRange getTimeRange() method test.
- */
- @Test
- public void testGetTimeRange() {
- TmfTimeRange result = fixture.getTimeRange();
- assertNotNull(result);
- }
-
- /**
- * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
- */
- @Test
- public void testReadNextEvent() {
- ITmfContext context = fixture.seekEvent(0);
- CtfTmfEvent result = fixture.getNext(context);
- assertNotNull(result);
- }
-
- /**
- * Run the ITmfContext seekEvent(double) method test.
- */
- @Test
- public void testSeekEvent_ratio() {
- double ratio = 0.99;
- ITmfContext result = fixture.seekEvent(ratio);
- assertNotNull(result);
- }
-
- /**
- * Run the ITmfContext seekEvent(long) method test.
- */
- @Test
- public void testSeekEvent_rank() {
- long rank = 1L;
- ITmfContext result = fixture.seekEvent(rank);
- assertNotNull(result);
- }
-
- /**
- * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
- */
- @Test
- public void testSeekEvent_timestamp() {
- ITmfTimestamp timestamp = new TmfTimestamp();
- ITmfContext result = fixture.seekEvent(timestamp);
- assertNotNull(result);
- }
-
- /**
- * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
- */
- @Test
- public void testSeekEvent_location() {
- final CtfLocationInfo location2 = new CtfLocationInfo(1L, 0L);
- CtfLocation ctfLocation = new CtfLocation(location2);
- ITmfContext result = fixture.seekEvent(ctfLocation);
- assertNotNull(result);
- }
-
- /**
- * Run the boolean validate(IProject,String) method test.
- */
- @Test
- public void testValidate() {
- IProject project = null;
- IStatus result = fixture.validate(project, testTrace.getPath());
- assertTrue(result.isOK());
- }
-
- /**
- * Run the boolean hasEvent(final String) method test
- */
- @Test
- public void testEventLookup() {
- Set<? extends ITmfEventType> eventTypes = fixture.getContainedEventTypes();
- Set<String> eventNames = TmfEventTypeCollectionHelper.getEventNames(eventTypes);
- assertTrue(eventNames.contains("sched_switch"));
- assertFalse(eventNames.contains("Sched_switch"));
- String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
- assertTrue(eventNames.containsAll(Arrays.asList(events)));
- Set<String> copy = new HashSet<>(eventNames);
- copy.retainAll(Arrays.asList(events));
- assertFalse(copy.isEmpty());
- String[] names = { "inexistent", "sched_switch", "SomeThing" };
- copy = new HashSet<>(eventNames);
- copy.retainAll(Arrays.asList(names));
- assertTrue(!copy.isEmpty());
- assertFalse(eventNames.containsAll(Arrays.asList(names)));
- }
-
- /**
- * Run the String getHostId() method test
- */
- @Test
- public void testCtfHostId() {
- String a = fixture.getHostId();
- assertEquals("\"84db105b-b3f4-4821-b662-efc51455106a\"", a);
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assume.assumeTrue;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTimestamp;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Tests for reading event contexts from a CtfTmfTrace.
- *
- * @author Alexandre Montplaisir
- */
-public class EventContextTest {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- /* We use test trace #2, kernel_vm, which has event contexts */
- private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL_VM;
-
- private CtfTmfTrace fixture;
- private long startTime;
- private long endTime;
-
- // ------------------------------------------------------------------------
- // Class methods
- // ------------------------------------------------------------------------
-
- /**
- * Perform pre-class initialization.
- *
- * @throws TmfTraceException
- * If the test trace is not found
- */
- @Before
- public void setUp() throws TmfTraceException {
- assumeTrue(testTrace.exists());
- fixture = new CtfTmfTrace();
- fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
- fixture.indexTrace(true);
-
- startTime = fixture.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
- endTime = fixture.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
- }
-
- /**
- * Perform post-class clean-up.
- */
- @After
- public void tearDown() {
- if (fixture != null) {
- fixture.dispose();
- }
- }
-
- // ------------------------------------------------------------------------
- // Test methods
- // ------------------------------------------------------------------------
-
- /**
- * Make sure the trace is the correct one, and its timestamps are read
- * correctly.
- */
- @Test
- public void testTrace() {
- assertEquals(1363700740555978750L, startTime);
- assertEquals(1363700770550261288L, endTime);
- }
-
- /**
- * Test the context of the very first event of the trace.
- */
- @Test
- public void testContextStart() {
- CtfTmfEvent firstEvent = getEventAt(startTime);
- long perfPageFault = (Long) firstEvent.getContent().getField("context._perf_page_fault").getValue();
- String procname = (String) firstEvent.getContent().getField("context._procname").getValue();
- long tid = (Long) firstEvent.getContent().getField("context._tid").getValue();
-
- assertEquals(613, perfPageFault);
- assertEquals("lttng-sessiond", procname);
- assertEquals(1230, tid);
- }
-
- /**
- * Test the context of the event at 1363700745.559739078.
- */
- @Test
- public void testContext1() {
- long time = startTime + 5000000000L; // 1363700745.559739078
- CtfTmfEvent event = getEventAt(time);
- long perfPageFault = (Long) event.getContent().getField("context._perf_page_fault").getValue();
- String procname = (String) event.getContent().getField("context._procname").getValue();
- long tid = (Long) event.getContent().getField("context._tid").getValue();
-
- assertEquals(6048, perfPageFault);
- assertEquals("swapper/0", procname);
- assertEquals(0, tid);
- }
-
- /**
- * Test the context of the event at 1363700750.559707062.
- */
- @Test
- public void testContext2() {
- long time = startTime + 2 * 5000000000L; // 1363700750.559707062
- CtfTmfEvent event = getEventAt(time);
- long perfPageFault = (Long) event.getContent().getField("context._perf_page_fault").getValue();
- String procname = (String) event.getContent().getField("context._procname").getValue();
- long tid = (Long) event.getContent().getField("context._tid").getValue();
-
- assertEquals(13258, perfPageFault);
- assertEquals("swapper/0", procname);
- assertEquals(0, tid);
- }
-
- /**
- * Test the context of the event at 1363700755.555723128, which is roughly
- * mid-way through the trace.
- */
- @Test
- public void testContextMiddle() {
- long midTime = startTime + (endTime - startTime) / 2L; // 1363700755.555723128
- CtfTmfEvent midEvent = getEventAt(midTime);
- long perfPageFault = (Long) midEvent.getContent().getField("context._perf_page_fault").getValue();
- String procname = (String) midEvent.getContent().getField("context._procname").getValue();
- long tid = (Long) midEvent.getContent().getField("context._tid").getValue();
-
- assertEquals(19438, perfPageFault);
- assertEquals("swapper/0", procname);
- assertEquals(0, tid);
- }
-
- /**
- * Test the context of the event at 1363700760.559719724.
- */
- @Test
- public void testContext3() {
- long time = startTime + 4 * 5000000000L; // 1363700760.559719724
- CtfTmfEvent event = getEventAt(time);
- long perfPageFault = (Long) event.getContent().getField("context._perf_page_fault").getValue();
- String procname = (String) event.getContent().getField("context._procname").getValue();
- long tid = (Long) event.getContent().getField("context._tid").getValue();
-
- assertEquals(21507, perfPageFault);
- assertEquals("swapper/0", procname);
- assertEquals(0, tid);
- }
-
- /**
- * Test the context of the event at 1363700765.559714634.
- */
- @Test
- public void testContext4() {
- long time = startTime + 5 * 5000000000L; // 1363700765.559714634
- CtfTmfEvent event = getEventAt(time);
- long perfPageFault = (Long) event.getContent().getField("context._perf_page_fault").getValue();
- String procname = (String) event.getContent().getField("context._procname").getValue();
- long tid = (Long) event.getContent().getField("context._tid").getValue();
-
- assertEquals(21507, perfPageFault);
- assertEquals("swapper/0", procname);
- assertEquals(0, tid);
- }
-
- /**
- * Test the context of the last event of the trace.
- */
- @Test
- public void testContextEnd() {
- CtfTmfEvent lastEvent = getEventAt(endTime);
- long perfPageFault = (Long) lastEvent.getContent().getField("context._perf_page_fault").getValue();
- String procname = (String) lastEvent.getContent().getField("context._procname").getValue();
- long tid = (Long) lastEvent.getContent().getField("context._tid").getValue();
-
- assertEquals(22117, perfPageFault);
- assertEquals("lttng-sessiond", procname);
- assertEquals(1230, tid);
- }
-
- // ------------------------------------------------------------------------
- // Private stuff
- // ------------------------------------------------------------------------
-
- private synchronized CtfTmfEvent getEventAt(long timestamp) {
- EventContextTestRequest req = new EventContextTestRequest(timestamp);
- fixture.sendRequest(req);
- try {
- req.waitForCompletion();
- } catch (InterruptedException e) {
- return null;
- }
- return req.getEvent();
- }
-
- private class EventContextTestRequest extends TmfEventRequest {
-
- private CtfTmfEvent retEvent = null;
-
- public EventContextTestRequest(long timestamp) {
- super(CtfTmfEvent.class,
- new TmfTimeRange(new CtfTmfTimestamp(timestamp), TmfTimestamp.BIG_CRUNCH),
- 0, 1, ExecutionType.FOREGROUND);
- }
-
- @Override
- public void handleData(ITmfEvent event) {
- retEvent = (CtfTmfEvent) event;
- }
-
- public CtfTmfEvent getEvent() {
- return retEvent;
- }
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assume.assumeTrue;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfEnumPair;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestRule;
-import org.junit.rules.Timeout;
-
-/**
- * More advanced CTF tests using "funky_trace", a trace generated with the
- * Babeltrace CTF writer API, which has lots of fun things like different
- * integer/float sizes and non-standard struct alignments.
- *
- * @author Alexandre Montplaisir
- */
-public class FunkyTraceTest {
-
- /** Time-out tests after 20 seconds */
- @Rule
- public TestRule globalTimeout= new Timeout(20000);
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.FUNKY_TRACE;
- private static final double DELTA = 0.0000001;
-
- private CtfTmfTrace fTrace;
-
- // ------------------------------------------------------------------------
- // Setup
- // ------------------------------------------------------------------------
-
- /**
- * Test setup
- */
- @Before
- public void setup() {
- assumeTrue(testTrace.exists());
- fTrace = testTrace.getTrace();
- fTrace.indexTrace(true);
- }
-
- /**
- * Clean-up
- */
- @After
- public void tearDown() {
- if (fTrace != null) {
- fTrace.dispose();
- }
- }
-
- // ------------------------------------------------------------------------
- // Test methods
- // ------------------------------------------------------------------------
-
- /**
- * Verify the contents of the first event
- */
- @Test
- public void testFirstEvent() {
- CtfTmfEvent event = getEvent(0);
- assertEquals("Simple Event", event.getType().getName());
- assertEquals(1234567, event.getTimestamp().getValue());
- assertEquals(42, ((Long) event.getContent().getField("integer_field").getValue()).intValue());
- assertEquals(3.1415, ((Double) event.getContent().getField("float_field").getValue()).doubleValue(), DELTA);
- }
-
- /**
- * Verify the contents of the second event (the first "spammy event")
- */
- @Test
- public void testSecondEvent() {
- CtfTmfEvent event = getEvent(1);
- assertEquals("Spammy_Event", event.getType().getName());
- assertEquals(1234568, event.getTimestamp().getValue());
- assertEquals(0, ((Long) event.getContent().getField("field_1").getValue()).intValue());
- assertEquals("This is a test", event.getContent().getField("a_string").getValue());
- }
-
- /**
- * Verify the contents of the last "spammy event"
- */
- @Test
- public void testSecondToLastEvent() {
- CtfTmfEvent event = getEvent(100000);
- assertEquals("Spammy_Event", event.getType().getName());
- assertEquals(1334567, event.getTimestamp().getValue());
- assertEquals(99999, ((Long) event.getContent().getField("field_1").getValue()).intValue());
- assertEquals("This is a test", event.getContent().getField("a_string").getValue());
- }
-
- /**
- * Verify the contents of the last, complex event
- */
- @Test
- public void testLastEvent() {
- /*
- * Last event as seen in Babeltrace:
- * [19:00:00.001334568] (+0.000000001) Complex Test Event: { }, {
- * uint_35 = 0xDDF00D,
- * int_16 = -12345,
- * complex_structure = {
- * variant_selector = ( INT16_TYPE : container = 1 ),
- * a_string = "Test string",
- * variant_value = { INT16_TYPE = -200 },
- * inner_structure = {
- * seq_len = 0xA,
- * a_sequence = [ [0] = 4, [1] = 3, [2] = 2, [3] = 1, [4] = 0, [5] = -1, [6] = -2, [7] = -3, [8] = -4, [9] = -5 ]
- * }
- * }
- * }
- */
-
- CtfTmfEvent event = getEvent(100001);
- assertEquals("Complex Test Event", event.getType().getName());
- assertEquals(1334568, event.getTimestamp().getValue());
- assertEquals(0xddf00d, ((Long) event.getContent().getField("uint_35").getValue()).intValue());
- assertEquals(-12345, ((Long) event.getContent().getField("int_16").getValue()).intValue());
-
- ITmfEventField[] complexStruct =
- (ITmfEventField[]) event.getContent().getField("complex_structure").getValue();
-
- assertEquals("variant_selector", complexStruct[0].getName());
- CtfEnumPair variant1 = (CtfEnumPair) complexStruct[0].getValue();
- assertEquals("INT16_TYPE", variant1.getStringValue());
- assertEquals(Long.valueOf(1), variant1.getLongValue());
-
- assertEquals("a_string", complexStruct[1].getName());
- assertEquals("Test string", complexStruct[1].getValue());
-
- assertEquals("variant_value", complexStruct[2].getName());
- ITmfEventField variantField = (ITmfEventField) complexStruct[2].getValue();
- assertEquals("INT16_TYPE", variantField.getName());
- assertEquals(Long.valueOf(-200), variantField.getValue());
-
- ITmfEventField[] innerStruct = (ITmfEventField[]) complexStruct[3].getValue();
-
- assertEquals("seq_len", innerStruct[0].getName());
- assertEquals(Long.valueOf(10), innerStruct[0].getValue());
-
- assertEquals("a_sequence", innerStruct[1].getName());
- long[] seqValues = (long[]) innerStruct[1].getValue();
- long[] expectedValues = { 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 };
- assertArrayEquals(expectedValues, seqValues);
- }
-
- // ------------------------------------------------------------------------
- // Private stuff
- // ------------------------------------------------------------------------
-
- private synchronized CtfTmfEvent getEvent(long index) {
- TestEventRequest req = new TestEventRequest(index);
- fTrace.sendRequest(req);
- try {
- req.waitForCompletion();
- } catch (InterruptedException e) {
- return null;
- }
- return req.getEvent();
- }
-
- private class TestEventRequest extends TmfEventRequest {
-
- private CtfTmfEvent fRetEvent = null;
-
- public TestEventRequest(long index) {
- super(CtfTmfEvent.class,
- TmfTimeRange.ETERNITY,
- index,
- 1,
- ExecutionType.FOREGROUND);
- }
-
- @Override
- public void handleData(ITmfEvent event) {
- fRetEvent = (CtfTmfEvent) event;
- }
-
- public CtfTmfEvent getEvent() {
- return fRetEvent;
- }
- }
-
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.context;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ CtfLocationDataTest.class,
+ CtfLocationTest.class,
+ CtfTmfContextTest.class
+})
+public class AllTests {
+
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.context;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Collection of tests for the {@link CtfLocationInfo}
+ *
+ * @author alexmont
+ */
+public class CtfLocationDataTest {
+
+ private CtfLocationInfo fixture;
+
+ /**
+ * Perform pre-test initialization.
+ */
+ @Before
+ public void setUp() {
+ fixture = new CtfLocationInfo(1, 0);
+ }
+
+ /**
+ * Test for the .getTimestamp() and .getIndex() methods
+ */
+ @Test
+ public void testGetters() {
+ long timestamp = fixture.getTimestamp();
+ long index = fixture.getIndex();
+
+ assertEquals(1, timestamp);
+ assertEquals(0, index);
+ }
+
+ /**
+ * Test for the .hashCode() method
+ */
+ @Test
+ public void testHashCode() {
+ int code = fixture.hashCode();
+ assertEquals(962, code);
+ }
+
+ /**
+ * Test for the .equals() method
+ */
+ @Test
+ public void testEquals() {
+ CtfLocationInfo same = new CtfLocationInfo(1, 0);
+ CtfLocationInfo diff1 = new CtfLocationInfo(100, 0);
+ CtfLocationInfo diff2 = new CtfLocationInfo(1, 10);
+
+ assertTrue(fixture.equals(same));
+ assertFalse(fixture.equals(diff1));
+ assertFalse(fixture.equals(diff2));
+ }
+
+ /**
+ * Test for the .compareTo() method
+ */
+ @Test
+ public void testCompareTo() {
+ CtfLocationInfo same = new CtfLocationInfo(1, 0);
+ CtfLocationInfo smaller = new CtfLocationInfo(0, 0);
+ CtfLocationInfo bigger1 = new CtfLocationInfo(1000, 500);
+ CtfLocationInfo bigger2 = new CtfLocationInfo(1, 1);
+
+ assertEquals(0, same.compareTo(fixture));
+ assertEquals(-1, smaller.compareTo(fixture));
+ assertEquals(1, bigger1.compareTo(fixture));
+ assertEquals(1, bigger2.compareTo(fixture));
+ }
+
+ /**
+ * Test for the .toString() method
+ */
+ @Test
+ public void testToString() {
+ String expected = "Element [1/0]";
+ assertEquals(expected, fixture.toString());
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial generation with CodePro tools
+ * Alexandre Montplaisir - Clean up, consolidate redundant tests
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.context;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>CtfLocationTest</code> contains tests for the class
+ * <code>{@link CtfLocation}</code>.
+ *
+ * @author ematkho
+ * @version 1.0
+ */
+public class CtfLocationTest {
+
+ private CtfLocation fixture;
+
+ /**
+ * Perform pre-test initialization.
+ */
+ @Before
+ public void setUp() {
+ fixture = new CtfLocation(new CtfLocationInfo(1, 0));
+ }
+
+ /**
+ * Run the CtfLocation(Long) constructor test.
+ */
+ @Test
+ public void testCtfLocation_long() {
+ CtfLocationInfo location = new CtfLocationInfo(1, 0);
+ CtfLocation result = new CtfLocation(location);
+
+ assertNotNull(result);
+ assertEquals(1L, result.getLocationInfo().getTimestamp());
+ }
+
+ /**
+ * Run the CtfLocation(ITmfTimestamp) constructor test.
+ */
+ @Test
+ public void testCtfLocation_timestamp() {
+ ITmfTimestamp timestamp = new TmfTimestamp();
+ CtfLocation result = new CtfLocation(timestamp);
+
+ assertNotNull(result);
+ assertEquals(0L, result.getLocationInfo().getTimestamp());
+ }
+
+ /**
+ * Run the Long getLocation() method test.
+ */
+ @Test
+ public void testGetLocation() {
+ CtfLocationInfo location = fixture.getLocationInfo();
+ long result = location.getTimestamp();
+ assertEquals(1L, result);
+ }
+
+ /**
+ * Run the void setLocation(Long) method test.
+ */
+ @Test
+ public void testSetLocation() {
+ CtfLocationInfo location = new CtfLocationInfo(1337, 7331);
+ fixture = new CtfLocation(location);
+ }
+
+ /**
+ * Test the toString() method with a valid location.
+ */
+ @Test
+ public void testToString_valid(){
+ CtfLocation fixture2 = new CtfLocation(new CtfLocationInfo(1337, 7331));
+ assertEquals("CtfLocation [fLocationInfo=Element [1337/7331]]", fixture2.toString());
+ }
+
+ /**
+ * Test the toString() method with an invalid location.
+ */
+ @Test
+ public void testToString_invalid(){
+ CtfLocation fixture2 = new CtfLocation(new CtfLocationInfo(-1, -1));
+ assertEquals("CtfLocation [INVALID]", fixture2.toString());
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation
+ * Alexandre Montplaisir
+ * Patrick Tasse - Updated for removal of context clone
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.context;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
+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.Before;
+import org.junit.Test;
+
+/**
+ * Tests for the CtfTmfLightweightContext class
+ *
+ * @author Matthew Khouzam
+ * @version 1.1
+ */
+public class CtfTmfContextTest {
+
+ private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
+ private static final long begin = 1332170682440133097L; /* Trace start time */
+ private static final long end = 1332170692664579801L; /* Trace end time */
+
+ private CtfTmfTrace trace;
+
+ private class SeekerThread extends Thread {
+ long val;
+
+ public void setVal(long val) {
+ this.val = val;
+ }
+ }
+
+ /**
+ * Pre-test initialization
+ *
+ * @throws TmfTraceException
+ * If the trace couldn't be init'ed, which shouldn't happen.
+ */
+ @Before
+ public void setUp() throws TmfTraceException {
+ assumeTrue(testTrace.exists());
+ trace = new CtfTmfTrace();
+ String path = testTrace.getPath();
+ trace.initTrace((IResource) null, path, CtfTmfEvent.class);
+ }
+
+ /**
+ * Index all the events in the test trace.
+ */
+ @Test
+ public void testIndexing() {
+ CtfTmfContext context = new CtfTmfContext(trace);
+ context.seek(0);
+
+ int count = 0;
+ while (trace.getNext(context) != null) {
+ count++;
+ }
+ assertTrue(count > 0);
+ }
+
+ /**
+ * Context fuzzer. Use an amount of contexts greater than the size of the
+ * iterator cache and have them access the trace in parallel.
+ *
+ * @throws InterruptedException
+ * Would fail the test
+ */
+ @Test
+ public void testTooManyContexts() throws InterruptedException {
+ final int lwcCount = 101;
+ double increment = (end - begin) / lwcCount;
+ final ArrayList<Long> vals = new ArrayList<>();
+ final ArrayList<Thread> threads = new ArrayList<>();
+ final ArrayList<CtfTmfContext> tooManyContexts = new ArrayList<>();
+
+ for (double i = begin; i < end; i += increment) {
+ SeekerThread thread = new SeekerThread() {
+ @Override
+ public void run() {
+ CtfTmfContext lwc = new CtfTmfContext(trace);
+ lwc.seek(val);
+ trace.getNext(lwc);
+ synchronized(trace){
+ if (lwc.getCurrentEvent() != null) {
+ vals.add(lwc.getCurrentEvent().getTimestamp().getValue());
+ }
+ tooManyContexts.add(lwc);
+ }
+ }
+ };
+ thread.setVal((long)i);
+ threads.add(thread);
+ thread.start();
+ }
+
+ for (Thread t: threads){
+ t.join();
+ }
+
+ for (long val : vals){
+ assertTrue(val >= begin);
+ assertTrue(val <= end);
+ }
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.event;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ CtfTmfEventFieldTest.class,
+ CtfTmfEventTest.class,
+ CtfTmfEventTypeTest.class,
+ CtfTmfLostEventStatisticsTest.class,
+ CtfTmfLostEventsTest.class,
+ EventContextTest.class
+})
+public class AllTests {
+
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial generation with CodePro tools
+ * Alexandre Montplaisir - Clean up, consolidate redundant tests
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.event;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
+import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.FloatDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.FloatDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.StringDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.VariantDeclaration;
+import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
+import org.eclipse.tracecompass.internal.ctf.core.event.types.ArrayDeclaration;
+import org.eclipse.tracecompass.internal.ctf.core.event.types.SequenceDeclaration;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventField;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>CtfTmfEventFieldTest</code> contains tests for the class
+ * <code>{@link CtfTmfEventField}</code>.
+ *
+ * @author Matthew Khouzam
+ * @version 1.0
+ */
+public class CtfTmfEventFieldTest {
+
+ private static final @NonNull String ROOT = "root";
+ private static final String SEQ = "seq";
+ private static final @NonNull String ARRAY_STR = "array_str";
+ private static final @NonNull String ARRAY_FLOAT = "array_float";
+ private static final @NonNull String ARRAY_INT = "array_int";
+ private static final @NonNull String ARRAY_STRUCT = "array_struct";
+ private static final @NonNull String ARRAY_VARIANT = "array_variant";
+ private static final @NonNull String ARRAY_ENUM = "array_enum";
+ private static final String STR = "str";
+ private static final String FLOAT = "float";
+ private static final String LEN = "len";
+ private static final String INT = "int";
+ private static final String NAME = "test";
+ private static final String STRUCT = "struct";
+ private static final String VARIANT = "variant";
+ private static final String ENUM = "enum";
+
+ private static final byte TEST_NUMBER = 2;
+ private static final String TEST_STRING = "two";
+
+ private static final int ARRAY_SIZE = 2;
+
+ private StructDefinition fixture;
+
+ /**
+ * Perform pre-test initialization.
+ *
+ * @throws UnsupportedEncodingException
+ * Thrown when UTF-8 encoding is not available.
+ * @throws CTFReaderException
+ * error
+ */
+ @Before
+ public void setUp() throws UnsupportedEncodingException, CTFReaderException {
+ final byte[] testStringBytes = TEST_STRING.getBytes("UTF-8");
+
+ int capacity = 2048;
+ ByteBuffer bb = ByteBuffer.allocateDirect(capacity);
+
+ StructDeclaration sDec = new StructDeclaration(1l);
+ StringDeclaration strDec = new StringDeclaration();
+ IntegerDeclaration intDec = IntegerDeclaration.UINT_8_DECL;
+ FloatDeclaration flDec = new FloatDeclaration(8, 24,
+ ByteOrder.BIG_ENDIAN, 8);
+ SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec);
+ StructDeclaration structDec = new StructDeclaration(8);
+ EnumDeclaration enumDec = new EnumDeclaration(intDec);
+ VariantDeclaration varDec = new VariantDeclaration();
+ ArrayDeclaration arrStrDec = new ArrayDeclaration(ARRAY_SIZE, strDec);
+ ArrayDeclaration arrFloatDec = new ArrayDeclaration(ARRAY_SIZE, flDec);
+ ArrayDeclaration arrIntDec = new ArrayDeclaration(ARRAY_SIZE, intDec);
+ ArrayDeclaration arrStructDec = new ArrayDeclaration(ARRAY_SIZE, structDec);
+ ArrayDeclaration arrVariantDec = new ArrayDeclaration(ARRAY_SIZE, varDec);
+ ArrayDeclaration arrEnumDec = new ArrayDeclaration(ARRAY_SIZE, enumDec);
+
+ sDec.addField(INT, intDec);
+ bb.put(TEST_NUMBER);
+
+ sDec.addField(ARRAY_INT, arrIntDec);
+ for (int i = 0; i < ARRAY_SIZE; ++i) {
+ bb.put(TEST_NUMBER);
+ }
+
+ sDec.addField(LEN, intDec);
+ bb.put(TEST_NUMBER);
+
+ sDec.addField(FLOAT, flDec);
+ bb.putFloat(TEST_NUMBER);
+
+ sDec.addField(ARRAY_FLOAT, arrFloatDec);
+ for (int i = 0; i < ARRAY_SIZE; ++i) {
+ bb.putFloat(TEST_NUMBER);
+ }
+
+ sDec.addField(STR, strDec);
+ bb.put(testStringBytes);
+ bb.put((byte) 0);
+
+ sDec.addField(ARRAY_STR, arrStrDec);
+ for (int i = 0; i < ARRAY_SIZE; ++i) {
+ bb.put(testStringBytes);
+ bb.put((byte) 0);
+ }
+
+ sDec.addField(SEQ, seqDec);
+ bb.put(TEST_NUMBER);
+ bb.put(TEST_NUMBER);
+
+ structDec.addField(STR, strDec);
+ structDec.addField(INT, intDec);
+ sDec.addField(STRUCT, structDec);
+ bb.put(testStringBytes);
+ bb.put((byte) 0);
+ bb.put(TEST_NUMBER);
+
+ sDec.addField(ARRAY_STRUCT, arrStructDec);
+ for (int i = 0; i < ARRAY_SIZE; ++i) {
+ bb.put(testStringBytes);
+ bb.put((byte) 0);
+ bb.put(TEST_NUMBER);
+ }
+
+ enumDec.add(0, 1, LEN);
+ enumDec.add(2, 3, FLOAT);
+ sDec.addField(ENUM, enumDec);
+ bb.put(TEST_NUMBER);
+
+ sDec.addField(ARRAY_ENUM, arrEnumDec);
+ for (int i = 0; i < ARRAY_SIZE; ++i) {
+ bb.put(TEST_NUMBER);
+ }
+
+ varDec.addField(LEN, intDec);
+ varDec.addField(FLOAT, flDec);
+ varDec.setTag(ENUM);
+ sDec.addField(VARIANT, varDec);
+ bb.putFloat(TEST_NUMBER);
+
+ sDec.addField(ARRAY_VARIANT, arrVariantDec);
+ for (int i = 0; i < ARRAY_SIZE; ++i) {
+ bb.putFloat(TEST_NUMBER);
+ }
+
+ fixture = sDec.createDefinition(fixture, ROOT, new BitBuffer(bb));
+
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test.
+ */
+ @Test
+ public void testParseField_float() {
+ FloatDefinition fieldDef = (FloatDefinition) fixture.lookupDefinition(FLOAT);
+ CtfTmfEventField result = CtfTmfEventField.parseField((IDefinition)fieldDef, "_" + NAME);
+ assertEquals("test=2.0", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test for an
+ * array of floats field.
+ */
+ @Test
+ public void testParseField_array_float() {
+ IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_FLOAT);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=[2.0, 2.0]", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test.
+ */
+ @Test
+ public void testParseField_int() {
+ IDefinition fieldDef = fixture.lookupDefinition(INT);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=2", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test for an
+ * array of integers field.
+ */
+ @Test
+ public void testParseField_array_int() {
+ IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_INT);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=[2, 2]", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test.
+ */
+ @Test
+ public void testParseField_sequence() {
+ IDefinition fieldDef = fixture.lookupDefinition(SEQ);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=[2, 2]", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test.
+ */
+ @Test
+ public void testParseField_sequence_value() {
+ IDefinition fieldDef = fixture.lookupDefinition(SEQ);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ long[] values = (long[]) result.getValue();
+ long[] expected = new long[] { 2, 2 };
+ assertArrayEquals(expected, values);
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test.
+ */
+ @Test
+ public void testParseField_string() {
+ IDefinition fieldDef = fixture.lookupDefinition(STR);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=two", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test for an
+ * array of strings field.
+ */
+ @Test
+ public void testParseField_array_string() {
+ IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_STR);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=[two, two]", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test.
+ */
+ @Test
+ public void testParseField_struct() {
+ IDefinition fieldDef = fixture.lookupDefinition(STRUCT);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=[str=two, int=2]", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test for an
+ * array of structs field.
+ */
+ @Test
+ public void testParseField_array_struct() {
+ IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_STRUCT);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=[[str=two, int=2], [str=two, int=2]]", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test.
+ */
+ @Test
+ public void testParseField_enum() {
+ IDefinition fieldDef = fixture.lookupDefinition(ENUM);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=float", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test for an
+ * array of enums field.
+ */
+ @Test
+ public void testParseField_array_enum() {
+ IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_ENUM);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=[float, float]", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test.
+ */
+ @Test
+ public void testParseField_variant() {
+ IDefinition fieldDef = fixture.lookupDefinition(VARIANT);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=float=2.0", result.toString());
+ }
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test for an
+ * array of variants field.
+ */
+ @Test
+ public void testParseField_array_variant() {
+ IDefinition fieldDef = fixture.lookupArrayDefinition(ARRAY_VARIANT);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=[float=2.0, float=2.0]", result.toString());
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial generation with CodePro tools
+ * Alexandre Montplaisir - Clean up, consolidate redundant tests
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.event;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assume.assumeTrue;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventFactory;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.iterator.CtfIterator;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>CtfTmfEventTest</code> contains tests for the class
+ * <code>{@link CtfTmfEvent}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+public class CtfTmfEventTest {
+
+ private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
+
+ private static CtfTmfEvent nullEvent;
+ private CtfTmfEvent fixture;
+
+ /**
+ * Perform pre-test initialization.
+ *
+ * @throws CTFReaderException
+ * error
+ */
+ @Before
+ public void setUp() throws CTFReaderException {
+ assumeTrue(testTrace.exists());
+ try (CtfTmfTrace trace = testTrace.getTrace();
+ CtfIterator tr = new CtfIterator(trace);) {
+ tr.advance();
+ fixture = tr.getCurrentEvent();
+ nullEvent = CtfTmfEventFactory.getNullEvent(trace);
+ }
+ }
+
+ /**
+ * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
+ */
+ @Test
+ public void testCTFEvent_read() {
+ assertNotNull(fixture);
+ }
+
+ /**
+ * Run the int getCPU() method test.
+ */
+ @Test
+ public void testGetCPU() {
+ int result = nullEvent.getCPU();
+ assertEquals(-1, result);
+ }
+
+ /**
+ * Run the String getEventName() method test.
+ */
+ @Test
+ public void testGetEventName() {
+ String result = nullEvent.getType().getName();
+ assertEquals("Empty CTF event", result);
+ }
+
+ /**
+ * Run the ArrayList<String> getFieldNames() method test.
+ */
+ @Test
+ public void testGetFieldNames() {
+ Collection<String> result = fixture.getContent().getFieldNames();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the Object getFieldValue(String) method test.
+ */
+ @Test
+ public void testGetFieldValue() {
+ String fieldName = "pid";
+ ITmfEventField result = fixture.getContent().getField(fieldName);
+
+ assertNotNull(result);
+ assertNotNull(result.getValue());
+ }
+
+ /**
+ * Run the HashMap<String, CTFEventField> getFields() method test.
+ */
+ @Test
+ public void testGetFields() {
+ Collection<? extends ITmfEventField> fields = nullEvent.getContent().getFields();
+ assertEquals(0, fields.size());
+ }
+
+ /**
+ * Run the ITmfEventField getSubFieldValue(String[]) method test.
+ */
+ @Test
+ public void testGetSubFieldValue() {
+ /* Field exists */
+ String[] names = { "pid" };
+ assertNotNull(fixture.getContent().getSubField(names));
+
+ /* First field exists, not the second */
+ String[] names2 = { "pid", "abcd" };
+ assertNull(fixture.getContent().getSubField(names2));
+
+ /* Both field do not exist */
+ String[] names3 = { "pfid", "abcd" };
+ assertNull(fixture.getContent().getSubField(names3));
+
+ /* TODO Missing case of embedded field, need event for it */
+ }
+
+ /**
+ * Run the long getID() method test.
+ */
+ @Test
+ public void testGetID() {
+ long result = nullEvent.getID();
+ assertEquals(-1L, result);
+ }
+
+ /**
+ * Run the long getTimestamp() method test.
+ */
+ @Test
+ public void testGetTimestamp() {
+ long result = nullEvent.getTimestamp().getValue();
+ assertEquals(-1L, result);
+ }
+
+ /**
+ * Test the getters for the reference, source and type.
+ */
+ @Test
+ public void testGetters() {
+ long rank = fixture.getRank();
+ try (CtfTmfTrace trace = fixture.getTrace();) {
+ assertEquals("kernel", trace.getName());
+ }
+ String reference = fixture.getReference();
+ String source = fixture.getSource();
+ ITmfEventType type = fixture.getType();
+ assertEquals(ITmfContext.UNKNOWN_RANK, rank);
+
+ assertEquals("channel0_1", reference);
+ assertEquals("1", source);
+ assertEquals("lttng_statedump_vm_map", type.toString());
+ }
+
+ /**
+ * Test the custom CTF attributes methods. The test trace doesn't have any,
+ * so the list of attributes should be empty.
+ */
+ @Test
+ public void testCustomAttributes() {
+ Set<String> attributes = fixture.listCustomAttributes();
+ assertEquals(0, attributes.size());
+
+ String attrib = fixture.getCustomAttribute("bozo");
+ assertNull(attrib);
+ }
+
+ /**
+ * Test the toString() method
+ */
+ @Test
+ public void testToString() {
+ String s = fixture.getContent().toString();
+ assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s);
+ }
+
+ /**
+ * Test the {@link CtfTmfEventFactory#getNullEvent(CtfTmfTrace)} method, and
+ * the nullEvent's values.
+ */
+ @Test
+ public void testNullEvent() {
+ CtfTmfEvent nullEvent2 = CtfTmfEventFactory.getNullEvent(fixture.getTrace());
+ assertSame(nullEvent2, nullEvent);
+ assertNotNull(nullEvent);
+ assertEquals(-1, nullEvent.getCPU());
+ assertEquals("Empty CTF event", nullEvent.getType().getName());
+ assertNull(nullEvent.getReference());
+ assertEquals(0, nullEvent.getContent().getFields().size());
+ assertEquals(-1L, nullEvent.getID());
+ assertEquals(-1L, nullEvent.getTimestamp().getValue());
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial generation with CodePro tools
+ * Alexandre Montplaisir - Clean up, consolidate redundant tests
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.event;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType;
+import org.junit.Test;
+
+/**
+ * The class <code>CtfTmfEventTypeTest</code> contains tests for the class
+ * <code>{@link CtfTmfEventType}</code>.
+ *
+ * @author ematkho
+ * @version 1.0
+ */
+public class CtfTmfEventTypeTest {
+
+ /**
+ * Run the CtfTmfEventType(String,String,ITmfEventField) constructor test.
+ */
+ @Test
+ public void testCtfTmfEventType() {
+ String eventName = "";
+ ITmfEventField content = new TmfEventField("", null, new ITmfEventField[] {});
+ CtfTmfEventType result = new CtfTmfEventType(eventName, content);
+
+ assertNotNull(result);
+ assertEquals("", result.toString());
+ assertEquals("", result.getName());
+ }
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString() {
+ ITmfEventField emptyField = new TmfEventField("", null, new ITmfEventField[] {});
+ CtfTmfEventType fixture = new CtfTmfEventType("" , emptyField);
+
+ String result = fixture.toString();
+
+ assertEquals("", result);
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.event;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+import java.util.Map;
+
+import org.eclipse.tracecompass.ctf.core.CTFStrings;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.tracecompass.tmf.core.statistics.TmfStateStatistics;
+import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsEventTypesModule;
+import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsTotalsModule;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
+
+/**
+ * Unit tests for handling of lost events by the statistics backends.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class CtfTmfLostEventStatisticsTest {
+
+ /** Time-out tests after 30 seconds */
+ @Rule
+ public TestRule globalTimeout= new Timeout(30000);
+
+ /**Test trace with lost events */
+ private static final CtfTmfTestTrace lostEventsTrace = CtfTmfTestTrace.HELLO_LOST;
+
+ private ITmfTrace fTrace;
+
+ /** The statistics back-end object for the trace with lost events */
+ private ITmfStatistics fStats;
+
+ /* The two analysis modules needed for fStats */
+ private TmfStatisticsTotalsModule fTotalsMod;
+ private TmfStatisticsEventTypesModule fEventTypesMod;
+
+ // ------------------------------------------------------------------------
+ // Maintenance
+ // ------------------------------------------------------------------------
+
+ /**
+ * Class setup
+ */
+ @BeforeClass
+ public static void setUpClass() {
+ assumeTrue(lostEventsTrace.exists());
+ }
+
+ /**
+ * Test setup
+ */
+ @Before
+ public void setUp() {
+ fTrace = lostEventsTrace.getTrace();
+
+ /* Prepare the two analysis-backed state systems */
+ fTotalsMod = new TmfStatisticsTotalsModule();
+ fEventTypesMod = new TmfStatisticsEventTypesModule();
+ try {
+ fTotalsMod.setTrace(fTrace);
+ fEventTypesMod.setTrace(fTrace);
+ } catch (TmfAnalysisException e) {
+ fail();
+ }
+
+ fTotalsMod.schedule();
+ fEventTypesMod.schedule();
+ assertTrue(fTotalsMod.waitForCompletion());
+ assertTrue(fEventTypesMod.waitForCompletion());
+
+ ITmfStateSystem totalsSS = fTotalsMod.getStateSystem();
+ ITmfStateSystem eventTypesSS = fEventTypesMod.getStateSystem();
+ assertNotNull(totalsSS);
+ assertNotNull(eventTypesSS);
+
+ fStats = new TmfStateStatistics(totalsSS, eventTypesSS);
+ }
+
+ /**
+ * Test cleanup
+ */
+ @After
+ public void tearDown() {
+ fStats.dispose();
+ fTotalsMod.dispose();
+ fEventTypesMod.dispose();
+ fTrace.dispose();
+ }
+
+ // ------------------------------------------------------------------------
+ // Test methods
+ // ------------------------------------------------------------------------
+
+ /*
+ * Trace start = 1376592664828559410
+ * Trace end = 1376592665108210547
+ */
+
+ private static final long rangeStart = 1376592664900000000L;
+ private static final long rangeEnd = 1376592665000000000L;
+
+ /**
+ * Test the total number of "real" events. Make sure the lost events aren't
+ * counted in the total.
+ */
+ @Test
+ public void testLostEventsTotals() {
+ long realEvents = fStats.getEventsTotal();
+ assertEquals(32300, realEvents);
+ }
+
+ /**
+ * Test the number of real events in a given range. Lost events shouldn't be
+ * counted.
+ */
+ @Test
+ public void testLostEventsTotalInRange() {
+ long realEventsInRange = fStats.getEventsInRange(rangeStart, rangeEnd);
+ assertEquals(11209L, realEventsInRange);
+ }
+
+ /**
+ * Test the total number of lost events reported in the trace.
+ */
+ @Test
+ public void testLostEventsTypes() {
+ Map<String, Long> events = fStats.getEventTypesTotal();
+ Long lostEvents = events.get(CTFStrings.LOST_EVENT_NAME);
+ assertEquals(Long.valueOf(967700L), lostEvents);
+ }
+
+ /**
+ * Test the number of lost events reported in a given range.
+ */
+ @Test
+ public void testLostEventsTypesInRange() {
+ Map<String, Long> eventsInRange = fStats.getEventTypesInRange(rangeStart, rangeEnd);
+ long lostEventsInRange = eventsInRange.get(CTFStrings.LOST_EVENT_NAME);
+ assertEquals(363494L, lostEventsInRange);
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.event;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent;
+import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+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.timestamp.CtfTmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests to verify that lost events are handled correctly.
+ *
+ * Be wary if you are using Babeltrace to cross-check those values. There could
+ * be a bug in Babeltrace with regards to lost events. See
+ * http://bugs.lttng.org/issues/589
+ *
+ * It's not 100% sure at this point which implementation is correct, so for now
+ * these tests assume the Java implementation is the right one.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class CtfTmfLostEventsTest {
+
+ private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.HELLO_LOST;
+
+ private CtfTmfTrace fixture = null;
+
+ /**
+ * Class setup
+ */
+ @Before
+ public void setUp() {
+ assumeTrue(testTrace.exists());
+ fixture = testTrace.getTrace();
+ fixture.indexTrace(true);
+ }
+
+ /**
+ * Clean-up
+ */
+ @After
+ public void tearDown() {
+ if (fixture != null) {
+ fixture.dispose();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Test methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test that the number of events is reported correctly (a range of lost
+ * events is counted as one event).
+ */
+ @Test
+ public void testNbEvents() {
+ final long expectedReal = 32300;
+ final long expectedLost = 562;
+
+ EventCountRequest req = new EventCountRequest();
+ fixture.sendRequest(req);
+ try {
+ req.waitForCompletion();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ assertEquals(expectedReal, req.getReal());
+ assertEquals(expectedLost, req.getLost());
+ }
+
+ /**
+ * Test getting the first lost event from the trace.
+ */
+ @Test
+ public void testFirstLostEvent() {
+ final long rank = 153;
+ final ITmfTimestamp start = new CtfTmfTimestamp(1376592664828848222L);
+ final ITmfTimestamp end = new CtfTmfTimestamp(1376592664828848540L);
+ final long nbLost = 859;
+
+ final CtfTmfEvent ev = getOneEventTime(start);
+ /* Make sure seeking by rank yields the same event */
+ final CtfTmfEvent ev2 = getOneEventRank(rank);
+ assertEquals(ev, ev2);
+
+ assertTrue(ev instanceof ITmfLostEvent);
+ ITmfLostEvent event = (ITmfLostEvent) ev;
+
+ assertEquals(start, event.getTimestamp());
+ assertEquals(start, event.getTimeRange().getStartTime());
+ assertEquals(end, event.getTimeRange().getEndTime());
+ assertEquals(nbLost, event.getNbLostEvents());
+ }
+
+ /**
+ * Test getting the second lost event from the trace.
+ */
+ @Test
+ public void testSecondLostEvent() {
+ final long rank = 191;
+ final ITmfTimestamp start = new CtfTmfTimestamp(1376592664829402521L);
+ final ITmfTimestamp end = new CtfTmfTimestamp(1376592664829403076L);
+ final long nbLost = 488;
+
+ final CtfTmfEvent ev = getOneEventTime(start);
+ /* Make sure seeking by rank yields the same event */
+ final CtfTmfEvent ev2 = getOneEventRank(rank);
+ assertEquals(ev, ev2);
+
+ assertTrue(ev instanceof ITmfLostEvent);
+ ITmfLostEvent event = (ITmfLostEvent) ev;
+
+ assertEquals(start, event.getTimestamp());
+ assertEquals(start, event.getTimeRange().getStartTime());
+ assertEquals(end, event.getTimeRange().getEndTime());
+ assertEquals(nbLost, event.getNbLostEvents());
+ }
+
+ /**
+ * Test getting one normal event from the trace (lost events should not
+ * interfere).
+ */
+ @Test
+ public void testNormalEvent() {
+ final long rank = 200;
+ final ITmfTimestamp ts = new CtfTmfTimestamp(1376592664829423928L);
+
+ final CtfTmfEvent event = getOneEventTime(ts);
+ /* Make sure seeking by rank yields the same event */
+ final CtfTmfEvent event2 = getOneEventRank(rank);
+ assertEquals(event, event2);
+
+ assertFalse(event instanceof ITmfLostEvent);
+ assertEquals(ts, event.getTimestamp());
+ }
+
+ // ------------------------------------------------------------------------
+ // Event requests
+ // ------------------------------------------------------------------------
+
+ private CtfTmfEvent getOneEventRank(long rank) {
+ OneEventRequestPerRank req = new OneEventRequestPerRank(rank);
+ fixture.sendRequest(req);
+ try {
+ req.waitForCompletion();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return req.getEvent();
+ }
+
+ private CtfTmfEvent getOneEventTime(ITmfTimestamp ts) {
+ OneEventRequestPerTs req = new OneEventRequestPerTs(ts);
+ fixture.sendRequest(req);
+ try {
+ req.waitForCompletion();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return req.getEvent();
+ }
+
+ private class OneEventRequestPerRank extends TmfEventRequest {
+
+ private CtfTmfEvent event = null;
+
+ public OneEventRequestPerRank(long rank) {
+ super(CtfTmfEvent.class, TmfTimeRange.ETERNITY, rank, 1, ExecutionType.FOREGROUND);
+ }
+
+ @Override
+ public void handleData(ITmfEvent ev) {
+ /* Type is checked by the request, cast should be safe */
+ event = (CtfTmfEvent) ev;
+ }
+
+ public CtfTmfEvent getEvent() {
+ return event;
+ }
+ }
+
+ private class OneEventRequestPerTs extends TmfEventRequest {
+
+ private CtfTmfEvent event = null;
+
+ public OneEventRequestPerTs(ITmfTimestamp ts) {
+ super(CtfTmfEvent.class,
+ new TmfTimeRange(ts, TmfTimestamp.PROJECT_IS_CANNED),
+ 0, 1, ExecutionType.FOREGROUND);
+ }
+
+ @Override
+ public void handleData(ITmfEvent ev) {
+ event = (CtfTmfEvent) ev;
+ }
+
+ public CtfTmfEvent getEvent() {
+ return event;
+ }
+ }
+
+ private class EventCountRequest extends TmfEventRequest {
+
+ private long nbReal = 0;
+ private long nbLost = 0;
+
+ public EventCountRequest() {
+ super(CtfTmfEvent.class, TmfTimeRange.ETERNITY, 0,
+ ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND);
+ }
+
+ @Override
+ public void handleData(ITmfEvent event) {
+ if (event instanceof ITmfLostEvent) {
+ nbLost++;
+ } else {
+ nbReal++;
+ }
+ }
+
+ public long getReal() {
+ return nbReal;
+ }
+
+ public long getLost() {
+ return nbLost;
+ }
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.event;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+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.timestamp.CtfTmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for reading event contexts from a CtfTmfTrace.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class EventContextTest {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ /* We use test trace #2, kernel_vm, which has event contexts */
+ private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL_VM;
+
+ private CtfTmfTrace fixture;
+ private long startTime;
+ private long endTime;
+
+ // ------------------------------------------------------------------------
+ // Class methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * Perform pre-class initialization.
+ *
+ * @throws TmfTraceException
+ * If the test trace is not found
+ */
+ @Before
+ public void setUp() throws TmfTraceException {
+ assumeTrue(testTrace.exists());
+ fixture = new CtfTmfTrace();
+ fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
+ fixture.indexTrace(true);
+
+ startTime = fixture.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ endTime = fixture.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ }
+
+ /**
+ * Perform post-class clean-up.
+ */
+ @After
+ public void tearDown() {
+ if (fixture != null) {
+ fixture.dispose();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Test methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * Make sure the trace is the correct one, and its timestamps are read
+ * correctly.
+ */
+ @Test
+ public void testTrace() {
+ assertEquals(1363700740555978750L, startTime);
+ assertEquals(1363700770550261288L, endTime);
+ }
+
+ /**
+ * Test the context of the very first event of the trace.
+ */
+ @Test
+ public void testContextStart() {
+ CtfTmfEvent firstEvent = getEventAt(startTime);
+ long perfPageFault = (Long) firstEvent.getContent().getField("context._perf_page_fault").getValue();
+ String procname = (String) firstEvent.getContent().getField("context._procname").getValue();
+ long tid = (Long) firstEvent.getContent().getField("context._tid").getValue();
+
+ assertEquals(613, perfPageFault);
+ assertEquals("lttng-sessiond", procname);
+ assertEquals(1230, tid);
+ }
+
+ /**
+ * Test the context of the event at 1363700745.559739078.
+ */
+ @Test
+ public void testContext1() {
+ long time = startTime + 5000000000L; // 1363700745.559739078
+ CtfTmfEvent event = getEventAt(time);
+ long perfPageFault = (Long) event.getContent().getField("context._perf_page_fault").getValue();
+ String procname = (String) event.getContent().getField("context._procname").getValue();
+ long tid = (Long) event.getContent().getField("context._tid").getValue();
+
+ assertEquals(6048, perfPageFault);
+ assertEquals("swapper/0", procname);
+ assertEquals(0, tid);
+ }
+
+ /**
+ * Test the context of the event at 1363700750.559707062.
+ */
+ @Test
+ public void testContext2() {
+ long time = startTime + 2 * 5000000000L; // 1363700750.559707062
+ CtfTmfEvent event = getEventAt(time);
+ long perfPageFault = (Long) event.getContent().getField("context._perf_page_fault").getValue();
+ String procname = (String) event.getContent().getField("context._procname").getValue();
+ long tid = (Long) event.getContent().getField("context._tid").getValue();
+
+ assertEquals(13258, perfPageFault);
+ assertEquals("swapper/0", procname);
+ assertEquals(0, tid);
+ }
+
+ /**
+ * Test the context of the event at 1363700755.555723128, which is roughly
+ * mid-way through the trace.
+ */
+ @Test
+ public void testContextMiddle() {
+ long midTime = startTime + (endTime - startTime) / 2L; // 1363700755.555723128
+ CtfTmfEvent midEvent = getEventAt(midTime);
+ long perfPageFault = (Long) midEvent.getContent().getField("context._perf_page_fault").getValue();
+ String procname = (String) midEvent.getContent().getField("context._procname").getValue();
+ long tid = (Long) midEvent.getContent().getField("context._tid").getValue();
+
+ assertEquals(19438, perfPageFault);
+ assertEquals("swapper/0", procname);
+ assertEquals(0, tid);
+ }
+
+ /**
+ * Test the context of the event at 1363700760.559719724.
+ */
+ @Test
+ public void testContext3() {
+ long time = startTime + 4 * 5000000000L; // 1363700760.559719724
+ CtfTmfEvent event = getEventAt(time);
+ long perfPageFault = (Long) event.getContent().getField("context._perf_page_fault").getValue();
+ String procname = (String) event.getContent().getField("context._procname").getValue();
+ long tid = (Long) event.getContent().getField("context._tid").getValue();
+
+ assertEquals(21507, perfPageFault);
+ assertEquals("swapper/0", procname);
+ assertEquals(0, tid);
+ }
+
+ /**
+ * Test the context of the event at 1363700765.559714634.
+ */
+ @Test
+ public void testContext4() {
+ long time = startTime + 5 * 5000000000L; // 1363700765.559714634
+ CtfTmfEvent event = getEventAt(time);
+ long perfPageFault = (Long) event.getContent().getField("context._perf_page_fault").getValue();
+ String procname = (String) event.getContent().getField("context._procname").getValue();
+ long tid = (Long) event.getContent().getField("context._tid").getValue();
+
+ assertEquals(21507, perfPageFault);
+ assertEquals("swapper/0", procname);
+ assertEquals(0, tid);
+ }
+
+ /**
+ * Test the context of the last event of the trace.
+ */
+ @Test
+ public void testContextEnd() {
+ CtfTmfEvent lastEvent = getEventAt(endTime);
+ long perfPageFault = (Long) lastEvent.getContent().getField("context._perf_page_fault").getValue();
+ String procname = (String) lastEvent.getContent().getField("context._procname").getValue();
+ long tid = (Long) lastEvent.getContent().getField("context._tid").getValue();
+
+ assertEquals(22117, perfPageFault);
+ assertEquals("lttng-sessiond", procname);
+ assertEquals(1230, tid);
+ }
+
+ // ------------------------------------------------------------------------
+ // Private stuff
+ // ------------------------------------------------------------------------
+
+ private synchronized CtfTmfEvent getEventAt(long timestamp) {
+ EventContextTestRequest req = new EventContextTestRequest(timestamp);
+ fixture.sendRequest(req);
+ try {
+ req.waitForCompletion();
+ } catch (InterruptedException e) {
+ return null;
+ }
+ return req.getEvent();
+ }
+
+ private class EventContextTestRequest extends TmfEventRequest {
+
+ private CtfTmfEvent retEvent = null;
+
+ public EventContextTestRequest(long timestamp) {
+ super(CtfTmfEvent.class,
+ new TmfTimeRange(new CtfTmfTimestamp(timestamp), TmfTimestamp.BIG_CRUNCH),
+ 0, 1, ExecutionType.FOREGROUND);
+ }
+
+ @Override
+ public void handleData(ITmfEvent event) {
+ retEvent = (CtfTmfEvent) event;
+ }
+
+ public CtfTmfEvent getEvent() {
+ return retEvent;
+ }
+ }
+}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.headless;
-
-import java.util.Vector;
-
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfContext;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-
-/**
- * Test and benchmark reading a CTF LTTng kernel trace.
- *
- * @author Matthew Khouzam
- */
-public class Benchmark {
-
- /**
- * Run the benchmark.
- *
- * @param args The command-line arguments
- */
- public static void main(final String[] args) {
- final String TRACE_PATH = "testfiles/kernel";
- final int NUM_LOOPS = 100;
-
- // Change this to enable text output
- final boolean USE_TEXT = true;
-
- // Work variables
- long nbEvent = 0L;
- final Vector<Double> benchs = new Vector<>();
- long start, stop;
- for (int loops = 0; loops < NUM_LOOPS; loops++) {
- nbEvent = 0L;
- try (CtfTmfTrace trace = new CtfTmfTrace();) {
- try {
- trace.initTrace(null, TRACE_PATH, CtfTmfEvent.class);
- } catch (final TmfTraceException e) {
- loops = NUM_LOOPS + 1;
- break;
- }
-
- start = System.nanoTime();
- if (nbEvent != -1) {
- final CtfTmfContext traceReader = (CtfTmfContext) trace.seekEvent(0);
-
- start = System.nanoTime();
- CtfTmfEvent current = traceReader.getCurrentEvent();
- while (current != null) {
- nbEvent++;
- if (USE_TEXT) {
-
- System.out.println("Event " + nbEvent + " Time "
- + current.getTimestamp().toString() + " type " + current.getType().getName()
- + " on CPU " + current.getSource() + " " + current.getContent().toString());
- }
- // advance the trace to the next event.
- boolean hasMore = traceReader.advance();
- if (hasMore) {
- // you can know the trace has more events.
- }
- current = traceReader.getCurrentEvent();
- }
- }
- stop = System.nanoTime();
- System.out.print('.');
- final double time = (stop - start) / (double) nbEvent;
- benchs.add(time);
- } // trace.close()
- }
- System.out.println("");
- double avg = 0;
- for (final double val : benchs) {
- avg += val;
- }
- avg /= benchs.size();
- System.out.println("Time to read = " + avg + " events/ns");
- for (final Double val : benchs) {
- System.out.print(val);
- System.out.print(", ");
- }
-
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * William Bourque <wbourque@gmail.com> - Initial API and implementation
- * Matthew Khouzam - Update to CtfTmf trace and events
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.headless;
-
-import java.util.Vector;
-
-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.TmfExperiment;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-
-/**
- * Benchmark the event request subsystem of TMF.
- */
-public class RequestBenchmark extends TmfEventRequest {
-
- private RequestBenchmark(final Class<? extends ITmfEvent> dataType,
- final TmfTimeRange range, final int nbRequested) {
- super(dataType, range, 0, nbRequested, ExecutionType.FOREGROUND);
- }
-
- // Path of the trace
- private static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel";
-
- // Change this to run several time over the same trace
- private static final int NB_OF_PASS = 100;
-
- // Work variables
- private static int nbEvent = 0;
- private static TmfExperiment fExperiment = null;
- private static Vector<Double> benchs = new Vector<>();
-
- /**
- * Run the benchmark
- *
- * @param args
- * The command-line arguments
- */
- public static void main(final String[] args) {
-
- try {
- /* Our experiment will contains ONE trace */
- final ITmfTrace[] traces = new ITmfTrace[1];
- traces[0] = new CtfTmfTrace();
- traces[0].initTrace(null, TRACE_PATH, CtfTmfEvent.class);
- /* Create our new experiment */
- fExperiment = new TmfExperiment(CtfTmfEvent.class, "Headless", traces);
-
- /*
- * We will issue a request for each "pass". TMF will then process
- * them synchronously.
- */
- RequestBenchmark request = null;
- for (int x = 0; x < NB_OF_PASS; x++) {
- request = new RequestBenchmark(CtfTmfEvent.class,
- TmfTimeRange.ETERNITY, Integer.MAX_VALUE);
- fExperiment.sendRequest(request);
- }
- prev = System.nanoTime();
- } catch (final NullPointerException e) {
- /*
- * Silently dismiss Null pointer exception The only way to "finish"
- * the threads in TMF is by crashing them with null.
- */
- } catch (final Exception e) {
- e.printStackTrace();
- }
-
- }
-
- @Override
- public void handleData(final ITmfEvent event) {
- super.handleData(event);
- nbEvent++;
-
- }
-
- static long prev;
- static long done = 0;
- @Override
- public void handleCompleted() {
- final long next = System.nanoTime();
- double val = next - prev;
- final int nbEvent2 = nbEvent;
- val /= nbEvent2;
-
- nbEvent = 0;
- prev = next;
- benchs.add(val);
- if (benchs.size() == NB_OF_PASS) {
- try {
- System.out.println("Nb events : " + nbEvent2);
-
- for (final double value : benchs) {
- System.out.print(value + ", ");
- }
- fExperiment.sendRequest(null);
-
- } catch (final Exception e) {
- }
- }
- }
-
- @Override
- public void handleSuccess() {
- }
-
- @Override
- public void handleFailure() {
- }
-
- @Override
- public void handleCancel() {
- }
-
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.iterator;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ CtfIteratorTest.class
+})
+public class AllTests {
+
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial generation with CodePro tools
+ * Alexandre Montplaisir - Clean up, consolidate redundant tests
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.iterator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
+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.eclipse.tracecompass.tmf.ctf.core.trace.iterator.CtfIterator;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>CtfIteratorTest</code> contains tests for the class
+ * <code>{@link CtfIterator}</code>.
+ *
+ * @author ematkho
+ * @version 1.0
+ */
+public class CtfIteratorTest {
+
+ private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
+
+ private CtfTmfTrace trace;
+ private CtfIterator iterator;
+
+ /**
+ * Perform pre-test initialization.
+ * @throws CTFReaderException error
+ */
+ @Before
+ public void setUp() throws CTFReaderException {
+ assumeTrue(testTrace.exists());
+ trace = testTrace.getTrace();
+ iterator = new CtfIterator(trace);
+ CtfLocation ctfLocation = new CtfLocation(new CtfLocationInfo(1, 0));
+ iterator.setLocation(ctfLocation);
+ iterator.increaseRank();
+ }
+
+ /**
+ * Perform post-test clean-up.
+ */
+ @After
+ public void tearDown() {
+ if (trace != null) {
+ trace.dispose();
+ }
+ if (iterator != null) {
+ iterator.dispose();
+ }
+ }
+
+ /**
+ * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
+ * @throws CTFReaderException error
+ */
+ @Test
+ public void testCtfIterator_noinit() throws CTFReaderException {
+ try (CtfIterator result = new CtfIterator(trace);) {
+ assertNotNull(result);
+ }
+ }
+
+ /**
+ * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
+ * @throws CTFReaderException error
+ */
+ @Test
+ public void testCtfIterator_init() throws CTFReaderException {
+ trace.init("test");
+ try (CtfIterator result = new CtfIterator(trace);) {
+ assertNotNull(result);
+ }
+ }
+
+ /**
+ * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
+ * specifies an initial position for the iterator.
+ * @throws CTFReaderException error
+ */
+ @Test
+ public void testCtfIterator_position() throws CTFReaderException {
+ long timestampValue = 1L;
+ long rank = 1L;
+ try (CtfIterator result = new CtfIterator(trace, new CtfLocationInfo(timestampValue, 0), rank);) {
+ assertNotNull(result);
+ }
+ }
+
+
+ /**
+ * Run the boolean advance() method test.
+ */
+ @Test
+ public void testAdvance() {
+ boolean result = iterator.advance();
+ assertTrue(result);
+ }
+
+ /**
+ * Run the int compareTo(CtfIterator) method test.
+ * @throws CTFReaderException error
+ */
+ @Test
+ public void testCompareTo() throws CTFReaderException {
+ try (CtfIterator o = new CtfIterator(trace);) {
+ int result = iterator.compareTo(o);
+ assertEquals(1L, result);
+ }
+ }
+
+ /**
+ * Run the boolean equals(Object) method test. Compare with another iterator
+ * on the same trace.
+ * @throws CTFReaderException error
+ */
+ @Test
+ public void testEquals_other() throws CTFReaderException {
+ try (CtfIterator obj = new CtfIterator(trace);) {
+ CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
+ obj.setLocation(ctfLocation1);
+ obj.increaseRank();
+
+ boolean result = iterator.equals(obj);
+ assertTrue(result);
+ }
+ }
+
+ /**
+ * Run the boolean equals(Object) method test. Compare with an empty object.
+ */
+ @Test
+ public void testEquals_empty() {
+ Object obj = new Object();
+ boolean result = iterator.equals(obj);
+
+ assertFalse(result);
+ }
+
+ /**
+ * Run the CtfTmfTrace getCtfTmfTrace() method test.
+ */
+ @Test
+ public void testGetCtfTmfTrace() {
+ try (CtfTmfTrace result = iterator.getCtfTmfTrace();) {
+ assertNotNull(result);
+ }
+ }
+
+ /**
+ * Run the CtfTmfEvent getCurrentEvent() method test.
+ */
+ @Test
+ public void testGetCurrentEvent() {
+ CtfTmfEvent result = iterator.getCurrentEvent();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the CtfLocation getLocation() method test.
+ */
+ @Test
+ public void testGetLocation() {
+ CtfLocation result = iterator.getLocation();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the long getRank() method test.
+ */
+ @Test
+ public void testGetRank() {
+ long result = iterator.getRank();
+ assertEquals(1L, result);
+ }
+
+ /**
+ * Run the boolean hasValidRank() method test.
+ */
+ @Test
+ public void testHasValidRank() {
+ boolean result = iterator.hasValidRank();
+ assertTrue(result);
+ }
+
+ /**
+ * Run the int hashCode() method test.
+ */
+ @Test
+ public void testHashCode() {
+ int result = iterator.hashCode();
+ int result2 = iterator.hashCode();
+ assertEquals(result, result2);
+ }
+
+ /**
+ * Run the void increaseRank() method test.
+ */
+ @Test
+ public void testIncreaseRank() {
+ iterator.increaseRank();
+ }
+
+ /**
+ * Run the boolean seek(long) method test.
+ */
+ @Test
+ public void testSeek() {
+ long timestamp = 1L;
+ boolean result = iterator.seek(timestamp);
+ assertTrue(result);
+ }
+
+ /**
+ * Run the void setLocation(ITmfLocation<?>) method test.
+ */
+ @Test
+ public void testSetLocation() {
+ CtfLocation location = new CtfLocation(new CtfLocationInfo(1, 0));
+ iterator.setLocation(location);
+ }
+}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.request;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TmfSchedulerTest.class
-})
-public class AllTests {}
\ No newline at end of file
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Simon Delisle - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.request;
-
-import java.io.PrintWriter;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-
-/**
- * Benchmark for the request scheduler
- *
- * The benchmark has three tests. The first one is the latency (time between the
- * creation of the request and the beginning of its execution). The second one
- * is the average waiting time for a request. The last one is the total
- * completion time.
- */
-public class TmfSchedulerBenchmark {
-
- // ------------------------------------------------------------------------
- // Constants
- // ------------------------------------------------------------------------
-
- private static final int NUM_LOOPS = 10;
- private static final int NANOSECONDS_IN_MILLISECONDS = 1000000;
- private static final int NANOSECONDS_IN_SECONDS = 1000000000;
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- private static CtfTmfTrace trace = CtfTmfTestTrace.KERNEL.getTrace();
- private static ForegroundRequest lastForegroundRequest = null;
- private static BackgroundRequest lastBackgroundRequest = null;
-
- private static PrintWriter pw = new PrintWriter(System.out, true);
-
- /**
- * Start the benchmark
- *
- * @param args
- * The command-line arguments
- */
- public static void main(final String[] args) {
- trace.indexTrace(true);
- pw.println("---------- Benchmark started ----------");
- latencyBenchmark();
- averageWaitingTime();
- completedTime();
- benchmarkResults();
- trace.dispose();
- }
-
- private static void latencyBenchmark() {
- long averageLatency = 0;
-
- pw.println("----- Latency -----");
- for (int i = 0; i < NUM_LOOPS; i++) {
- try {
- ForegroundRequest foreground1 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- trace.sendRequest(foreground1);
- foreground1.waitForCompletion();
- averageLatency += foreground1.getLatency();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- pw.println((averageLatency / NUM_LOOPS) / NANOSECONDS_IN_MILLISECONDS + " ms");
- }
-
- private static void averageWaitingTime() {
- long averageWaitingBackground = 0;
- long averageWaitingForeground1 = 0;
- long averageWaitingForeground2 = 0;
-
- pw.println("----- Average waiting time with 3 requests -----");
- for (int i = 0; i < NUM_LOOPS; i++) {
- ForegroundRequest foreground1 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground2 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- BackgroundRequest background1 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- trace.sendRequest(background1);
- trace.sendRequest(foreground1);
- trace.sendRequest(foreground2);
- try {
- foreground1.waitForCompletion();
- foreground2.waitForCompletion();
- background1.waitForCompletion();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- averageWaitingBackground += background1.getAverageWaitingTime();
- averageWaitingForeground1 += foreground1.getAverageWaitingTime();
- averageWaitingForeground2 += foreground2.getAverageWaitingTime();
- }
- pw.print("-- Background : ");
- pw.println((averageWaitingBackground / NUM_LOOPS) / NANOSECONDS_IN_MILLISECONDS + " ms");
-
- pw.print("-- First foreground : ");
- pw.println((averageWaitingForeground1 / NUM_LOOPS) / NANOSECONDS_IN_MILLISECONDS + " ms");
-
- pw.print("-- Second foreground : ");
- pw.println((averageWaitingForeground2 / NUM_LOOPS) / NANOSECONDS_IN_MILLISECONDS + " ms");
- }
-
- private static void completedTime() {
- long averageCompletedTime1 = 0;
- long averageCompletedTime2 = 0;
- long averageCompletedTime3 = 0;
- long averageCompletedTime4 = 0;
- long averageCompletedTime5 = 0;
- long averageCompletedTime6 = 0;
-
- pw.println("----- Time to complete request -----");
- for (int i = 0; i < NUM_LOOPS; i++) {
- try {
- ForegroundRequest foreground1 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- trace.sendRequest(foreground1);
- foreground1.waitForCompletion();
- averageCompletedTime1 += foreground1.getCompletedTime();
-
- ForegroundRequest foreground2 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground3 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- trace.sendRequest(foreground2);
- trace.sendRequest(foreground3);
- foreground2.waitForCompletion();
- foreground3.waitForCompletion();
- averageCompletedTime2 += (foreground2.getCompletedTime() + foreground3.getCompletedTime());
-
- ForegroundRequest foreground4 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- BackgroundRequest background1 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- trace.sendRequest(foreground4);
- trace.sendRequest(background1);
- foreground4.waitForCompletion();
- background1.waitForCompletion();
- averageCompletedTime3 += (foreground4.getCompletedTime() + background1.getCompletedTime());
-
- ForegroundRequest foreground5 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground6 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- BackgroundRequest background2 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- trace.sendRequest(foreground5);
- trace.sendRequest(foreground6);
- trace.sendRequest(background2);
- foreground5.waitForCompletion();
- foreground6.waitForCompletion();
- background2.waitForCompletion();
- averageCompletedTime4 += (foreground5.getCompletedTime() + foreground6.getCompletedTime() + background2.getCompletedTime());
-
- ForegroundRequest foreground7 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground8 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground9 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- BackgroundRequest background3 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- trace.sendRequest(foreground7);
- trace.sendRequest(foreground8);
- trace.sendRequest(foreground9);
- trace.sendRequest(background3);
- foreground7.waitForCompletion();
- foreground8.waitForCompletion();
- foreground9.waitForCompletion();
- background3.waitForCompletion();
- averageCompletedTime5 += (foreground7.getCompletedTime() + foreground8.getCompletedTime() + foreground9.getCompletedTime() + background3.getCompletedTime());
-
- ForegroundRequest foreground10 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground11 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground12 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground13 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- BackgroundRequest background4 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- trace.sendRequest(foreground10);
- trace.sendRequest(foreground11);
- trace.sendRequest(foreground12);
- trace.sendRequest(foreground13);
- trace.sendRequest(background4);
- foreground10.waitForCompletion();
- foreground11.waitForCompletion();
- foreground12.waitForCompletion();
- foreground13.waitForCompletion();
- background4.waitForCompletion();
- averageCompletedTime6 += (foreground10.getCompletedTime() + foreground11.getCompletedTime() + foreground12.getCompletedTime() + foreground13.getCompletedTime() + background4.getCompletedTime());
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- pw.print("-- Time to complete one request : ");
- pw.println((averageCompletedTime1 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
-
- pw.print("-- Time to complete 2 requests (2 foreground) : ");
- pw.println((averageCompletedTime2 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
-
- pw.print("-- Time to complete 2 requests (1 foreground, 1 background) : ");
- pw.println((averageCompletedTime3 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
-
- pw.print("-- Time to complete 3 requests (2 foreground, 1 background) : ");
- pw.println((averageCompletedTime4 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
-
- pw.print("-- Time to complete 4 requests (3 foreground, 1 background) : ");
- pw.println((averageCompletedTime5 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
-
- pw.print("-- Time to complete 5 requests (4 foreground, 1 background) : ");
- pw.println((averageCompletedTime6 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
- }
-
- /**
- * The benchmark results
- */
- public static void benchmarkResults() {
- pw.println("---------- Benchmark completed ----------");
- }
-
- // ------------------------------------------------------------------------
- // Helper methods
- // ------------------------------------------------------------------------
-
- private static class BackgroundRequest extends TmfEventRequest {
- private long startTime;
- private long endTimeLatency = -1;
- private long completedTime = 0;
- private long waitingTimeStart = 0;
- private long waitingTimeEnd = 0;
- private long waitingTime = 0;
- private int waitingCounter = 0;
- private boolean isWaiting = false;
-
- BackgroundRequest(TmfTimeRange timeRange) {
- super(trace.getEventType(),
- timeRange,
- 0,
- ITmfEventRequest.ALL_DATA,
- ExecutionType.BACKGROUND);
- startTime = System.nanoTime();
- }
-
- @Override
- public void handleData(final ITmfEvent event) {
- if (endTimeLatency == -1) {
- endTimeLatency = System.nanoTime();
- }
- super.handleData(event);
- if (lastForegroundRequest == null && lastBackgroundRequest == null) {
- lastBackgroundRequest = this;
- }
- if (isWaiting) {
- waitingTimeEnd = System.nanoTime();
- waitingTime += waitingTimeEnd - waitingTimeStart;
- ++waitingCounter;
- isWaiting = false;
- }
- if (lastForegroundRequest != null) {
- lastForegroundRequest.waitingTimeStart = System.nanoTime();
- lastForegroundRequest.isWaiting = true;
- lastForegroundRequest = null;
- lastBackgroundRequest = this;
- }
- if (lastBackgroundRequest != this) {
- lastBackgroundRequest.waitingTimeStart = System.nanoTime();
- lastBackgroundRequest.isWaiting = true;
- lastBackgroundRequest = this;
- }
- }
-
- @Override
- public void handleCompleted() {
- completedTime = System.nanoTime();
- super.handleCompleted();
- }
-
- public long getCompletedTime() {
- return completedTime - startTime;
- }
-
- public long getAverageWaitingTime() {
- if (waitingCounter == 0) {
- return 0;
- }
- return waitingTime / waitingCounter;
- }
- }
-
- private static class ForegroundRequest extends TmfEventRequest {
- private long startTime = 0;
- private long endTimeLatency = -1;
- private long completedTime = 0;
- private long waitingTimeStart = 0;
- private long waitingTimeEnd = 0;
- private long waitingTime = 0;
- private int waitingCounter = 0;
- private boolean isWaiting = false;
-
- ForegroundRequest(TmfTimeRange timeRange) {
- super(trace.getEventType(),
- timeRange,
- 0,
- ITmfEventRequest.ALL_DATA,
- ExecutionType.FOREGROUND);
- startTime = System.nanoTime();
- }
-
- @Override
- public void handleData(final ITmfEvent event) {
- if (endTimeLatency == -1) {
- endTimeLatency = System.nanoTime();
- }
- super.handleData(event);
- if (lastBackgroundRequest == null && lastForegroundRequest == null) {
- lastForegroundRequest = this;
- }
- if (isWaiting) {
- waitingTimeEnd = System.nanoTime();
- waitingTime += waitingTimeEnd - waitingTimeStart;
- ++waitingCounter;
- isWaiting = false;
- }
- if (lastBackgroundRequest != null) {
- lastBackgroundRequest.waitingTimeStart = System.nanoTime();
- lastBackgroundRequest.isWaiting = true;
- lastBackgroundRequest = null;
- lastForegroundRequest = this;
- }
- if (lastForegroundRequest != this) {
- lastForegroundRequest.waitingTimeStart = System.nanoTime();
- lastForegroundRequest.isWaiting = true;
- lastForegroundRequest = this;
- }
- }
-
- @Override
- public void handleCompleted() {
- completedTime = System.nanoTime();
- super.handleCompleted();
- }
-
- public long getLatency() {
- return endTimeLatency - startTime;
- }
-
- public long getCompletedTime() {
- return completedTime - startTime;
- }
-
- public long getAverageWaitingTime() {
- if (waitingCounter == 0) {
- return 0;
- }
- return waitingTime / waitingCounter;
- }
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Simon Delisle - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.request;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestRule;
-import org.junit.rules.Timeout;
-
-/**
- * Test suite for the scheduler.
- */
-public class TmfSchedulerTest {
-
- /** Time-out tests after 60 seconds */
- @Rule
- public TestRule globalTimeout= new Timeout(60000);
-
- // ------------------------------------------------------------------------
- // Constants
- // ------------------------------------------------------------------------
-
- private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
- private static final int NB_EVENTS_TRACE = 695319;
- private static final int NB_EVENTS_TIME_RANGE = 155133;
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- private CtfTmfTrace fixture;
-
- private long fStartTime;
- private long fEndTime;
- private TmfTimeRange fForegroundTimeRange;
-
- private final List<String> fOrderList = new ArrayList<>();
- private int fForegroundId = 0;
- private int fBackgroundId = 0;
-
- /**
- * Perform pre-test initialization.
- *
- * @throws TmfTraceException
- * If the test trace is not found
- */
- @Before
- public void setUp() throws TmfTraceException {
- assumeTrue(testTrace.exists());
- fixture = new CtfTmfTrace();
- fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
- fixture.indexTrace(true);
- fStartTime = fixture.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
- fEndTime = fixture.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
-
- long foregroundStartTime = fStartTime + ((fEndTime - fStartTime) / 4);
- long foregroundEndTime = fStartTime + ((fEndTime - fStartTime) / 2);
- fForegroundTimeRange = new TmfTimeRange(new TmfTimestamp(foregroundStartTime, ITmfTimestamp.NANOSECOND_SCALE),
- new TmfTimestamp(foregroundEndTime, ITmfTimestamp.NANOSECOND_SCALE));
- }
-
- /**
- * Perform post-test clean-up.
- */
- @After
- public void tearDown() {
- if (fixture != null) {
- fixture.dispose();
- }
- }
-
- // ------------------------------------------------------------------------
- // Tests cases
- // ------------------------------------------------------------------------
-
- /**
- * Test one background request
- */
- @Test
- public void backgroundRequest() {
- BackgroundRequest background = new BackgroundRequest(TmfTimeRange.ETERNITY);
- fixture.sendRequest(background);
- try {
- background.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
- assertEquals(NB_EVENTS_TRACE, background.getNbEvents());
- }
-
- /**
- * Test one foreground request
- */
- @Test
- public void foregroundRequest() {
- ForegroundRequest foreground = new ForegroundRequest(TmfTimeRange.ETERNITY);
- fixture.sendRequest(foreground);
- try {
- foreground.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
- assertEquals(NB_EVENTS_TRACE, foreground.getNbEvents());
- }
-
- /**
- * Test one foreground and one background request for the entire trace at
- * the same time
- */
- @Test
- public void TestMultiRequest1() {
- BackgroundRequest background = new BackgroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground = new ForegroundRequest(TmfTimeRange.ETERNITY);
-
- fixture.sendRequest(background);
- fixture.sendRequest(foreground);
- try {
- background.waitForCompletion();
- foreground.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
-
- assertEquals(NB_EVENTS_TRACE, background.getNbEvents());
- assertEquals(NB_EVENTS_TRACE, foreground.getNbEvents());
- }
-
- /**
- * Test one background request for the entire trace and one foreground
- * request for smaller time range
- */
- @Test
- public void TestMultiRequest2() {
- BackgroundRequest background2 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground2 = new ForegroundRequest(fForegroundTimeRange);
-
- fixture.sendRequest(background2);
- fixture.sendRequest(foreground2);
- try {
- background2.waitForCompletion();
- foreground2.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
-
- assertEquals(NB_EVENTS_TRACE, background2.getNbEvents());
- assertEquals(NB_EVENTS_TIME_RANGE, foreground2.getNbEvents());
- }
-
- /**
- * Test two foreground request, one to select a time range and one to select
- * an event in this time range
- */
- @Test
- public void TestMultiRequest3() {
- ForegroundRequest foreground3 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- fixture.sendRequest(foreground3);
-
- TmfTimeSynchSignal signal3 = new TmfTimeSynchSignal(this, new TmfTimestamp(fForegroundTimeRange.getStartTime()));
- fixture.broadcast(signal3);
-
- try {
- foreground3.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
-
- assertEquals(NB_EVENTS_TRACE, foreground3.getNbEvents());
- }
-
- /**
- * Test two foreground request, one to select a time range and one to select
- * an event before this time range
- */
- @Test
- public void TestMultiRequest4() {
- ForegroundRequest foreground4 = new ForegroundRequest(fForegroundTimeRange);
- fixture.sendRequest(foreground4);
- TmfTimeSynchSignal signal4 = new TmfTimeSynchSignal(this, new TmfTimestamp(fStartTime + ((fEndTime - fStartTime) / 8)));
- fixture.broadcast(signal4);
-
- try {
- foreground4.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
-
- assertEquals(NB_EVENTS_TIME_RANGE, foreground4.getNbEvents());
- }
-
- /**
- * Test two foreground request, one to select a time range and one to select
- * an event after this time range
- */
- @Test
- public void TestMultiRequest5() {
- ForegroundRequest foreground5 = new ForegroundRequest(fForegroundTimeRange);
- fixture.sendRequest(foreground5);
- TmfTimeSynchSignal signal5 = new TmfTimeSynchSignal(this, new TmfTimestamp(fEndTime - ((fEndTime - fStartTime) / 4)));
- fixture.broadcast(signal5);
-
- try {
- foreground5.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
-
- assertEquals(NB_EVENTS_TIME_RANGE, foreground5.getNbEvents());
- }
-
- /**
- * Test one background and one foreground request for the entire trace and
- * one foreground request to select an event
- */
- @Test
- public void TestMultiRequest6() {
- BackgroundRequest background6 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground6 = new ForegroundRequest(TmfTimeRange.ETERNITY);
-
- fixture.sendRequest(background6);
- fixture.sendRequest(foreground6);
-
- TmfTimeSynchSignal signal6 = new TmfTimeSynchSignal(this, new TmfTimestamp(fStartTime + ((fEndTime - fStartTime) / 8)));
- fixture.broadcast(signal6);
-
- try {
- background6.waitForCompletion();
- foreground6.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
-
- assertEquals(NB_EVENTS_TRACE, background6.getNbEvents());
- assertEquals(NB_EVENTS_TRACE, foreground6.getNbEvents());
- }
-
- /**
- * Four request, two foreground and two background
- */
- @Test
- public void TestMultiRequest7() {
- ForegroundRequest foreground7 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground8 = new ForegroundRequest(fForegroundTimeRange);
- BackgroundRequest background7 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- BackgroundRequest background8 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- fixture.sendRequest(foreground7);
- fixture.sendRequest(foreground8);
- fixture.sendRequest(background7);
- fixture.sendRequest(background8);
- try {
- foreground7.waitForCompletion();
- foreground8.waitForCompletion();
- background7.waitForCompletion();
- background8.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
- assertEquals(NB_EVENTS_TRACE, foreground7.getNbEvents());
- assertEquals(NB_EVENTS_TIME_RANGE, foreground8.getNbEvents());
- assertEquals(NB_EVENTS_TRACE, background7.getNbEvents());
- assertEquals(NB_EVENTS_TRACE, background8.getNbEvents());
- }
-
- /**
- * One long foreground request and one short foreground request, the short
- * one should finish first
- */
- @Test
- public void preemptedForegroundRequest() {
- ForegroundRequest foreground9 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- TmfTimeRange shortTimeRange = new TmfTimeRange(new TmfTimestamp(fStartTime, ITmfTimestamp.NANOSECOND_SCALE),
- new TmfTimestamp(fStartTime + ((fEndTime - fStartTime) / 16), ITmfTimestamp.NANOSECOND_SCALE));
- ForegroundRequest shortForeground = new ForegroundRequest(shortTimeRange);
- fixture.sendRequest(foreground9);
- try {
- foreground9.waitForStart();
- } catch (InterruptedException e) {
- fail();
- }
- fixture.sendRequest(shortForeground);
- try {
- shortForeground.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
- assertFalse(foreground9.isCompleted());
- }
-
- /**
- * One long background request and one short foreground request, the
- * foreground request should finish first
- */
- @Test
- public void preemptedBackgroundRequest() {
- BackgroundRequest background9 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground10 = new ForegroundRequest(fForegroundTimeRange);
- fixture.sendRequest(background9);
- fixture.sendRequest(foreground10);
- try {
- foreground10.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
- assertTrue(foreground10.isCompleted());
- assertFalse(background9.isCompleted());
- }
-
- /**
- * Test if the scheduler is working as expected
- */
- @Ignore
- @Test
- public void executionOrder() {
- List<String> expectedOrder = new LinkedList<>();
- expectedOrder.add("FOREGROUND1");
- expectedOrder.add("FOREGROUND2");
- expectedOrder.add("FOREGROUND3");
- expectedOrder.add("FOREGROUND4");
- expectedOrder.add("BACKGROUND1");
- expectedOrder.add("FOREGROUND1");
- expectedOrder.add("FOREGROUND2");
- expectedOrder.add("FOREGROUND3");
- expectedOrder.add("FOREGROUND4");
- expectedOrder.add("BACKGROUND2");
-
- fOrderList.clear();
- fForegroundId = 0;
- fBackgroundId = 0;
-
- BackgroundRequest background1 = new BackgroundRequest(TmfTimeRange.ETERNITY);
- BackgroundRequest background2 = new BackgroundRequest(TmfTimeRange.ETERNITY);
-
- ForegroundRequest foreground1 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground2 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground3 = new ForegroundRequest(TmfTimeRange.ETERNITY);
- ForegroundRequest foreground4 = new ForegroundRequest(TmfTimeRange.ETERNITY);
-
- fixture.sendRequest(foreground1);
- fixture.sendRequest(foreground2);
- fixture.sendRequest(foreground3);
- fixture.sendRequest(foreground4);
- fixture.sendRequest(background1);
- fixture.sendRequest(background2);
- try {
- foreground1.waitForCompletion();
- foreground2.waitForCompletion();
- foreground3.waitForCompletion();
- foreground4.waitForCompletion();
- background1.waitForCompletion();
- background2.waitForCompletion();
- } catch (InterruptedException e) {
- fail();
- }
- assertEquals(expectedOrder, fOrderList.subList(0, expectedOrder.size()));
- }
-
- // ------------------------------------------------------------------------
- // Helper methods
- // ------------------------------------------------------------------------
-
- private class BackgroundRequest extends TmfEventRequest {
- private int nbEvents = 0;
- private String backgroundName;
-
- BackgroundRequest(TmfTimeRange timeRange) {
- super(fixture.getEventType(),
- timeRange,
- 0,
- ITmfEventRequest.ALL_DATA,
- ExecutionType.BACKGROUND);
- backgroundName = getExecType().toString() + ++fBackgroundId;
- }
-
- @Override
- public void handleData(final ITmfEvent event) {
- super.handleData(event);
- synchronized (fOrderList) {
- if (fOrderList.isEmpty() || !fOrderList.get(fOrderList.size() - 1).equals(backgroundName)) {
- fOrderList.add(backgroundName);
- }
- }
- ++nbEvents;
- }
-
- public int getNbEvents() {
- return nbEvents;
- }
- }
-
- private class ForegroundRequest extends TmfEventRequest {
- private int nbEvents = 0;
- private String foregroundName;
-
- ForegroundRequest(TmfTimeRange timeRange) {
- super(fixture.getEventType(),
- timeRange,
- 0,
- ITmfEventRequest.ALL_DATA,
- ExecutionType.FOREGROUND);
- foregroundName = getExecType().toString() + ++fForegroundId;
- }
-
- @Override
- public void handleData(final ITmfEvent event) {
- super.handleData(event);
- synchronized (fOrderList) {
- if (fOrderList.isEmpty() || !fOrderList.get(fOrderList.size() - 1).equals(foregroundName)) {
- fOrderList.add(foregroundName);
- }
- }
- ++nbEvents;
- }
-
- public int getNbEvents() {
- return nbEvents;
- }
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.statistics;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TmfEventsStatisticsTest.class,
- TmfStateStatisticsTest.class
-})
-public class AllTests {}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.statistics;
-
-import static org.junit.Assume.assumeTrue;
-
-import org.eclipse.tracecompass.tmf.core.statistics.TmfEventsStatistics;
-import org.junit.BeforeClass;
-
-/**
- * Unit tests for the {@link TmfEventsStatistics}
- *
- * @author Alexandre Montplaisir
- */
-public class TmfEventsStatisticsTest extends TmfStatisticsTest {
-
- /**
- * Set up the fixture once for all tests.
- */
- @BeforeClass
- public static void setUpClass() {
- assumeTrue(testTrace.exists());
- backend = new TmfEventsStatistics(testTrace.getTrace());
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.statistics;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
-
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
-import org.eclipse.tracecompass.tmf.core.statistics.TmfStateStatistics;
-import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsEventTypesModule;
-import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsTotalsModule;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-
-/**
- * Unit tests for the {@link TmfStateStatistics}
- *
- * @author Alexandre Montplaisir
- */
-public class TmfStateStatisticsTest extends TmfStatisticsTest {
-
- private ITmfTrace fTrace;
-
- private TmfStatisticsTotalsModule fTotalsMod;
- private TmfStatisticsEventTypesModule fEventTypesMod;
-
- /**
- * Class setup
- */
- @BeforeClass
- public static void setUpClass() {
- assumeTrue(testTrace.exists());
- }
-
- /**
- * Test setup
- */
- @Before
- public void setUp() {
- fTrace = testTrace.getTrace();
-
- /* Prepare the two analysis-backed state systems */
- fTotalsMod = new TmfStatisticsTotalsModule();
- fEventTypesMod = new TmfStatisticsEventTypesModule();
- try {
- fTotalsMod.setTrace(fTrace);
- fEventTypesMod.setTrace(fTrace);
- } catch (TmfAnalysisException e) {
- fail();
- }
-
- fTotalsMod.schedule();
- fEventTypesMod.schedule();
- assertTrue(fTotalsMod.waitForCompletion());
- assertTrue(fEventTypesMod.waitForCompletion());
-
- ITmfStateSystem totalsSS = fTotalsMod.getStateSystem();
- ITmfStateSystem eventTypesSS = fEventTypesMod.getStateSystem();
- assertNotNull(totalsSS);
- assertNotNull(eventTypesSS);
-
- backend = new TmfStateStatistics(totalsSS, eventTypesSS);
- }
-
- /**
- * Test cleanup
- */
- @After
- public void tearDown() {
- fTotalsMod.dispose();
- fEventTypesMod.dispose();
- fTrace.dispose();
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.statistics;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestRule;
-import org.junit.rules.Timeout;
-
-/**
- * Base unit test class for any type of ITmfStatistics. Sub-classes should
- * implement a "@BeforeClass" method to setup the 'backend' fixture accordingly.
- *
- * @author Alexandre Montplaisir
- */
-public abstract class TmfStatisticsTest {
-
- /** Time-out tests after 30 seconds */
- @Rule public TestRule globalTimeout= new Timeout(30000);
-
- /** Test trace used for these tests */
- protected static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
-
- /** The statistics back-end object */
- protected static ITmfStatistics backend;
-
- /* Known values about the trace */
- private static final int totalNbEvents = 695319;
- private static final long tStart = 1332170682440133097L; /* Timestamp of first event */
- private static final long tEnd = 1332170692664579801L; /* Timestamp of last event */
-
- /* Timestamps of interest */
- private static final long t1 = 1332170682490946000L;
- private static final long t2 = 1332170682490947524L; /* event exactly here */
- private static final long t3 = 1332170682490948000L;
- private static final long t4 = 1332170682490949000L;
- private static final long t5 = 1332170682490949270L; /* following event here */
- private static final long t6 = 1332170682490949300L;
-
- private static final String eventType = "lttng_statedump_process_state";
-
-
- // ------------------------------------------------------------------------
- // Tests for histogramQuery()
- // ------------------------------------------------------------------------
-
- /**
- * Test the {@link ITmfStatistics#histogramQuery} method for the small known
- * interval.
- */
- @Test
- public void testHistogramQuerySmall() {
- final int NB_REQ = 10;
- List<Long> results = backend.histogramQuery(t1, t6, NB_REQ);
-
- /* Make sure the returned array has the right size */
- assertEquals(NB_REQ, results.size());
-
- /* Check the contents of each "bucket" */
- assertEquals(0, results.get(0).longValue());
- assertEquals(0, results.get(1).longValue());
- assertEquals(0, results.get(2).longValue());
- assertEquals(0, results.get(3).longValue());
- assertEquals(1, results.get(4).longValue());
- assertEquals(0, results.get(5).longValue());
- assertEquals(0, results.get(6).longValue());
- assertEquals(0, results.get(7).longValue());
- assertEquals(0, results.get(8).longValue());
- assertEquals(1, results.get(9).longValue());
-
- }
-
- /**
- * Test the {@link ITmfStatistics#histogramQuery} method over the whole
- * trace.
- */
- @Test
- public void testHistogramQueryFull() {
- final int NB_REQ = 10;
- List<Long> results = backend.histogramQuery(tStart, tEnd, NB_REQ);
-
- /* Make sure the returned array has the right size */
- assertEquals(NB_REQ, results.size());
-
- /* Check the total number of events */
- long count = 0;
- for (long val : results) {
- count += val;
- }
- assertEquals(totalNbEvents, count);
-
- /* Check the contents of each "bucket" */
- assertEquals(94161, results.get(0).longValue());
- assertEquals(87348, results.get(1).longValue());
- assertEquals(58941, results.get(2).longValue());
- assertEquals(59879, results.get(3).longValue());
- assertEquals(66941, results.get(4).longValue());
- assertEquals(68939, results.get(5).longValue());
- assertEquals(72746, results.get(6).longValue());
- assertEquals(60749, results.get(7).longValue());
- assertEquals(61208, results.get(8).longValue());
- assertEquals(64407, results.get(9).longValue());
- }
-
- // ------------------------------------------------------------------------
- // Test for getEventsTotal()
- // ------------------------------------------------------------------------
-
- /**
- * Basic test for {@link ITmfStatistics#getEventsTotal}
- */
- @Test
- public void testGetEventsTotal() {
- long count = backend.getEventsTotal();
- assertEquals(totalNbEvents, count);
- }
-
- // ------------------------------------------------------------------------
- // Test for getEventTypesTotal()
- // ------------------------------------------------------------------------
-
- /**
- * Basic test for {@link ITmfStatistics#getEventTypesTotal}
- */
- @Test
- public void testEventTypesTotal() {
- Map<String, Long> res = backend.getEventTypesTotal();
- assertEquals(126, res.size()); /* Number of different event types in the trace */
-
- long count = sumOfEvents(res);
- assertEquals(totalNbEvents, count);
- }
-
- // ------------------------------------------------------------------------
- // Tests for getEventsInRange(ITmfTimestamp start, ITmfTimestamp end)
- // ------------------------------------------------------------------------
-
- /**
- * Test for {@link ITmfStatistics#getEventsInRange} over the whole trace.
- */
- @Test
- public void testGetEventsInRangeWholeRange() {
- long count = backend.getEventsInRange(tStart, tEnd);
- assertEquals(totalNbEvents, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventsInRange} for the whole range,
- * except the start time (there is only one event at the start time).
- */
- @Test
- public void testGetEventsInRangeMinusStart() {
- long count = backend.getEventsInRange(tStart + 1, tEnd);
- assertEquals(totalNbEvents - 1, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventsInRange} for the whole range,
- * except the end time (there is only one event at the end time).
- */
- @Test
- public void testGetEventsInRangeMinusEnd() {
- long count = backend.getEventsInRange(tStart, tEnd - 1);
- assertEquals(totalNbEvents - 1, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventsInRange} when both the start and
- * end times don't match an event.
- */
- @Test
- public void testGetEventsInRangeNoEventsAtEdges() {
- long count = backend.getEventsInRange(t1, t6);
- assertEquals(2, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventsInRange} when the *start* of the
- * interval is exactly on an event (that event should be included).
- */
- @Test
- public void testGetEventsInRangeEventAtStart() {
- long count = backend.getEventsInRange(t2, t3);
- assertEquals(1, count);
-
- count = backend.getEventsInRange(t2, t6);
- assertEquals(2, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventsInRange} when the *end* of the
- * interval is exactly on an event (that event should be included).
- */
- @Test
- public void testGetEventsInRangeEventAtEnd() {
- long count = backend.getEventsInRange(t4, t5);
- assertEquals(1, count);
-
- count = backend.getEventsInRange(t1, t5);
- assertEquals(2, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventsInRange} when there are events
- * matching exactly both the start and end times of the range (both should
- * be included).
- */
- @Test
- public void testGetEventsInRangeEventAtBoth() {
- long count = backend.getEventsInRange(t2, t5);
- assertEquals(2, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventsInRange} when there are no events
- * in a given range.
- */
- @Test
- public void testGetEventsInRangeNoEvents() {
- long count = backend.getEventsInRange(t3, t4);
- assertEquals(0, count);
- }
-
- // ------------------------------------------------------------------------
- // Tests for getEventTypesInRange(ITmfTimestamp start, ITmfTimestamp end)
- // ------------------------------------------------------------------------
-
- /**
- * Test for {@link ITmfStatistics#getEventTypesInRange} over the whole trace.
- */
- @Test
- public void testGetEventTypesInRangeWholeRange() {
- Map<String, Long> result = backend.getEventTypesInRange(tStart, tEnd);
- /* Number of events of that type in the whole trace */
- assertEquals(new Long(464L), result.get(eventType));
-
- long count = sumOfEvents(result);
- assertEquals(totalNbEvents, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventTypesInRange} for the whole range,
- * except the start time (there is only one event at the start time).
- */
- @Test
- public void testGetEventTypesInRangeMinusStart() {
- Map<String, Long> result = backend.getEventTypesInRange(tStart + 1, tEnd);
-
- long count = sumOfEvents(result);
- assertEquals(totalNbEvents - 1, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventTypesInRange} for the whole range,
- * except the end time (there is only one event at the end time).
- */
- @Test
- public void testGetEventTypesInRangeMinusEnd() {
- Map<String, Long> result = backend.getEventTypesInRange(tStart, tEnd - 1);
-
- long count = sumOfEvents(result);
- assertEquals(totalNbEvents - 1, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventTypesInRange} when both the start
- * and end times don't match an event.
- */
- @Test
- public void testGetEventTypesInRangeNoEventsAtEdges() {
- Map<String, Long> result = backend.getEventTypesInRange(t1, t6);
- assertEquals(new Long(2L), result.get(eventType));
-
- long count = sumOfEvents(result);
- assertEquals(2, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventTypesInRange} when the *start* of
- * the interval is exactly on an event (that event should be included).
- */
- @Test
- public void testGetEventTypesInRangeEventAtStart() {
- Map<String, Long> result = backend.getEventTypesInRange(t2, t3);
- assertEquals(new Long(1L), result.get(eventType));
- long count = sumOfEvents(result);
- assertEquals(1, count);
-
- result = backend.getEventTypesInRange(t2, t6);
- assertEquals(new Long(2L), result.get(eventType));
- count = sumOfEvents(result);
- assertEquals(2, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventTypesInRange} when the *end* of
- * the interval is exactly on an event (that event should be included).
- */
- @Test
- public void testGetEventTypesInRangeEventAtEnd() {
- Map<String, Long> result = backend.getEventTypesInRange(t4, t5);
- assertEquals(new Long(1L), result.get(eventType));
- long count = sumOfEvents(result);
- assertEquals(1, count);
-
- result = backend.getEventTypesInRange(t1, t5);
- assertEquals(new Long(2L), result.get(eventType));
- count = sumOfEvents(result);
- assertEquals(2, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventTypesInRange} when there are
- * events matching exactly both the start and end times of the range (both
- * should be included).
- */
- @Test
- public void testGetEventTypesInRangeEventAtBoth() {
- Map<String, Long> result = backend.getEventTypesInRange(t2, t5);
- assertEquals(new Long(2L), result.get(eventType));
- long count = sumOfEvents(result);
- assertEquals(2, count);
- }
-
- /**
- * Test for {@link ITmfStatistics#getEventTypesInRange} when there are no
- * events in a given range.
- */
- @Test
- public void testGetEventTypesInRangeNoEvents() {
- Map<String, Long> result = backend.getEventTypesInRange(t3, t4);
- long count = sumOfEvents(result);
- assertEquals(0, count);
- }
-
- // ------------------------------------------------------------------------
- // Convenience methods
- // ------------------------------------------------------------------------
-
- private static long sumOfEvents(Map<String, Long> map) {
- long count = 0;
- for (long val : map.values()) {
- count += val;
- }
- return count;
- }
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.headless;
+
+import java.util.Vector;
+
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * Test and benchmark reading a CTF LTTng kernel trace.
+ *
+ * @author Matthew Khouzam
+ */
+public class Benchmark {
+
+ /**
+ * Run the benchmark.
+ *
+ * @param args The command-line arguments
+ */
+ public static void main(final String[] args) {
+ final String TRACE_PATH = "testfiles/kernel";
+ final int NUM_LOOPS = 100;
+
+ // Change this to enable text output
+ final boolean USE_TEXT = true;
+
+ // Work variables
+ long nbEvent = 0L;
+ final Vector<Double> benchs = new Vector<>();
+ long start, stop;
+ for (int loops = 0; loops < NUM_LOOPS; loops++) {
+ nbEvent = 0L;
+ try (CtfTmfTrace trace = new CtfTmfTrace();) {
+ try {
+ trace.initTrace(null, TRACE_PATH, CtfTmfEvent.class);
+ } catch (final TmfTraceException e) {
+ loops = NUM_LOOPS + 1;
+ break;
+ }
+
+ start = System.nanoTime();
+ if (nbEvent != -1) {
+ final CtfTmfContext traceReader = (CtfTmfContext) trace.seekEvent(0);
+
+ start = System.nanoTime();
+ CtfTmfEvent current = traceReader.getCurrentEvent();
+ while (current != null) {
+ nbEvent++;
+ if (USE_TEXT) {
+
+ System.out.println("Event " + nbEvent + " Time "
+ + current.getTimestamp().toString() + " type " + current.getType().getName()
+ + " on CPU " + current.getSource() + " " + current.getContent().toString());
+ }
+ // advance the trace to the next event.
+ boolean hasMore = traceReader.advance();
+ if (hasMore) {
+ // you can know the trace has more events.
+ }
+ current = traceReader.getCurrentEvent();
+ }
+ }
+ stop = System.nanoTime();
+ System.out.print('.');
+ final double time = (stop - start) / (double) nbEvent;
+ benchs.add(time);
+ } // trace.close()
+ }
+ System.out.println("");
+ double avg = 0;
+ for (final double val : benchs) {
+ avg += val;
+ }
+ avg /= benchs.size();
+ System.out.println("Time to read = " + avg + " events/ns");
+ for (final Double val : benchs) {
+ System.out.print(val);
+ System.out.print(", ");
+ }
+
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * William Bourque <wbourque@gmail.com> - Initial API and implementation
+ * Matthew Khouzam - Update to CtfTmf trace and events
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.headless;
+
+import java.util.Vector;
+
+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.TmfExperiment;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * Benchmark the event request subsystem of TMF.
+ */
+public class RequestBenchmark extends TmfEventRequest {
+
+ private RequestBenchmark(final Class<? extends ITmfEvent> dataType,
+ final TmfTimeRange range, final int nbRequested) {
+ super(dataType, range, 0, nbRequested, ExecutionType.FOREGROUND);
+ }
+
+ // Path of the trace
+ private static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel";
+
+ // Change this to run several time over the same trace
+ private static final int NB_OF_PASS = 100;
+
+ // Work variables
+ private static int nbEvent = 0;
+ private static TmfExperiment fExperiment = null;
+ private static Vector<Double> benchs = new Vector<>();
+
+ /**
+ * Run the benchmark
+ *
+ * @param args
+ * The command-line arguments
+ */
+ public static void main(final String[] args) {
+
+ try {
+ /* Our experiment will contains ONE trace */
+ final ITmfTrace[] traces = new ITmfTrace[1];
+ traces[0] = new CtfTmfTrace();
+ traces[0].initTrace(null, TRACE_PATH, CtfTmfEvent.class);
+ /* Create our new experiment */
+ fExperiment = new TmfExperiment(CtfTmfEvent.class, "Headless", traces);
+
+ /*
+ * We will issue a request for each "pass". TMF will then process
+ * them synchronously.
+ */
+ RequestBenchmark request = null;
+ for (int x = 0; x < NB_OF_PASS; x++) {
+ request = new RequestBenchmark(CtfTmfEvent.class,
+ TmfTimeRange.ETERNITY, Integer.MAX_VALUE);
+ fExperiment.sendRequest(request);
+ }
+ prev = System.nanoTime();
+ } catch (final NullPointerException e) {
+ /*
+ * Silently dismiss Null pointer exception The only way to "finish"
+ * the threads in TMF is by crashing them with null.
+ */
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ public void handleData(final ITmfEvent event) {
+ super.handleData(event);
+ nbEvent++;
+
+ }
+
+ static long prev;
+ static long done = 0;
+ @Override
+ public void handleCompleted() {
+ final long next = System.nanoTime();
+ double val = next - prev;
+ final int nbEvent2 = nbEvent;
+ val /= nbEvent2;
+
+ nbEvent = 0;
+ prev = next;
+ benchs.add(val);
+ if (benchs.size() == NB_OF_PASS) {
+ try {
+ System.out.println("Nb events : " + nbEvent2);
+
+ for (final double value : benchs) {
+ System.out.print(value + ", ");
+ }
+ fExperiment.sendRequest(null);
+
+ } catch (final Exception e) {
+ }
+ }
+ }
+
+ @Override
+ public void handleSuccess() {
+ }
+
+ @Override
+ public void handleFailure() {
+ }
+
+ @Override
+ public void handleCancel() {
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.request;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TmfSchedulerTest.class
+})
+public class AllTests {}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon Delisle - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.request;
+
+import java.io.PrintWriter;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * Benchmark for the request scheduler
+ *
+ * The benchmark has three tests. The first one is the latency (time between the
+ * creation of the request and the beginning of its execution). The second one
+ * is the average waiting time for a request. The last one is the total
+ * completion time.
+ */
+public class TmfSchedulerBenchmark {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ private static final int NUM_LOOPS = 10;
+ private static final int NANOSECONDS_IN_MILLISECONDS = 1000000;
+ private static final int NANOSECONDS_IN_SECONDS = 1000000000;
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private static CtfTmfTrace trace = CtfTmfTestTrace.KERNEL.getTrace();
+ private static ForegroundRequest lastForegroundRequest = null;
+ private static BackgroundRequest lastBackgroundRequest = null;
+
+ private static PrintWriter pw = new PrintWriter(System.out, true);
+
+ /**
+ * Start the benchmark
+ *
+ * @param args
+ * The command-line arguments
+ */
+ public static void main(final String[] args) {
+ trace.indexTrace(true);
+ pw.println("---------- Benchmark started ----------");
+ latencyBenchmark();
+ averageWaitingTime();
+ completedTime();
+ benchmarkResults();
+ trace.dispose();
+ }
+
+ private static void latencyBenchmark() {
+ long averageLatency = 0;
+
+ pw.println("----- Latency -----");
+ for (int i = 0; i < NUM_LOOPS; i++) {
+ try {
+ ForegroundRequest foreground1 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ trace.sendRequest(foreground1);
+ foreground1.waitForCompletion();
+ averageLatency += foreground1.getLatency();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ pw.println((averageLatency / NUM_LOOPS) / NANOSECONDS_IN_MILLISECONDS + " ms");
+ }
+
+ private static void averageWaitingTime() {
+ long averageWaitingBackground = 0;
+ long averageWaitingForeground1 = 0;
+ long averageWaitingForeground2 = 0;
+
+ pw.println("----- Average waiting time with 3 requests -----");
+ for (int i = 0; i < NUM_LOOPS; i++) {
+ ForegroundRequest foreground1 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground2 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ BackgroundRequest background1 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ trace.sendRequest(background1);
+ trace.sendRequest(foreground1);
+ trace.sendRequest(foreground2);
+ try {
+ foreground1.waitForCompletion();
+ foreground2.waitForCompletion();
+ background1.waitForCompletion();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ averageWaitingBackground += background1.getAverageWaitingTime();
+ averageWaitingForeground1 += foreground1.getAverageWaitingTime();
+ averageWaitingForeground2 += foreground2.getAverageWaitingTime();
+ }
+ pw.print("-- Background : ");
+ pw.println((averageWaitingBackground / NUM_LOOPS) / NANOSECONDS_IN_MILLISECONDS + " ms");
+
+ pw.print("-- First foreground : ");
+ pw.println((averageWaitingForeground1 / NUM_LOOPS) / NANOSECONDS_IN_MILLISECONDS + " ms");
+
+ pw.print("-- Second foreground : ");
+ pw.println((averageWaitingForeground2 / NUM_LOOPS) / NANOSECONDS_IN_MILLISECONDS + " ms");
+ }
+
+ private static void completedTime() {
+ long averageCompletedTime1 = 0;
+ long averageCompletedTime2 = 0;
+ long averageCompletedTime3 = 0;
+ long averageCompletedTime4 = 0;
+ long averageCompletedTime5 = 0;
+ long averageCompletedTime6 = 0;
+
+ pw.println("----- Time to complete request -----");
+ for (int i = 0; i < NUM_LOOPS; i++) {
+ try {
+ ForegroundRequest foreground1 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ trace.sendRequest(foreground1);
+ foreground1.waitForCompletion();
+ averageCompletedTime1 += foreground1.getCompletedTime();
+
+ ForegroundRequest foreground2 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground3 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ trace.sendRequest(foreground2);
+ trace.sendRequest(foreground3);
+ foreground2.waitForCompletion();
+ foreground3.waitForCompletion();
+ averageCompletedTime2 += (foreground2.getCompletedTime() + foreground3.getCompletedTime());
+
+ ForegroundRequest foreground4 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ BackgroundRequest background1 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ trace.sendRequest(foreground4);
+ trace.sendRequest(background1);
+ foreground4.waitForCompletion();
+ background1.waitForCompletion();
+ averageCompletedTime3 += (foreground4.getCompletedTime() + background1.getCompletedTime());
+
+ ForegroundRequest foreground5 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground6 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ BackgroundRequest background2 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ trace.sendRequest(foreground5);
+ trace.sendRequest(foreground6);
+ trace.sendRequest(background2);
+ foreground5.waitForCompletion();
+ foreground6.waitForCompletion();
+ background2.waitForCompletion();
+ averageCompletedTime4 += (foreground5.getCompletedTime() + foreground6.getCompletedTime() + background2.getCompletedTime());
+
+ ForegroundRequest foreground7 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground8 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground9 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ BackgroundRequest background3 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ trace.sendRequest(foreground7);
+ trace.sendRequest(foreground8);
+ trace.sendRequest(foreground9);
+ trace.sendRequest(background3);
+ foreground7.waitForCompletion();
+ foreground8.waitForCompletion();
+ foreground9.waitForCompletion();
+ background3.waitForCompletion();
+ averageCompletedTime5 += (foreground7.getCompletedTime() + foreground8.getCompletedTime() + foreground9.getCompletedTime() + background3.getCompletedTime());
+
+ ForegroundRequest foreground10 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground11 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground12 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground13 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ BackgroundRequest background4 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ trace.sendRequest(foreground10);
+ trace.sendRequest(foreground11);
+ trace.sendRequest(foreground12);
+ trace.sendRequest(foreground13);
+ trace.sendRequest(background4);
+ foreground10.waitForCompletion();
+ foreground11.waitForCompletion();
+ foreground12.waitForCompletion();
+ foreground13.waitForCompletion();
+ background4.waitForCompletion();
+ averageCompletedTime6 += (foreground10.getCompletedTime() + foreground11.getCompletedTime() + foreground12.getCompletedTime() + foreground13.getCompletedTime() + background4.getCompletedTime());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ pw.print("-- Time to complete one request : ");
+ pw.println((averageCompletedTime1 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
+
+ pw.print("-- Time to complete 2 requests (2 foreground) : ");
+ pw.println((averageCompletedTime2 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
+
+ pw.print("-- Time to complete 2 requests (1 foreground, 1 background) : ");
+ pw.println((averageCompletedTime3 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
+
+ pw.print("-- Time to complete 3 requests (2 foreground, 1 background) : ");
+ pw.println((averageCompletedTime4 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
+
+ pw.print("-- Time to complete 4 requests (3 foreground, 1 background) : ");
+ pw.println((averageCompletedTime5 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
+
+ pw.print("-- Time to complete 5 requests (4 foreground, 1 background) : ");
+ pw.println((averageCompletedTime6 / NUM_LOOPS) / NANOSECONDS_IN_SECONDS + " s");
+ }
+
+ /**
+ * The benchmark results
+ */
+ public static void benchmarkResults() {
+ pw.println("---------- Benchmark completed ----------");
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper methods
+ // ------------------------------------------------------------------------
+
+ private static class BackgroundRequest extends TmfEventRequest {
+ private long startTime;
+ private long endTimeLatency = -1;
+ private long completedTime = 0;
+ private long waitingTimeStart = 0;
+ private long waitingTimeEnd = 0;
+ private long waitingTime = 0;
+ private int waitingCounter = 0;
+ private boolean isWaiting = false;
+
+ BackgroundRequest(TmfTimeRange timeRange) {
+ super(trace.getEventType(),
+ timeRange,
+ 0,
+ ITmfEventRequest.ALL_DATA,
+ ExecutionType.BACKGROUND);
+ startTime = System.nanoTime();
+ }
+
+ @Override
+ public void handleData(final ITmfEvent event) {
+ if (endTimeLatency == -1) {
+ endTimeLatency = System.nanoTime();
+ }
+ super.handleData(event);
+ if (lastForegroundRequest == null && lastBackgroundRequest == null) {
+ lastBackgroundRequest = this;
+ }
+ if (isWaiting) {
+ waitingTimeEnd = System.nanoTime();
+ waitingTime += waitingTimeEnd - waitingTimeStart;
+ ++waitingCounter;
+ isWaiting = false;
+ }
+ if (lastForegroundRequest != null) {
+ lastForegroundRequest.waitingTimeStart = System.nanoTime();
+ lastForegroundRequest.isWaiting = true;
+ lastForegroundRequest = null;
+ lastBackgroundRequest = this;
+ }
+ if (lastBackgroundRequest != this) {
+ lastBackgroundRequest.waitingTimeStart = System.nanoTime();
+ lastBackgroundRequest.isWaiting = true;
+ lastBackgroundRequest = this;
+ }
+ }
+
+ @Override
+ public void handleCompleted() {
+ completedTime = System.nanoTime();
+ super.handleCompleted();
+ }
+
+ public long getCompletedTime() {
+ return completedTime - startTime;
+ }
+
+ public long getAverageWaitingTime() {
+ if (waitingCounter == 0) {
+ return 0;
+ }
+ return waitingTime / waitingCounter;
+ }
+ }
+
+ private static class ForegroundRequest extends TmfEventRequest {
+ private long startTime = 0;
+ private long endTimeLatency = -1;
+ private long completedTime = 0;
+ private long waitingTimeStart = 0;
+ private long waitingTimeEnd = 0;
+ private long waitingTime = 0;
+ private int waitingCounter = 0;
+ private boolean isWaiting = false;
+
+ ForegroundRequest(TmfTimeRange timeRange) {
+ super(trace.getEventType(),
+ timeRange,
+ 0,
+ ITmfEventRequest.ALL_DATA,
+ ExecutionType.FOREGROUND);
+ startTime = System.nanoTime();
+ }
+
+ @Override
+ public void handleData(final ITmfEvent event) {
+ if (endTimeLatency == -1) {
+ endTimeLatency = System.nanoTime();
+ }
+ super.handleData(event);
+ if (lastBackgroundRequest == null && lastForegroundRequest == null) {
+ lastForegroundRequest = this;
+ }
+ if (isWaiting) {
+ waitingTimeEnd = System.nanoTime();
+ waitingTime += waitingTimeEnd - waitingTimeStart;
+ ++waitingCounter;
+ isWaiting = false;
+ }
+ if (lastBackgroundRequest != null) {
+ lastBackgroundRequest.waitingTimeStart = System.nanoTime();
+ lastBackgroundRequest.isWaiting = true;
+ lastBackgroundRequest = null;
+ lastForegroundRequest = this;
+ }
+ if (lastForegroundRequest != this) {
+ lastForegroundRequest.waitingTimeStart = System.nanoTime();
+ lastForegroundRequest.isWaiting = true;
+ lastForegroundRequest = this;
+ }
+ }
+
+ @Override
+ public void handleCompleted() {
+ completedTime = System.nanoTime();
+ super.handleCompleted();
+ }
+
+ public long getLatency() {
+ return endTimeLatency - startTime;
+ }
+
+ public long getCompletedTime() {
+ return completedTime - startTime;
+ }
+
+ public long getAverageWaitingTime() {
+ if (waitingCounter == 0) {
+ return 0;
+ }
+ return waitingTime / waitingCounter;
+ }
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon Delisle - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.request;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+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.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
+
+/**
+ * Test suite for the scheduler.
+ */
+public class TmfSchedulerTest {
+
+ /** Time-out tests after 60 seconds */
+ @Rule
+ public TestRule globalTimeout= new Timeout(60000);
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
+ private static final int NB_EVENTS_TRACE = 695319;
+ private static final int NB_EVENTS_TIME_RANGE = 155133;
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private CtfTmfTrace fixture;
+
+ private long fStartTime;
+ private long fEndTime;
+ private TmfTimeRange fForegroundTimeRange;
+
+ private final List<String> fOrderList = new ArrayList<>();
+ private int fForegroundId = 0;
+ private int fBackgroundId = 0;
+
+ /**
+ * Perform pre-test initialization.
+ *
+ * @throws TmfTraceException
+ * If the test trace is not found
+ */
+ @Before
+ public void setUp() throws TmfTraceException {
+ assumeTrue(testTrace.exists());
+ fixture = new CtfTmfTrace();
+ fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
+ fixture.indexTrace(true);
+ fStartTime = fixture.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ fEndTime = fixture.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+
+ long foregroundStartTime = fStartTime + ((fEndTime - fStartTime) / 4);
+ long foregroundEndTime = fStartTime + ((fEndTime - fStartTime) / 2);
+ fForegroundTimeRange = new TmfTimeRange(new TmfTimestamp(foregroundStartTime, ITmfTimestamp.NANOSECOND_SCALE),
+ new TmfTimestamp(foregroundEndTime, ITmfTimestamp.NANOSECOND_SCALE));
+ }
+
+ /**
+ * Perform post-test clean-up.
+ */
+ @After
+ public void tearDown() {
+ if (fixture != null) {
+ fixture.dispose();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Tests cases
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test one background request
+ */
+ @Test
+ public void backgroundRequest() {
+ BackgroundRequest background = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ fixture.sendRequest(background);
+ try {
+ background.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+ assertEquals(NB_EVENTS_TRACE, background.getNbEvents());
+ }
+
+ /**
+ * Test one foreground request
+ */
+ @Test
+ public void foregroundRequest() {
+ ForegroundRequest foreground = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ fixture.sendRequest(foreground);
+ try {
+ foreground.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+ assertEquals(NB_EVENTS_TRACE, foreground.getNbEvents());
+ }
+
+ /**
+ * Test one foreground and one background request for the entire trace at
+ * the same time
+ */
+ @Test
+ public void TestMultiRequest1() {
+ BackgroundRequest background = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground = new ForegroundRequest(TmfTimeRange.ETERNITY);
+
+ fixture.sendRequest(background);
+ fixture.sendRequest(foreground);
+ try {
+ background.waitForCompletion();
+ foreground.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+
+ assertEquals(NB_EVENTS_TRACE, background.getNbEvents());
+ assertEquals(NB_EVENTS_TRACE, foreground.getNbEvents());
+ }
+
+ /**
+ * Test one background request for the entire trace and one foreground
+ * request for smaller time range
+ */
+ @Test
+ public void TestMultiRequest2() {
+ BackgroundRequest background2 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground2 = new ForegroundRequest(fForegroundTimeRange);
+
+ fixture.sendRequest(background2);
+ fixture.sendRequest(foreground2);
+ try {
+ background2.waitForCompletion();
+ foreground2.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+
+ assertEquals(NB_EVENTS_TRACE, background2.getNbEvents());
+ assertEquals(NB_EVENTS_TIME_RANGE, foreground2.getNbEvents());
+ }
+
+ /**
+ * Test two foreground request, one to select a time range and one to select
+ * an event in this time range
+ */
+ @Test
+ public void TestMultiRequest3() {
+ ForegroundRequest foreground3 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ fixture.sendRequest(foreground3);
+
+ TmfTimeSynchSignal signal3 = new TmfTimeSynchSignal(this, new TmfTimestamp(fForegroundTimeRange.getStartTime()));
+ fixture.broadcast(signal3);
+
+ try {
+ foreground3.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+
+ assertEquals(NB_EVENTS_TRACE, foreground3.getNbEvents());
+ }
+
+ /**
+ * Test two foreground request, one to select a time range and one to select
+ * an event before this time range
+ */
+ @Test
+ public void TestMultiRequest4() {
+ ForegroundRequest foreground4 = new ForegroundRequest(fForegroundTimeRange);
+ fixture.sendRequest(foreground4);
+ TmfTimeSynchSignal signal4 = new TmfTimeSynchSignal(this, new TmfTimestamp(fStartTime + ((fEndTime - fStartTime) / 8)));
+ fixture.broadcast(signal4);
+
+ try {
+ foreground4.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+
+ assertEquals(NB_EVENTS_TIME_RANGE, foreground4.getNbEvents());
+ }
+
+ /**
+ * Test two foreground request, one to select a time range and one to select
+ * an event after this time range
+ */
+ @Test
+ public void TestMultiRequest5() {
+ ForegroundRequest foreground5 = new ForegroundRequest(fForegroundTimeRange);
+ fixture.sendRequest(foreground5);
+ TmfTimeSynchSignal signal5 = new TmfTimeSynchSignal(this, new TmfTimestamp(fEndTime - ((fEndTime - fStartTime) / 4)));
+ fixture.broadcast(signal5);
+
+ try {
+ foreground5.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+
+ assertEquals(NB_EVENTS_TIME_RANGE, foreground5.getNbEvents());
+ }
+
+ /**
+ * Test one background and one foreground request for the entire trace and
+ * one foreground request to select an event
+ */
+ @Test
+ public void TestMultiRequest6() {
+ BackgroundRequest background6 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground6 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+
+ fixture.sendRequest(background6);
+ fixture.sendRequest(foreground6);
+
+ TmfTimeSynchSignal signal6 = new TmfTimeSynchSignal(this, new TmfTimestamp(fStartTime + ((fEndTime - fStartTime) / 8)));
+ fixture.broadcast(signal6);
+
+ try {
+ background6.waitForCompletion();
+ foreground6.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+
+ assertEquals(NB_EVENTS_TRACE, background6.getNbEvents());
+ assertEquals(NB_EVENTS_TRACE, foreground6.getNbEvents());
+ }
+
+ /**
+ * Four request, two foreground and two background
+ */
+ @Test
+ public void TestMultiRequest7() {
+ ForegroundRequest foreground7 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground8 = new ForegroundRequest(fForegroundTimeRange);
+ BackgroundRequest background7 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ BackgroundRequest background8 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ fixture.sendRequest(foreground7);
+ fixture.sendRequest(foreground8);
+ fixture.sendRequest(background7);
+ fixture.sendRequest(background8);
+ try {
+ foreground7.waitForCompletion();
+ foreground8.waitForCompletion();
+ background7.waitForCompletion();
+ background8.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+ assertEquals(NB_EVENTS_TRACE, foreground7.getNbEvents());
+ assertEquals(NB_EVENTS_TIME_RANGE, foreground8.getNbEvents());
+ assertEquals(NB_EVENTS_TRACE, background7.getNbEvents());
+ assertEquals(NB_EVENTS_TRACE, background8.getNbEvents());
+ }
+
+ /**
+ * One long foreground request and one short foreground request, the short
+ * one should finish first
+ */
+ @Test
+ public void preemptedForegroundRequest() {
+ ForegroundRequest foreground9 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ TmfTimeRange shortTimeRange = new TmfTimeRange(new TmfTimestamp(fStartTime, ITmfTimestamp.NANOSECOND_SCALE),
+ new TmfTimestamp(fStartTime + ((fEndTime - fStartTime) / 16), ITmfTimestamp.NANOSECOND_SCALE));
+ ForegroundRequest shortForeground = new ForegroundRequest(shortTimeRange);
+ fixture.sendRequest(foreground9);
+ try {
+ foreground9.waitForStart();
+ } catch (InterruptedException e) {
+ fail();
+ }
+ fixture.sendRequest(shortForeground);
+ try {
+ shortForeground.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+ assertFalse(foreground9.isCompleted());
+ }
+
+ /**
+ * One long background request and one short foreground request, the
+ * foreground request should finish first
+ */
+ @Test
+ public void preemptedBackgroundRequest() {
+ BackgroundRequest background9 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground10 = new ForegroundRequest(fForegroundTimeRange);
+ fixture.sendRequest(background9);
+ fixture.sendRequest(foreground10);
+ try {
+ foreground10.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+ assertTrue(foreground10.isCompleted());
+ assertFalse(background9.isCompleted());
+ }
+
+ /**
+ * Test if the scheduler is working as expected
+ */
+ @Ignore
+ @Test
+ public void executionOrder() {
+ List<String> expectedOrder = new LinkedList<>();
+ expectedOrder.add("FOREGROUND1");
+ expectedOrder.add("FOREGROUND2");
+ expectedOrder.add("FOREGROUND3");
+ expectedOrder.add("FOREGROUND4");
+ expectedOrder.add("BACKGROUND1");
+ expectedOrder.add("FOREGROUND1");
+ expectedOrder.add("FOREGROUND2");
+ expectedOrder.add("FOREGROUND3");
+ expectedOrder.add("FOREGROUND4");
+ expectedOrder.add("BACKGROUND2");
+
+ fOrderList.clear();
+ fForegroundId = 0;
+ fBackgroundId = 0;
+
+ BackgroundRequest background1 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+ BackgroundRequest background2 = new BackgroundRequest(TmfTimeRange.ETERNITY);
+
+ ForegroundRequest foreground1 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground2 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground3 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+ ForegroundRequest foreground4 = new ForegroundRequest(TmfTimeRange.ETERNITY);
+
+ fixture.sendRequest(foreground1);
+ fixture.sendRequest(foreground2);
+ fixture.sendRequest(foreground3);
+ fixture.sendRequest(foreground4);
+ fixture.sendRequest(background1);
+ fixture.sendRequest(background2);
+ try {
+ foreground1.waitForCompletion();
+ foreground2.waitForCompletion();
+ foreground3.waitForCompletion();
+ foreground4.waitForCompletion();
+ background1.waitForCompletion();
+ background2.waitForCompletion();
+ } catch (InterruptedException e) {
+ fail();
+ }
+ assertEquals(expectedOrder, fOrderList.subList(0, expectedOrder.size()));
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper methods
+ // ------------------------------------------------------------------------
+
+ private class BackgroundRequest extends TmfEventRequest {
+ private int nbEvents = 0;
+ private String backgroundName;
+
+ BackgroundRequest(TmfTimeRange timeRange) {
+ super(fixture.getEventType(),
+ timeRange,
+ 0,
+ ITmfEventRequest.ALL_DATA,
+ ExecutionType.BACKGROUND);
+ backgroundName = getExecType().toString() + ++fBackgroundId;
+ }
+
+ @Override
+ public void handleData(final ITmfEvent event) {
+ super.handleData(event);
+ synchronized (fOrderList) {
+ if (fOrderList.isEmpty() || !fOrderList.get(fOrderList.size() - 1).equals(backgroundName)) {
+ fOrderList.add(backgroundName);
+ }
+ }
+ ++nbEvents;
+ }
+
+ public int getNbEvents() {
+ return nbEvents;
+ }
+ }
+
+ private class ForegroundRequest extends TmfEventRequest {
+ private int nbEvents = 0;
+ private String foregroundName;
+
+ ForegroundRequest(TmfTimeRange timeRange) {
+ super(fixture.getEventType(),
+ timeRange,
+ 0,
+ ITmfEventRequest.ALL_DATA,
+ ExecutionType.FOREGROUND);
+ foregroundName = getExecType().toString() + ++fForegroundId;
+ }
+
+ @Override
+ public void handleData(final ITmfEvent event) {
+ super.handleData(event);
+ synchronized (fOrderList) {
+ if (fOrderList.isEmpty() || !fOrderList.get(fOrderList.size() - 1).equals(foregroundName)) {
+ fOrderList.add(foregroundName);
+ }
+ }
+ ++nbEvents;
+ }
+
+ public int getNbEvents() {
+ return nbEvents;
+ }
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.statistics;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TmfEventsStatisticsTest.class,
+ TmfStateStatisticsTest.class
+})
+public class AllTests {}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.statistics;
+
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.tracecompass.tmf.core.statistics.TmfEventsStatistics;
+import org.junit.BeforeClass;
+
+/**
+ * Unit tests for the {@link TmfEventsStatistics}
+ *
+ * @author Alexandre Montplaisir
+ */
+public class TmfEventsStatisticsTest extends TmfStatisticsTest {
+
+ /**
+ * Set up the fixture once for all tests.
+ */
+ @BeforeClass
+ public static void setUpClass() {
+ assumeTrue(testTrace.exists());
+ backend = new TmfEventsStatistics(testTrace.getTrace());
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.statistics;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.statistics.TmfStateStatistics;
+import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsEventTypesModule;
+import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsTotalsModule;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+/**
+ * Unit tests for the {@link TmfStateStatistics}
+ *
+ * @author Alexandre Montplaisir
+ */
+public class TmfStateStatisticsTest extends TmfStatisticsTest {
+
+ private ITmfTrace fTrace;
+
+ private TmfStatisticsTotalsModule fTotalsMod;
+ private TmfStatisticsEventTypesModule fEventTypesMod;
+
+ /**
+ * Class setup
+ */
+ @BeforeClass
+ public static void setUpClass() {
+ assumeTrue(testTrace.exists());
+ }
+
+ /**
+ * Test setup
+ */
+ @Before
+ public void setUp() {
+ fTrace = testTrace.getTrace();
+
+ /* Prepare the two analysis-backed state systems */
+ fTotalsMod = new TmfStatisticsTotalsModule();
+ fEventTypesMod = new TmfStatisticsEventTypesModule();
+ try {
+ fTotalsMod.setTrace(fTrace);
+ fEventTypesMod.setTrace(fTrace);
+ } catch (TmfAnalysisException e) {
+ fail();
+ }
+
+ fTotalsMod.schedule();
+ fEventTypesMod.schedule();
+ assertTrue(fTotalsMod.waitForCompletion());
+ assertTrue(fEventTypesMod.waitForCompletion());
+
+ ITmfStateSystem totalsSS = fTotalsMod.getStateSystem();
+ ITmfStateSystem eventTypesSS = fEventTypesMod.getStateSystem();
+ assertNotNull(totalsSS);
+ assertNotNull(eventTypesSS);
+
+ backend = new TmfStateStatistics(totalsSS, eventTypesSS);
+ }
+
+ /**
+ * Test cleanup
+ */
+ @After
+ public void tearDown() {
+ fTotalsMod.dispose();
+ fEventTypesMod.dispose();
+ fTrace.dispose();
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.statistics;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
+
+/**
+ * Base unit test class for any type of ITmfStatistics. Sub-classes should
+ * implement a "@BeforeClass" method to setup the 'backend' fixture accordingly.
+ *
+ * @author Alexandre Montplaisir
+ */
+public abstract class TmfStatisticsTest {
+
+ /** Time-out tests after 30 seconds */
+ @Rule public TestRule globalTimeout= new Timeout(30000);
+
+ /** Test trace used for these tests */
+ protected static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
+
+ /** The statistics back-end object */
+ protected static ITmfStatistics backend;
+
+ /* Known values about the trace */
+ private static final int totalNbEvents = 695319;
+ private static final long tStart = 1332170682440133097L; /* Timestamp of first event */
+ private static final long tEnd = 1332170692664579801L; /* Timestamp of last event */
+
+ /* Timestamps of interest */
+ private static final long t1 = 1332170682490946000L;
+ private static final long t2 = 1332170682490947524L; /* event exactly here */
+ private static final long t3 = 1332170682490948000L;
+ private static final long t4 = 1332170682490949000L;
+ private static final long t5 = 1332170682490949270L; /* following event here */
+ private static final long t6 = 1332170682490949300L;
+
+ private static final String eventType = "lttng_statedump_process_state";
+
+
+ // ------------------------------------------------------------------------
+ // Tests for histogramQuery()
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test the {@link ITmfStatistics#histogramQuery} method for the small known
+ * interval.
+ */
+ @Test
+ public void testHistogramQuerySmall() {
+ final int NB_REQ = 10;
+ List<Long> results = backend.histogramQuery(t1, t6, NB_REQ);
+
+ /* Make sure the returned array has the right size */
+ assertEquals(NB_REQ, results.size());
+
+ /* Check the contents of each "bucket" */
+ assertEquals(0, results.get(0).longValue());
+ assertEquals(0, results.get(1).longValue());
+ assertEquals(0, results.get(2).longValue());
+ assertEquals(0, results.get(3).longValue());
+ assertEquals(1, results.get(4).longValue());
+ assertEquals(0, results.get(5).longValue());
+ assertEquals(0, results.get(6).longValue());
+ assertEquals(0, results.get(7).longValue());
+ assertEquals(0, results.get(8).longValue());
+ assertEquals(1, results.get(9).longValue());
+
+ }
+
+ /**
+ * Test the {@link ITmfStatistics#histogramQuery} method over the whole
+ * trace.
+ */
+ @Test
+ public void testHistogramQueryFull() {
+ final int NB_REQ = 10;
+ List<Long> results = backend.histogramQuery(tStart, tEnd, NB_REQ);
+
+ /* Make sure the returned array has the right size */
+ assertEquals(NB_REQ, results.size());
+
+ /* Check the total number of events */
+ long count = 0;
+ for (long val : results) {
+ count += val;
+ }
+ assertEquals(totalNbEvents, count);
+
+ /* Check the contents of each "bucket" */
+ assertEquals(94161, results.get(0).longValue());
+ assertEquals(87348, results.get(1).longValue());
+ assertEquals(58941, results.get(2).longValue());
+ assertEquals(59879, results.get(3).longValue());
+ assertEquals(66941, results.get(4).longValue());
+ assertEquals(68939, results.get(5).longValue());
+ assertEquals(72746, results.get(6).longValue());
+ assertEquals(60749, results.get(7).longValue());
+ assertEquals(61208, results.get(8).longValue());
+ assertEquals(64407, results.get(9).longValue());
+ }
+
+ // ------------------------------------------------------------------------
+ // Test for getEventsTotal()
+ // ------------------------------------------------------------------------
+
+ /**
+ * Basic test for {@link ITmfStatistics#getEventsTotal}
+ */
+ @Test
+ public void testGetEventsTotal() {
+ long count = backend.getEventsTotal();
+ assertEquals(totalNbEvents, count);
+ }
+
+ // ------------------------------------------------------------------------
+ // Test for getEventTypesTotal()
+ // ------------------------------------------------------------------------
+
+ /**
+ * Basic test for {@link ITmfStatistics#getEventTypesTotal}
+ */
+ @Test
+ public void testEventTypesTotal() {
+ Map<String, Long> res = backend.getEventTypesTotal();
+ assertEquals(126, res.size()); /* Number of different event types in the trace */
+
+ long count = sumOfEvents(res);
+ assertEquals(totalNbEvents, count);
+ }
+
+ // ------------------------------------------------------------------------
+ // Tests for getEventsInRange(ITmfTimestamp start, ITmfTimestamp end)
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test for {@link ITmfStatistics#getEventsInRange} over the whole trace.
+ */
+ @Test
+ public void testGetEventsInRangeWholeRange() {
+ long count = backend.getEventsInRange(tStart, tEnd);
+ assertEquals(totalNbEvents, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventsInRange} for the whole range,
+ * except the start time (there is only one event at the start time).
+ */
+ @Test
+ public void testGetEventsInRangeMinusStart() {
+ long count = backend.getEventsInRange(tStart + 1, tEnd);
+ assertEquals(totalNbEvents - 1, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventsInRange} for the whole range,
+ * except the end time (there is only one event at the end time).
+ */
+ @Test
+ public void testGetEventsInRangeMinusEnd() {
+ long count = backend.getEventsInRange(tStart, tEnd - 1);
+ assertEquals(totalNbEvents - 1, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventsInRange} when both the start and
+ * end times don't match an event.
+ */
+ @Test
+ public void testGetEventsInRangeNoEventsAtEdges() {
+ long count = backend.getEventsInRange(t1, t6);
+ assertEquals(2, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventsInRange} when the *start* of the
+ * interval is exactly on an event (that event should be included).
+ */
+ @Test
+ public void testGetEventsInRangeEventAtStart() {
+ long count = backend.getEventsInRange(t2, t3);
+ assertEquals(1, count);
+
+ count = backend.getEventsInRange(t2, t6);
+ assertEquals(2, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventsInRange} when the *end* of the
+ * interval is exactly on an event (that event should be included).
+ */
+ @Test
+ public void testGetEventsInRangeEventAtEnd() {
+ long count = backend.getEventsInRange(t4, t5);
+ assertEquals(1, count);
+
+ count = backend.getEventsInRange(t1, t5);
+ assertEquals(2, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventsInRange} when there are events
+ * matching exactly both the start and end times of the range (both should
+ * be included).
+ */
+ @Test
+ public void testGetEventsInRangeEventAtBoth() {
+ long count = backend.getEventsInRange(t2, t5);
+ assertEquals(2, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventsInRange} when there are no events
+ * in a given range.
+ */
+ @Test
+ public void testGetEventsInRangeNoEvents() {
+ long count = backend.getEventsInRange(t3, t4);
+ assertEquals(0, count);
+ }
+
+ // ------------------------------------------------------------------------
+ // Tests for getEventTypesInRange(ITmfTimestamp start, ITmfTimestamp end)
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test for {@link ITmfStatistics#getEventTypesInRange} over the whole trace.
+ */
+ @Test
+ public void testGetEventTypesInRangeWholeRange() {
+ Map<String, Long> result = backend.getEventTypesInRange(tStart, tEnd);
+ /* Number of events of that type in the whole trace */
+ assertEquals(new Long(464L), result.get(eventType));
+
+ long count = sumOfEvents(result);
+ assertEquals(totalNbEvents, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventTypesInRange} for the whole range,
+ * except the start time (there is only one event at the start time).
+ */
+ @Test
+ public void testGetEventTypesInRangeMinusStart() {
+ Map<String, Long> result = backend.getEventTypesInRange(tStart + 1, tEnd);
+
+ long count = sumOfEvents(result);
+ assertEquals(totalNbEvents - 1, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventTypesInRange} for the whole range,
+ * except the end time (there is only one event at the end time).
+ */
+ @Test
+ public void testGetEventTypesInRangeMinusEnd() {
+ Map<String, Long> result = backend.getEventTypesInRange(tStart, tEnd - 1);
+
+ long count = sumOfEvents(result);
+ assertEquals(totalNbEvents - 1, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventTypesInRange} when both the start
+ * and end times don't match an event.
+ */
+ @Test
+ public void testGetEventTypesInRangeNoEventsAtEdges() {
+ Map<String, Long> result = backend.getEventTypesInRange(t1, t6);
+ assertEquals(new Long(2L), result.get(eventType));
+
+ long count = sumOfEvents(result);
+ assertEquals(2, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventTypesInRange} when the *start* of
+ * the interval is exactly on an event (that event should be included).
+ */
+ @Test
+ public void testGetEventTypesInRangeEventAtStart() {
+ Map<String, Long> result = backend.getEventTypesInRange(t2, t3);
+ assertEquals(new Long(1L), result.get(eventType));
+ long count = sumOfEvents(result);
+ assertEquals(1, count);
+
+ result = backend.getEventTypesInRange(t2, t6);
+ assertEquals(new Long(2L), result.get(eventType));
+ count = sumOfEvents(result);
+ assertEquals(2, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventTypesInRange} when the *end* of
+ * the interval is exactly on an event (that event should be included).
+ */
+ @Test
+ public void testGetEventTypesInRangeEventAtEnd() {
+ Map<String, Long> result = backend.getEventTypesInRange(t4, t5);
+ assertEquals(new Long(1L), result.get(eventType));
+ long count = sumOfEvents(result);
+ assertEquals(1, count);
+
+ result = backend.getEventTypesInRange(t1, t5);
+ assertEquals(new Long(2L), result.get(eventType));
+ count = sumOfEvents(result);
+ assertEquals(2, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventTypesInRange} when there are
+ * events matching exactly both the start and end times of the range (both
+ * should be included).
+ */
+ @Test
+ public void testGetEventTypesInRangeEventAtBoth() {
+ Map<String, Long> result = backend.getEventTypesInRange(t2, t5);
+ assertEquals(new Long(2L), result.get(eventType));
+ long count = sumOfEvents(result);
+ assertEquals(2, count);
+ }
+
+ /**
+ * Test for {@link ITmfStatistics#getEventTypesInRange} when there are no
+ * events in a given range.
+ */
+ @Test
+ public void testGetEventTypesInRangeNoEvents() {
+ Map<String, Long> result = backend.getEventTypesInRange(t3, t4);
+ long count = sumOfEvents(result);
+ assertEquals(0, count);
+ }
+
+ // ------------------------------------------------------------------------
+ // Convenience methods
+ // ------------------------------------------------------------------------
+
+ private static long sumOfEvents(Map<String, Long> map) {
+ long count = 0;
+ for (long val : map.values()) {
+ count += val;
+ }
+ return count;
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.tracemanager;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TmfTraceManagerTest.class
+})
+public class AllTests {}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ * Patrick Tasse - Support selection range
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.tracemanager;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+import java.util.Set;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.signal.TmfRangeSynchSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Test suite for the {@link TmfTraceManager}.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class TmfTraceManagerTest {
+
+ private static final int SCALE = ITmfTimestamp.NANOSECOND_SCALE;
+
+ private static ITmfTrace trace1;
+ private static final long t1start = 1331668247314038062L;
+ private static final long t1end = 1331668259054285979L;
+
+ private static ITmfTrace trace2;
+ private static final long t2start = 1332170682440133097L;
+ private static final long t2end = 1332170692664579801L;
+
+ private static final long ONE_SECOND = 1000000000L;
+
+ private TmfTraceManager tm;
+
+
+ /**
+ * Test class initialization
+ */
+ @BeforeClass
+ public static void setUpClass() {
+ assumeTrue(CtfTmfTestTrace.TRACE2.exists());
+ assumeTrue(CtfTmfTestTrace.KERNEL.exists());
+ trace1 = CtfTmfTestTrace.TRACE2.getTrace();
+ trace2 = CtfTmfTestTrace.KERNEL.getTrace();
+
+ trace1.indexTrace(true);
+ trace2.indexTrace(true);
+
+ // Deregister traces from signal manager so that they don't
+ // interfere with the TmfTraceManager tests
+ TmfSignalManager.deregister(trace1);
+ TmfSignalManager.deregister(trace2);
+ }
+
+ /**
+ * Test initialization
+ */
+ @Before
+ public void setUp() {
+ tm = TmfTraceManager.getInstance();
+ }
+
+ /**
+ * Test clean-up
+ */
+ @After
+ public void tearDown() {
+ while (tm.getActiveTrace() != null) {
+ closeTrace(tm.getActiveTrace());
+ }
+ }
+
+ /**
+ * Test class clean-up
+ */
+ @AfterClass
+ public static void tearDownClass() {
+ CtfTmfTestTrace.TRACE2.dispose();
+ CtfTmfTestTrace.KERNEL.dispose();
+ }
+
+ // ------------------------------------------------------------------------
+ // Dummy actions (fake signals)
+ // ------------------------------------------------------------------------
+
+ private void openTrace(ITmfTrace trace) {
+ if (trace == null) {
+ throw new IllegalArgumentException();
+ }
+ TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, trace, null));
+ selectTrace(trace);
+ }
+
+ private void closeTrace(ITmfTrace trace) {
+ if (trace == null) {
+ throw new IllegalArgumentException();
+ }
+ TmfSignalManager.dispatchSignal(new TmfTraceClosedSignal(this, trace));
+ /*
+ * In TMF, the next tab would now be selected (if there are some), which
+ * would select another trace automatically.
+ */
+ if (tm.getOpenedTraces().size() > 0) {
+ selectTrace(tm.getOpenedTraces().toArray(new ITmfTrace[0])[0]);
+ }
+ }
+
+ private void selectTrace(ITmfTrace trace) {
+ TmfSignalManager.dispatchSignal(new TmfTraceSelectedSignal(this, trace));
+ }
+
+ private void selectTimestamp(ITmfTimestamp ts) {
+ TmfSignalManager.dispatchSignal(new TmfTimeSynchSignal(this, ts));
+ }
+
+ private void selectTimeRange(TmfTimeRange tr) {
+ TmfSignalManager.dispatchSignal(new TmfRangeSynchSignal(this, tr));
+ }
+
+ // ------------------------------------------------------------------------
+ // General tests
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test that the manager is correctly initialized
+ */
+ @Test
+ public void testInitialize() {
+ TmfTraceManager mgr = TmfTraceManager.getInstance();
+ assertNotNull(mgr);
+ assertSame(tm, mgr);
+ }
+
+ /**
+ * Test the contents of a trace set with one trace.
+ */
+ @Test
+ public void testTraceSet() {
+ openTrace(trace1);
+ openTrace(trace2);
+ selectTrace(trace2);
+
+ ITmfTrace[] expected = new ITmfTrace[] { trace2 };
+ ITmfTrace[] actual = tm.getActiveTraceSet();
+
+ assertEquals(1, actual.length);
+ assertArrayEquals(expected, actual);
+ }
+
+ /**
+ * Test the contents of a trace set with an experiment.
+ */
+ @Test
+ public void testTraceSetExperiment() {
+ TmfExperiment exp = createExperiment(trace1, trace2);
+ openTrace(trace1);
+ openTrace(exp);
+
+ ITmfTrace[] expected = new ITmfTrace[] { trace1, trace2 };
+ ITmfTrace[] actual = tm.getActiveTraceSet();
+
+ assertEquals(2, actual.length);
+ assertArrayEquals(expected, actual);
+ }
+
+ /**
+ * Test the contents of the complete trace set.
+ */
+ @Test
+ public void testTraceSetWithExperiment() {
+ /* Test with a trace */
+ Set<ITmfTrace> expected = ImmutableSet.of(trace1);
+ Set<ITmfTrace> actual = TmfTraceManager.getTraceSetWithExperiment(trace1);
+ assertEquals(1, actual.size());
+ assertEquals(expected, actual);
+
+ /* Test with an experiment */
+ TmfExperiment exp = createExperiment(trace1, trace2);
+ expected = ImmutableSet.of(trace1, trace2, exp);
+ actual = TmfTraceManager.getTraceSetWithExperiment(exp);
+ assertEquals(3, actual.size());
+ assertEquals(expected, actual);
+ }
+
+ /**
+ * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
+ */
+ @Test
+ public void testSupplementaryFileDir() {
+ String name1 = trace1.getName();
+ String name2 = trace2.getName();
+ String basePath = TmfTraceManager.getTemporaryDirPath() + File.separator;
+
+ String expected1 = basePath + name1 + File.separator;
+ String expected2 = basePath + name2 + File.separator;
+
+ assertEquals(expected1, TmfTraceManager.getSupplementaryFileDir(trace1));
+ assertEquals(expected2, TmfTraceManager.getSupplementaryFileDir(trace2));
+ }
+
+ // ------------------------------------------------------------------------
+ // Test a single trace
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test the initial range of a single trace.
+ */
+ @Test
+ public void testTraceInitialRange() {
+ openTrace(trace2);
+ final TmfTimeRange expectedRange = new TmfTimeRange(
+ trace2.getStartTime(),
+ calculateOffset(trace2.getStartTime(), trace2.getInitialRangeOffset()));
+ TmfTimeRange actualRange = tm.getCurrentRange();
+ assertEquals(expectedRange, actualRange);
+ }
+
+ /**
+ * Try selecting a timestamp contained inside the trace's range. The trace's
+ * current time should get updated correctly.
+ */
+ @Test
+ public void testNewTimestamp() {
+ openTrace(trace2);
+ ITmfTimestamp ts = new TmfTimestamp(t2start + ONE_SECOND, SCALE);
+ selectTimestamp(ts);
+
+ ITmfTimestamp afterTs = tm.getSelectionBeginTime();
+ assertEquals(ts, afterTs);
+ afterTs = tm.getSelectionEndTime();
+ assertEquals(ts, afterTs);
+ }
+
+ /**
+ * Try selecting a timestamp happening before the trace's start. The change
+ * should be ignored.
+ */
+ @Test
+ public void testTimestampBefore() {
+ openTrace(trace2);
+ ITmfTimestamp beforeTs = tm.getSelectionBeginTime();
+ ITmfTimestamp ts = new TmfTimestamp(t2start - ONE_SECOND, SCALE);
+ selectTimestamp(ts);
+
+ ITmfTimestamp curTs = tm.getSelectionBeginTime();
+ assertEquals(beforeTs, curTs);
+ curTs = tm.getSelectionEndTime();
+ assertEquals(beforeTs, curTs);
+ }
+
+ /**
+ * Try selecting a timestamp happening after the trace's end. The change
+ * should be ignored.
+ */
+ @Test
+ public void testTimestampAfter() {
+ openTrace(trace2);
+ ITmfTimestamp beforeTs = tm.getSelectionBeginTime();
+ ITmfTimestamp ts = new TmfTimestamp(t2end + ONE_SECOND, SCALE);
+ selectTimestamp(ts);
+
+ ITmfTimestamp curTs = tm.getSelectionBeginTime();
+ assertEquals(beforeTs, curTs);
+ curTs = tm.getSelectionEndTime();
+ assertEquals(beforeTs, curTs);
+ }
+
+ /**
+ * Test selecting a normal sub-range of a single trace.
+ */
+ @Test
+ public void testTraceNewTimeRange() {
+ openTrace(trace2);
+ TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t2start + ONE_SECOND, SCALE),
+ new TmfTimestamp(t2end - ONE_SECOND, SCALE));
+ selectTimeRange(range);
+
+ TmfTimeRange curRange = tm.getCurrentRange();
+ assertEquals(range.getStartTime(), curRange.getStartTime());
+ assertEquals(range.getEndTime(), curRange.getEndTime());
+ }
+
+ /**
+ * Test selecting a range whose start time is before the trace's start time.
+ * The selected range should get clamped to the trace's range.
+ */
+ @Test
+ public void testTraceTimeRangeClampingStart() {
+ openTrace(trace2);
+ TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t2start - ONE_SECOND, SCALE), // minus here
+ new TmfTimestamp(t2end - ONE_SECOND, SCALE));
+ selectTimeRange(range);
+
+ TmfTimeRange curRange = tm.getCurrentRange();
+ assertEquals(t2start, curRange.getStartTime().getValue());
+ assertEquals(range.getEndTime(), curRange.getEndTime());
+ }
+
+ /**
+ * Test selecting a range whose end time is after the trace's end time.
+ * The selected range should get clamped to the trace's range.
+ */
+ @Test
+ public void testTraceTimeRangeClampingEnd() {
+ openTrace(trace2);
+ TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t2start + ONE_SECOND, SCALE),
+ new TmfTimestamp(t2end + ONE_SECOND, SCALE)); // plus here
+ selectTimeRange(range);
+
+ TmfTimeRange curRange = tm.getCurrentRange();
+ assertEquals(range.getStartTime(), curRange.getStartTime());
+ assertEquals(t2end, curRange.getEndTime().getValue());
+ }
+
+ /**
+ * Test selecting a range whose both start and end times are outside of the
+ * trace's range. The selected range should get clamped to the trace's
+ * range.
+ */
+ @Test
+ public void testTraceTimeRangeClampingBoth() {
+ openTrace(trace2);
+ TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t2start - ONE_SECOND, SCALE), // minus here
+ new TmfTimestamp(t2end + ONE_SECOND, SCALE)); // plus here
+ selectTimeRange(range);
+
+ TmfTimeRange curRange = tm.getCurrentRange();
+ assertEquals(t2start, curRange.getStartTime().getValue());
+ assertEquals(t2end, curRange.getEndTime().getValue());
+ }
+
+ // ------------------------------------------------------------------------
+ // Test multiple, non-overlapping traces in parallel
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test, with two traces in parallel, when we select a timestamp that is
+ * part of the first trace.
+ *
+ * The first trace's timestamp should be updated, but the second trace's one
+ * should not change.
+ */
+ @Test
+ public void testTwoTracesTimestampValid() {
+ openTrace(trace1);
+ openTrace(trace2);
+ selectTrace(trace1);
+ TmfTimestamp ts = new TmfTimestamp(t1start + ONE_SECOND, SCALE);
+ selectTimestamp(ts);
+
+ /* Timestamp of trace1 should have been updated */
+ assertEquals(ts, tm.getSelectionBeginTime());
+ assertEquals(ts, tm.getSelectionEndTime());
+
+ /* Timestamp of trace2 should not have changed */
+ selectTrace(trace2);
+ assertEquals(trace2.getStartTime(), tm.getSelectionBeginTime());
+ assertEquals(trace2.getStartTime(), tm.getSelectionEndTime());
+ }
+
+ /**
+ * Test, with two traces in parallel, when we select a timestamp that is
+ * between two traces.
+ *
+ * None of the trace's timestamps should be updated (we are not in an
+ * experiment!)
+ */
+ @Test
+ public void testTwoTracesTimestampInBetween() {
+ openTrace(trace1);
+ openTrace(trace2);
+ selectTrace(trace1);
+ TmfTimestamp ts = new TmfTimestamp(t1end + ONE_SECOND, SCALE);
+ selectTimestamp(ts);
+
+ /* Timestamp of trace1 should not have changed */
+ assertEquals(trace1.getStartTime(), tm.getSelectionBeginTime());
+ assertEquals(trace1.getStartTime(), tm.getSelectionEndTime());
+
+ /* Timestamp of trace2 should not have changed */
+ selectTrace(trace2);
+ assertEquals(trace2.getStartTime(), tm.getSelectionBeginTime());
+ assertEquals(trace2.getStartTime(), tm.getSelectionEndTime());
+ }
+
+ /**
+ * Test, with two traces in parallel, when we select a timestamp that is
+ * completely out of the trace's range.
+ *
+ * None of the trace's timestamps should be updated.
+ */
+ @Test
+ public void testTwoTracesTimestampInvalid() {
+ openTrace(trace1);
+ openTrace(trace2);
+ selectTrace(trace1);
+ TmfTimestamp ts = new TmfTimestamp(t2end + ONE_SECOND, SCALE);
+ selectTimestamp(ts);
+
+ /* Timestamp of trace1 should not have changed */
+ assertEquals(trace1.getStartTime(), tm.getSelectionBeginTime());
+ assertEquals(trace1.getStartTime(), tm.getSelectionEndTime());
+
+ /* Timestamp of trace2 should not have changed */
+ selectTrace(trace2);
+ assertEquals(trace2.getStartTime(), tm.getSelectionBeginTime());
+ assertEquals(trace2.getStartTime(), tm.getSelectionEndTime());
+ }
+
+ /**
+ * Test, with two traces opened in parallel (not in an experiment), if we
+ * select a time range valid in one of them. That trace's time range should
+ * be updated, but not the other one.
+ */
+ @Test
+ public void testTwoTracesTimeRangeAllInOne() {
+ openTrace(trace1);
+ openTrace(trace2);
+ selectTrace(trace1);
+ TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t1start + ONE_SECOND, SCALE),
+ new TmfTimestamp(t1end - ONE_SECOND, SCALE));
+ selectTimeRange(range);
+
+ /* Range of trace1 should be equal to the requested one */
+ assertEquals(range, tm.getCurrentRange());
+
+ /* The range of trace 2 should not have changed */
+ selectTrace(trace2);
+ assertEquals(getInitialRange(trace2), tm.getCurrentRange());
+ }
+
+ /**
+ * Test, with two traces in parallel, when we select a time range that is
+ * only partially valid for one of the traces.
+ *
+ * The first trace's time range should be clamped to a valid range, and the
+ * second one's should not change.
+ */
+ @Test
+ public void testTwoTracesTimeRangePartiallyInOne() {
+ openTrace(trace1);
+ openTrace(trace2);
+ selectTrace(trace1);
+ TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t1start + ONE_SECOND, SCALE),
+ new TmfTimestamp(t1end + ONE_SECOND, SCALE));
+ selectTimeRange(range);
+
+ /* Range of trace1 should get clamped to its end time */
+ TmfTimeRange expectedRange = new TmfTimeRange(
+ new TmfTimestamp(t1start + ONE_SECOND, SCALE),
+ new TmfTimestamp(t1end, SCALE));
+ assertEquals(expectedRange, tm.getCurrentRange());
+
+ /* Range of trace2 should not have changed */
+ selectTrace(trace2);
+ assertEquals(getInitialRange(trace2), tm.getCurrentRange());
+ }
+
+ /**
+ * Test, with two traces in parallel, when we select a time range that is
+ * only partially valid for both traces.
+ *
+ * Each trace's time range should get clamped to respectively valid ranges.
+ */
+ @Test
+ public void testTwoTracesTimeRangeInBoth() {
+ openTrace(trace1);
+ openTrace(trace2);
+ selectTrace(trace1);
+ TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t1end - ONE_SECOND, SCALE),
+ new TmfTimestamp(t2start + ONE_SECOND, SCALE));
+ selectTimeRange(range);
+
+ /* Range of trace1 should be clamped to its end time */
+ TmfTimeRange expectedRange = new TmfTimeRange(
+ new TmfTimestamp(t1end - ONE_SECOND, SCALE),
+ new TmfTimestamp(t1end, SCALE));
+ assertEquals(expectedRange, tm.getCurrentRange());
+
+ /* Range of trace2 should be clamped to its start time */
+ selectTrace(trace2);
+ expectedRange = new TmfTimeRange(
+ new TmfTimestamp(t2start, SCALE),
+ new TmfTimestamp(t2start + ONE_SECOND, SCALE));
+ assertEquals(expectedRange, tm.getCurrentRange());
+ }
+
+ /**
+ * Test, with two traces in parallel, when we select a time range that is
+ * not valid for any trace.
+ *
+ * Each trace's time range should not be modified.
+ */
+ @Test
+ public void testTwoTracesTimeRangeInBetween() {
+ openTrace(trace1);
+ openTrace(trace2);
+ selectTrace(trace1);
+ TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t1end + ONE_SECOND, SCALE),
+ new TmfTimestamp(t1end - ONE_SECOND, SCALE));
+ selectTimeRange(range);
+
+ /* Range of trace1 should not have changed */
+ TmfTimeRange expectedRange = getInitialRange(trace1);
+ TmfTimeRange curRange = tm.getCurrentRange();
+ assertEquals(expectedRange.getStartTime(), curRange.getStartTime());
+ assertEquals(expectedRange.getEndTime(), curRange.getEndTime());
+
+ /* Range of trace2 should not have changed */
+ selectTrace(trace2);
+ expectedRange = getInitialRange(trace2);
+ curRange = tm.getCurrentRange();
+ assertEquals(expectedRange.getStartTime(), curRange.getStartTime());
+ assertEquals(expectedRange.getEndTime(), curRange.getEndTime());
+ }
+
+ // ------------------------------------------------------------------------
+ // Test an experiment
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test in an experiment when we select a timestamp that is part of one of
+ * the experiment's traces.
+ *
+ * The experiment's current time should be correctly updated.
+ */
+ @Test
+ public void testExperimentTimestampInTrace() {
+ TmfExperiment exp = createExperiment(trace1, trace2);
+ openTrace(exp);
+ TmfTimestamp ts = new TmfTimestamp(t1start + ONE_SECOND, SCALE);
+ selectTimestamp(ts);
+
+ /* The experiment's current time should be updated. */
+ assertEquals(ts, tm.getSelectionBeginTime());
+ assertEquals(ts, tm.getSelectionEndTime());
+ }
+
+ /**
+ * Test in an experiment when we select a timestamp that is between two
+ * traces in the experiment.
+ *
+ * The experiment's current time should still be updated, since the
+ * timestamp is valid in the experiment itself.
+ */
+ @Test
+ public void testExperimentTimestampInBetween() {
+ TmfExperiment exp = createExperiment(trace1, trace2);
+ openTrace(exp);
+ TmfTimestamp ts = new TmfTimestamp(t1end + ONE_SECOND, SCALE);
+ selectTimestamp(ts);
+
+ /* The experiment's current time should be updated. */
+ assertEquals(ts, tm.getSelectionBeginTime());
+ assertEquals(ts, tm.getSelectionEndTime());
+ }
+
+ /**
+ * Test in an experiment when we select a timestamp that is outside of the
+ * total range of the experiment.
+ *
+ * The experiment's current time should not be updated.
+ */
+ @Test
+ public void testExperimentTimestampInvalid() {
+ TmfExperiment exp = createExperiment(trace1, trace2);
+ openTrace(exp);
+ TmfTimestamp ts = new TmfTimestamp(t2end + ONE_SECOND, SCALE);
+ selectTimestamp(ts);
+
+ /* The experiment's current time should NOT be updated. */
+ assertEquals(trace1.getStartTime(), tm.getSelectionBeginTime());
+ assertEquals(trace1.getStartTime(), tm.getSelectionEndTime());
+ }
+
+ /**
+ * Test the initial range of an experiment.
+ */
+ @Test
+ public void testExperimentInitialRange() {
+ TmfExperiment exp = createExperiment(trace1, trace2);
+ openTrace(exp);
+ /*
+ * The initial range should be == to the initial range of the earliest
+ * trace (here trace1).
+ */
+ final TmfTimeRange actualRange = tm.getCurrentRange();
+
+ assertEquals(getInitialRange(trace1), actualRange);
+ assertEquals(getInitialRange(exp), actualRange);
+ }
+
+ /**
+ * Test the range clamping with the start time of the range outside of the
+ * earliest trace's range. Only that start time should get clamped.
+ */
+ @Test
+ public void testExperimentRangeClampingOne() {
+ TmfExperiment exp = createExperiment(trace1, trace2);
+ openTrace(exp);
+
+ final TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t1start - ONE_SECOND, SCALE),
+ new TmfTimestamp(t1end - ONE_SECOND, SCALE));
+ selectTimeRange(range);
+
+ TmfTimeRange actualRange = tm.getCurrentRange();
+ assertEquals(t1start, actualRange.getStartTime().getValue());
+ assertEquals(t1end - ONE_SECOND, actualRange.getEndTime().getValue());
+ }
+
+ /**
+ * Test the range clamping when both the start and end times of the signal's
+ * range are outside of the trace's range. The range should clamp to the
+ * experiment's range.
+ */
+ @Test
+ public void testExperimentRangeClampingBoth() {
+ TmfExperiment exp = createExperiment(trace1, trace2);
+ openTrace(exp);
+
+ final TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t1start - ONE_SECOND, SCALE),
+ new TmfTimestamp(t2end + ONE_SECOND, SCALE));
+ selectTimeRange(range);
+
+ TmfTimeRange actualRange = tm.getCurrentRange();
+ assertEquals(t1start, actualRange.getStartTime().getValue());
+ assertEquals(t2end, actualRange.getEndTime().getValue());
+ }
+
+ /**
+ * Test selecting a range in-between two disjoint traces in an experiment.
+ * The range should still get correctly selected, even if no trace has any
+ * events in that range.
+ */
+ @Test
+ public void testExperimentRangeInBetween() {
+ TmfExperiment exp = createExperiment(trace1, trace2);
+ openTrace(exp);
+
+ final TmfTimeRange range = new TmfTimeRange(
+ new TmfTimestamp(t1end + ONE_SECOND, SCALE),
+ new TmfTimestamp(t2start - ONE_SECOND, SCALE));
+ selectTimeRange(range);
+
+ TmfTimeRange actualRange = tm.getCurrentRange();
+ assertEquals(range, actualRange);
+ }
+
+ // ------------------------------------------------------------------------
+ // Utility methods
+ // ------------------------------------------------------------------------
+
+ private static TmfExperiment createExperiment(ITmfTrace t1, ITmfTrace t2) {
+ ITmfTrace[] traces = new ITmfTrace[] { t1, t2 };
+ TmfExperiment exp = new TmfExperiment(ITmfEvent.class, "test-exp", traces);
+ exp.indexTrace(true);
+ // Deregister experiment from signal manager so that it doesn't
+ // interfere with the TmfTraceManager tests
+ TmfSignalManager.deregister(exp);
+ return exp;
+ }
+
+ private static TmfTimeRange getInitialRange(ITmfTrace trace) {
+ return new TmfTimeRange(
+ trace.getStartTime(),
+ calculateOffset(trace.getStartTime(), trace.getInitialRangeOffset()));
+ }
+
+ /**
+ * Basically a "initial + offset" operation, but for ITmfTimetamp objects.
+ */
+ private static ITmfTimestamp calculateOffset(ITmfTimestamp initialTs, ITmfTimestamp offsetTs) {
+ long start = initialTs.normalize(0, SCALE).getValue();
+ long offset = offsetTs.normalize(0, SCALE).getValue();
+ return new TmfTimestamp(start + offset, SCALE);
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.timestamp;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ CtfTmfTimestampTest.class
+})
+public class AllTests {
+
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial generation with CodePro tools
+ * Alexandre Montplaisir - Clean up, consolidate redundant tests
+ * Patrick Tasse - Fix for local time zone
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.timestamp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.eclipse.tracecompass.tmf.ctf.core.timestamp.CtfTmfTimestamp;
+import org.junit.Test;
+
+/**
+ * The class <code>CtfTmfTimestampTest</code> contains tests for the class
+ * <code>{@link CtfTmfTimestamp}</code>.
+ *
+ * @author ematkho
+ * @version 1.0
+ */
+public class CtfTmfTimestampTest {
+
+ /**
+ * Run the CtfTmfTimestamp(long) constructor test.
+ */
+ @Test
+ public void testCtfTmfTimestamp() {
+ long timestamp = 1L;
+ DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS");
+ Date d = new Date(timestamp / 1000000);
+
+ CtfTmfTimestamp result = new CtfTmfTimestamp(timestamp);
+
+ assertNotNull(result);
+ assertEquals(df.format(d) + " 000 001", result.toString());
+ assertEquals(-9, result.getScale());
+ assertEquals(1L, result.getValue());
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.trace;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ CtfTmfTraceTest.class,
+ FunkyTraceTest.class
+})
+public class AllTests {
+
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial generation with CodePro tools
+ * Alexandre Montplaisir - Clean up, consolidate redundant tests
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.trace;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
+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.timestamp.CtfTmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>CtfTmfTraceTest</code> contains tests for the class
+ * <code>{@link CtfTmfTrace}</code>.
+ *
+ * @author ematkho
+ * @version 1.0
+ */
+public class CtfTmfTraceTest {
+
+ private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
+
+ private CtfTmfTrace fixture;
+
+ /**
+ * Perform pre-test initialization.
+ *
+ * @throws TmfTraceException
+ * If the test trace is not found
+ */
+ @Before
+ public void setUp() throws TmfTraceException {
+ assumeTrue(testTrace.exists());
+ fixture = new CtfTmfTrace();
+ fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
+ }
+
+ /**
+ * Perform post-test clean-up.
+ */
+ @After
+ public void tearDown() {
+ if (fixture != null) {
+ fixture.dispose();
+ }
+ }
+
+ /**
+ * Run the CtfTmfTrace() constructor test.
+ */
+ @Test
+ public void testCtfTmfTrace() {
+ try (CtfTmfTrace result = new CtfTmfTrace();) {
+ assertNotNull(result);
+ assertEquals(1000, result.getCacheSize());
+ assertEquals(0L, result.getNbEvents());
+ assertEquals(0L, result.getStreamingInterval());
+ assertNull(result.getResource());
+ assertNull(result.getType());
+ }
+ }
+
+ /**
+ * Test the parseEvent() method
+ */
+ @Test
+ public void testParseEvent() {
+ ITmfContext ctx = fixture.seekEvent(0);
+ fixture.getNext(ctx);
+ CtfTmfEvent event = fixture.parseEvent(ctx);
+ assertNotNull(event);
+ }
+
+ /**
+ * Run the void broadcast(TmfSignal) method test.
+ */
+ @Test
+ public void testBroadcast() {
+ TmfSignal signal = new TmfEndSynchSignal(1);
+ fixture.broadcast(signal);
+ }
+
+ /**
+ * Run the void dispose() method test.
+ */
+ @Test
+ public void testClose() {
+ try (CtfTmfTrace emptyFixture = new CtfTmfTrace();) {
+ }
+ }
+
+ /**
+ * Run the int getCacheSize() method test.
+ */
+ @Test
+ public void testGetCacheSize() {
+ try (CtfTmfTrace emptyFixture = new CtfTmfTrace();) {
+ int result = emptyFixture.getCacheSize();
+ assertEquals(1000, result);
+ }
+ }
+
+ /**
+ * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
+ */
+ @Test
+ public void testGetCurrentLocation() {
+ CtfLocation result = (CtfLocation) fixture.getCurrentLocation();
+ assertNull(result);
+ }
+
+ /**
+ * Test the seekEvent() method with a null location.
+ */
+ @Test
+ public void testSeekEventLoc_null() {
+ CtfLocation loc = null;
+ fixture.seekEvent(loc);
+ assertNotNull(fixture);
+ }
+
+ /**
+ * Test the seekEvent() method with a location from a timestamp.
+ */
+ @Test
+ public void testSeekEventLoc_timetamp() {
+ CtfLocation loc = new CtfLocation(new CtfTmfTimestamp(0L));
+ fixture.seekEvent(loc);
+ assertNotNull(fixture);
+ }
+
+ /**
+ * Run the ITmfTimestamp getEndTime() method test.
+ */
+ @Test
+ public void testGetEndTime() {
+ ITmfTimestamp result = fixture.getEndTime();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the String getEnvironment method test.
+ */
+ @Test
+ public void testGetEnvValue() {
+ String key = "tracer_name";
+ String result = fixture.getTraceProperties().get(key);
+ assertEquals("\"lttng-modules\"", result);
+ }
+
+ /**
+ * Test the {@link CtfTmfTrace#getEventType()} method.
+ */
+ @Test
+ public void testGetEventType() {
+ Class<?> result = fixture.getEventType();
+ assertNotNull(result);
+ assertEquals(CtfTmfEvent.class, result);
+ }
+
+ /**
+ * Run the Class<CtfTmfEvent> getContainedEventTypes() method test.
+ */
+ @Test
+ public void testGetContainedEventTypes() {
+ Set<? extends ITmfEventType> result = fixture.getContainedEventTypes();
+ assertNotNull(result);
+ assertFalse(result.isEmpty());
+ }
+
+ /**
+ * Run the double getLocationRatio(ITmfLocation<?>) method test.
+ */
+ @Test
+ public void testGetLocationRatio() {
+ final CtfLocationInfo location2 = new CtfLocationInfo(1, 0);
+ CtfLocation location = new CtfLocation(location2);
+ double result = fixture.getLocationRatio(location);
+
+ assertEquals(Double.NEGATIVE_INFINITY, result, 0.1);
+ }
+
+ /**
+ * Run the String getName() method test.
+ */
+ @Test
+ public void testGetName() {
+ String result = fixture.getName();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the getTraceProperties() method test.
+ */
+ @Test
+ public void testGetTraceProperties() {
+ int result = fixture.getTraceProperties().size();
+ assertEquals(9, result);
+ }
+
+ /**
+ * Run the long getNbEvents() method test.
+ */
+ @Test
+ public void testGetNbEvents() {
+ long result = fixture.getNbEvents();
+ assertEquals(1L, result);
+ }
+
+ /**
+ * Run the CtfTmfEvent getNext(ITmfContext) method test.
+ */
+ @Test
+ public void testGetNext() {
+ ITmfContext context = fixture.seekEvent(0);
+ CtfTmfEvent result = fixture.getNext(context);
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the String getPath() method test.
+ */
+ @Test
+ public void testGetPath() {
+ String result = fixture.getPath();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the IResource getResource() method test.
+ */
+ @Test
+ public void testGetResource() {
+ IResource result = fixture.getResource();
+ assertNull(result);
+ }
+
+ /**
+ * Run the ITmfTimestamp getStartTime() method test.
+ */
+ @Test
+ public void testGetStartTime() {
+ ITmfTimestamp result = fixture.getStartTime();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the long getStreamingInterval() method test.
+ */
+ @Test
+ public void testGetStreamingInterval() {
+ long result = fixture.getStreamingInterval();
+ assertEquals(0L, result);
+ }
+
+ /**
+ * Run the TmfTimeRange getTimeRange() method test.
+ */
+ @Test
+ public void testGetTimeRange() {
+ TmfTimeRange result = fixture.getTimeRange();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
+ */
+ @Test
+ public void testReadNextEvent() {
+ ITmfContext context = fixture.seekEvent(0);
+ CtfTmfEvent result = fixture.getNext(context);
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the ITmfContext seekEvent(double) method test.
+ */
+ @Test
+ public void testSeekEvent_ratio() {
+ double ratio = 0.99;
+ ITmfContext result = fixture.seekEvent(ratio);
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the ITmfContext seekEvent(long) method test.
+ */
+ @Test
+ public void testSeekEvent_rank() {
+ long rank = 1L;
+ ITmfContext result = fixture.seekEvent(rank);
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
+ */
+ @Test
+ public void testSeekEvent_timestamp() {
+ ITmfTimestamp timestamp = new TmfTimestamp();
+ ITmfContext result = fixture.seekEvent(timestamp);
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
+ */
+ @Test
+ public void testSeekEvent_location() {
+ final CtfLocationInfo location2 = new CtfLocationInfo(1L, 0L);
+ CtfLocation ctfLocation = new CtfLocation(location2);
+ ITmfContext result = fixture.seekEvent(ctfLocation);
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the boolean validate(IProject,String) method test.
+ */
+ @Test
+ public void testValidate() {
+ IProject project = null;
+ IStatus result = fixture.validate(project, testTrace.getPath());
+ assertTrue(result.isOK());
+ }
+
+ /**
+ * Run the boolean hasEvent(final String) method test
+ */
+ @Test
+ public void testEventLookup() {
+ Set<? extends ITmfEventType> eventTypes = fixture.getContainedEventTypes();
+ Set<String> eventNames = TmfEventTypeCollectionHelper.getEventNames(eventTypes);
+ assertTrue(eventNames.contains("sched_switch"));
+ assertFalse(eventNames.contains("Sched_switch"));
+ String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
+ assertTrue(eventNames.containsAll(Arrays.asList(events)));
+ Set<String> copy = new HashSet<>(eventNames);
+ copy.retainAll(Arrays.asList(events));
+ assertFalse(copy.isEmpty());
+ String[] names = { "inexistent", "sched_switch", "SomeThing" };
+ copy = new HashSet<>(eventNames);
+ copy.retainAll(Arrays.asList(names));
+ assertTrue(!copy.isEmpty());
+ assertFalse(eventNames.containsAll(Arrays.asList(names)));
+ }
+
+ /**
+ * Run the String getHostId() method test
+ */
+ @Test
+ public void testCtfHostId() {
+ String a = fixture.getHostId();
+ assertEquals("\"84db105b-b3f4-4821-b662-efc51455106a\"", a);
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.trace;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.ctf.core.CtfEnumPair;
+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.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
+
+/**
+ * More advanced CTF tests using "funky_trace", a trace generated with the
+ * Babeltrace CTF writer API, which has lots of fun things like different
+ * integer/float sizes and non-standard struct alignments.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class FunkyTraceTest {
+
+ /** Time-out tests after 20 seconds */
+ @Rule
+ public TestRule globalTimeout= new Timeout(20000);
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.FUNKY_TRACE;
+ private static final double DELTA = 0.0000001;
+
+ private CtfTmfTrace fTrace;
+
+ // ------------------------------------------------------------------------
+ // Setup
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test setup
+ */
+ @Before
+ public void setup() {
+ assumeTrue(testTrace.exists());
+ fTrace = testTrace.getTrace();
+ fTrace.indexTrace(true);
+ }
+
+ /**
+ * Clean-up
+ */
+ @After
+ public void tearDown() {
+ if (fTrace != null) {
+ fTrace.dispose();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Test methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * Verify the contents of the first event
+ */
+ @Test
+ public void testFirstEvent() {
+ CtfTmfEvent event = getEvent(0);
+ assertEquals("Simple Event", event.getType().getName());
+ assertEquals(1234567, event.getTimestamp().getValue());
+ assertEquals(42, ((Long) event.getContent().getField("integer_field").getValue()).intValue());
+ assertEquals(3.1415, ((Double) event.getContent().getField("float_field").getValue()).doubleValue(), DELTA);
+ }
+
+ /**
+ * Verify the contents of the second event (the first "spammy event")
+ */
+ @Test
+ public void testSecondEvent() {
+ CtfTmfEvent event = getEvent(1);
+ assertEquals("Spammy_Event", event.getType().getName());
+ assertEquals(1234568, event.getTimestamp().getValue());
+ assertEquals(0, ((Long) event.getContent().getField("field_1").getValue()).intValue());
+ assertEquals("This is a test", event.getContent().getField("a_string").getValue());
+ }
+
+ /**
+ * Verify the contents of the last "spammy event"
+ */
+ @Test
+ public void testSecondToLastEvent() {
+ CtfTmfEvent event = getEvent(100000);
+ assertEquals("Spammy_Event", event.getType().getName());
+ assertEquals(1334567, event.getTimestamp().getValue());
+ assertEquals(99999, ((Long) event.getContent().getField("field_1").getValue()).intValue());
+ assertEquals("This is a test", event.getContent().getField("a_string").getValue());
+ }
+
+ /**
+ * Verify the contents of the last, complex event
+ */
+ @Test
+ public void testLastEvent() {
+ /*
+ * Last event as seen in Babeltrace:
+ * [19:00:00.001334568] (+0.000000001) Complex Test Event: { }, {
+ * uint_35 = 0xDDF00D,
+ * int_16 = -12345,
+ * complex_structure = {
+ * variant_selector = ( INT16_TYPE : container = 1 ),
+ * a_string = "Test string",
+ * variant_value = { INT16_TYPE = -200 },
+ * inner_structure = {
+ * seq_len = 0xA,
+ * a_sequence = [ [0] = 4, [1] = 3, [2] = 2, [3] = 1, [4] = 0, [5] = -1, [6] = -2, [7] = -3, [8] = -4, [9] = -5 ]
+ * }
+ * }
+ * }
+ */
+
+ CtfTmfEvent event = getEvent(100001);
+ assertEquals("Complex Test Event", event.getType().getName());
+ assertEquals(1334568, event.getTimestamp().getValue());
+ assertEquals(0xddf00d, ((Long) event.getContent().getField("uint_35").getValue()).intValue());
+ assertEquals(-12345, ((Long) event.getContent().getField("int_16").getValue()).intValue());
+
+ ITmfEventField[] complexStruct =
+ (ITmfEventField[]) event.getContent().getField("complex_structure").getValue();
+
+ assertEquals("variant_selector", complexStruct[0].getName());
+ CtfEnumPair variant1 = (CtfEnumPair) complexStruct[0].getValue();
+ assertEquals("INT16_TYPE", variant1.getStringValue());
+ assertEquals(Long.valueOf(1), variant1.getLongValue());
+
+ assertEquals("a_string", complexStruct[1].getName());
+ assertEquals("Test string", complexStruct[1].getValue());
+
+ assertEquals("variant_value", complexStruct[2].getName());
+ ITmfEventField variantField = (ITmfEventField) complexStruct[2].getValue();
+ assertEquals("INT16_TYPE", variantField.getName());
+ assertEquals(Long.valueOf(-200), variantField.getValue());
+
+ ITmfEventField[] innerStruct = (ITmfEventField[]) complexStruct[3].getValue();
+
+ assertEquals("seq_len", innerStruct[0].getName());
+ assertEquals(Long.valueOf(10), innerStruct[0].getValue());
+
+ assertEquals("a_sequence", innerStruct[1].getName());
+ long[] seqValues = (long[]) innerStruct[1].getValue();
+ long[] expectedValues = { 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 };
+ assertArrayEquals(expectedValues, seqValues);
+ }
+
+ // ------------------------------------------------------------------------
+ // Private stuff
+ // ------------------------------------------------------------------------
+
+ private synchronized CtfTmfEvent getEvent(long index) {
+ TestEventRequest req = new TestEventRequest(index);
+ fTrace.sendRequest(req);
+ try {
+ req.waitForCompletion();
+ } catch (InterruptedException e) {
+ return null;
+ }
+ return req.getEvent();
+ }
+
+ private class TestEventRequest extends TmfEventRequest {
+
+ private CtfTmfEvent fRetEvent = null;
+
+ public TestEventRequest(long index) {
+ super(CtfTmfEvent.class,
+ TmfTimeRange.ETERNITY,
+ index,
+ 1,
+ ExecutionType.FOREGROUND);
+ }
+
+ @Override
+ public void handleData(ITmfEvent event) {
+ fRetEvent = (CtfTmfEvent) event;
+ }
+
+ public CtfTmfEvent getEvent() {
+ return fRetEvent;
+ }
+ }
+
+}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.tracemanager;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- TmfTraceManagerTest.class
-})
-public class AllTests {}
\ No newline at end of file
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- * Patrick Tasse - Support selection range
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core.tests.tracemanager;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assume.assumeTrue;
-
-import java.io.File;
-import java.util.Set;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.signal.TmfRangeSynchSignal;
-import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableSet;
-
-/**
- * Test suite for the {@link TmfTraceManager}.
- *
- * @author Alexandre Montplaisir
- */
-public class TmfTraceManagerTest {
-
- private static final int SCALE = ITmfTimestamp.NANOSECOND_SCALE;
-
- private static ITmfTrace trace1;
- private static final long t1start = 1331668247314038062L;
- private static final long t1end = 1331668259054285979L;
-
- private static ITmfTrace trace2;
- private static final long t2start = 1332170682440133097L;
- private static final long t2end = 1332170692664579801L;
-
- private static final long ONE_SECOND = 1000000000L;
-
- private TmfTraceManager tm;
-
-
- /**
- * Test class initialization
- */
- @BeforeClass
- public static void setUpClass() {
- assumeTrue(CtfTmfTestTrace.TRACE2.exists());
- assumeTrue(CtfTmfTestTrace.KERNEL.exists());
- trace1 = CtfTmfTestTrace.TRACE2.getTrace();
- trace2 = CtfTmfTestTrace.KERNEL.getTrace();
-
- trace1.indexTrace(true);
- trace2.indexTrace(true);
-
- // Deregister traces from signal manager so that they don't
- // interfere with the TmfTraceManager tests
- TmfSignalManager.deregister(trace1);
- TmfSignalManager.deregister(trace2);
- }
-
- /**
- * Test initialization
- */
- @Before
- public void setUp() {
- tm = TmfTraceManager.getInstance();
- }
-
- /**
- * Test clean-up
- */
- @After
- public void tearDown() {
- while (tm.getActiveTrace() != null) {
- closeTrace(tm.getActiveTrace());
- }
- }
-
- /**
- * Test class clean-up
- */
- @AfterClass
- public static void tearDownClass() {
- CtfTmfTestTrace.TRACE2.dispose();
- CtfTmfTestTrace.KERNEL.dispose();
- }
-
- // ------------------------------------------------------------------------
- // Dummy actions (fake signals)
- // ------------------------------------------------------------------------
-
- private void openTrace(ITmfTrace trace) {
- if (trace == null) {
- throw new IllegalArgumentException();
- }
- TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, trace, null));
- selectTrace(trace);
- }
-
- private void closeTrace(ITmfTrace trace) {
- if (trace == null) {
- throw new IllegalArgumentException();
- }
- TmfSignalManager.dispatchSignal(new TmfTraceClosedSignal(this, trace));
- /*
- * In TMF, the next tab would now be selected (if there are some), which
- * would select another trace automatically.
- */
- if (tm.getOpenedTraces().size() > 0) {
- selectTrace(tm.getOpenedTraces().toArray(new ITmfTrace[0])[0]);
- }
- }
-
- private void selectTrace(ITmfTrace trace) {
- TmfSignalManager.dispatchSignal(new TmfTraceSelectedSignal(this, trace));
- }
-
- private void selectTimestamp(ITmfTimestamp ts) {
- TmfSignalManager.dispatchSignal(new TmfTimeSynchSignal(this, ts));
- }
-
- private void selectTimeRange(TmfTimeRange tr) {
- TmfSignalManager.dispatchSignal(new TmfRangeSynchSignal(this, tr));
- }
-
- // ------------------------------------------------------------------------
- // General tests
- // ------------------------------------------------------------------------
-
- /**
- * Test that the manager is correctly initialized
- */
- @Test
- public void testInitialize() {
- TmfTraceManager mgr = TmfTraceManager.getInstance();
- assertNotNull(mgr);
- assertSame(tm, mgr);
- }
-
- /**
- * Test the contents of a trace set with one trace.
- */
- @Test
- public void testTraceSet() {
- openTrace(trace1);
- openTrace(trace2);
- selectTrace(trace2);
-
- ITmfTrace[] expected = new ITmfTrace[] { trace2 };
- ITmfTrace[] actual = tm.getActiveTraceSet();
-
- assertEquals(1, actual.length);
- assertArrayEquals(expected, actual);
- }
-
- /**
- * Test the contents of a trace set with an experiment.
- */
- @Test
- public void testTraceSetExperiment() {
- TmfExperiment exp = createExperiment(trace1, trace2);
- openTrace(trace1);
- openTrace(exp);
-
- ITmfTrace[] expected = new ITmfTrace[] { trace1, trace2 };
- ITmfTrace[] actual = tm.getActiveTraceSet();
-
- assertEquals(2, actual.length);
- assertArrayEquals(expected, actual);
- }
-
- /**
- * Test the contents of the complete trace set.
- */
- @Test
- public void testTraceSetWithExperiment() {
- /* Test with a trace */
- Set<ITmfTrace> expected = ImmutableSet.of(trace1);
- Set<ITmfTrace> actual = TmfTraceManager.getTraceSetWithExperiment(trace1);
- assertEquals(1, actual.size());
- assertEquals(expected, actual);
-
- /* Test with an experiment */
- TmfExperiment exp = createExperiment(trace1, trace2);
- expected = ImmutableSet.of(trace1, trace2, exp);
- actual = TmfTraceManager.getTraceSetWithExperiment(exp);
- assertEquals(3, actual.size());
- assertEquals(expected, actual);
- }
-
- /**
- * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
- */
- @Test
- public void testSupplementaryFileDir() {
- String name1 = trace1.getName();
- String name2 = trace2.getName();
- String basePath = TmfTraceManager.getTemporaryDirPath() + File.separator;
-
- String expected1 = basePath + name1 + File.separator;
- String expected2 = basePath + name2 + File.separator;
-
- assertEquals(expected1, TmfTraceManager.getSupplementaryFileDir(trace1));
- assertEquals(expected2, TmfTraceManager.getSupplementaryFileDir(trace2));
- }
-
- // ------------------------------------------------------------------------
- // Test a single trace
- // ------------------------------------------------------------------------
-
- /**
- * Test the initial range of a single trace.
- */
- @Test
- public void testTraceInitialRange() {
- openTrace(trace2);
- final TmfTimeRange expectedRange = new TmfTimeRange(
- trace2.getStartTime(),
- calculateOffset(trace2.getStartTime(), trace2.getInitialRangeOffset()));
- TmfTimeRange actualRange = tm.getCurrentRange();
- assertEquals(expectedRange, actualRange);
- }
-
- /**
- * Try selecting a timestamp contained inside the trace's range. The trace's
- * current time should get updated correctly.
- */
- @Test
- public void testNewTimestamp() {
- openTrace(trace2);
- ITmfTimestamp ts = new TmfTimestamp(t2start + ONE_SECOND, SCALE);
- selectTimestamp(ts);
-
- ITmfTimestamp afterTs = tm.getSelectionBeginTime();
- assertEquals(ts, afterTs);
- afterTs = tm.getSelectionEndTime();
- assertEquals(ts, afterTs);
- }
-
- /**
- * Try selecting a timestamp happening before the trace's start. The change
- * should be ignored.
- */
- @Test
- public void testTimestampBefore() {
- openTrace(trace2);
- ITmfTimestamp beforeTs = tm.getSelectionBeginTime();
- ITmfTimestamp ts = new TmfTimestamp(t2start - ONE_SECOND, SCALE);
- selectTimestamp(ts);
-
- ITmfTimestamp curTs = tm.getSelectionBeginTime();
- assertEquals(beforeTs, curTs);
- curTs = tm.getSelectionEndTime();
- assertEquals(beforeTs, curTs);
- }
-
- /**
- * Try selecting a timestamp happening after the trace's end. The change
- * should be ignored.
- */
- @Test
- public void testTimestampAfter() {
- openTrace(trace2);
- ITmfTimestamp beforeTs = tm.getSelectionBeginTime();
- ITmfTimestamp ts = new TmfTimestamp(t2end + ONE_SECOND, SCALE);
- selectTimestamp(ts);
-
- ITmfTimestamp curTs = tm.getSelectionBeginTime();
- assertEquals(beforeTs, curTs);
- curTs = tm.getSelectionEndTime();
- assertEquals(beforeTs, curTs);
- }
-
- /**
- * Test selecting a normal sub-range of a single trace.
- */
- @Test
- public void testTraceNewTimeRange() {
- openTrace(trace2);
- TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t2start + ONE_SECOND, SCALE),
- new TmfTimestamp(t2end - ONE_SECOND, SCALE));
- selectTimeRange(range);
-
- TmfTimeRange curRange = tm.getCurrentRange();
- assertEquals(range.getStartTime(), curRange.getStartTime());
- assertEquals(range.getEndTime(), curRange.getEndTime());
- }
-
- /**
- * Test selecting a range whose start time is before the trace's start time.
- * The selected range should get clamped to the trace's range.
- */
- @Test
- public void testTraceTimeRangeClampingStart() {
- openTrace(trace2);
- TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t2start - ONE_SECOND, SCALE), // minus here
- new TmfTimestamp(t2end - ONE_SECOND, SCALE));
- selectTimeRange(range);
-
- TmfTimeRange curRange = tm.getCurrentRange();
- assertEquals(t2start, curRange.getStartTime().getValue());
- assertEquals(range.getEndTime(), curRange.getEndTime());
- }
-
- /**
- * Test selecting a range whose end time is after the trace's end time.
- * The selected range should get clamped to the trace's range.
- */
- @Test
- public void testTraceTimeRangeClampingEnd() {
- openTrace(trace2);
- TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t2start + ONE_SECOND, SCALE),
- new TmfTimestamp(t2end + ONE_SECOND, SCALE)); // plus here
- selectTimeRange(range);
-
- TmfTimeRange curRange = tm.getCurrentRange();
- assertEquals(range.getStartTime(), curRange.getStartTime());
- assertEquals(t2end, curRange.getEndTime().getValue());
- }
-
- /**
- * Test selecting a range whose both start and end times are outside of the
- * trace's range. The selected range should get clamped to the trace's
- * range.
- */
- @Test
- public void testTraceTimeRangeClampingBoth() {
- openTrace(trace2);
- TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t2start - ONE_SECOND, SCALE), // minus here
- new TmfTimestamp(t2end + ONE_SECOND, SCALE)); // plus here
- selectTimeRange(range);
-
- TmfTimeRange curRange = tm.getCurrentRange();
- assertEquals(t2start, curRange.getStartTime().getValue());
- assertEquals(t2end, curRange.getEndTime().getValue());
- }
-
- // ------------------------------------------------------------------------
- // Test multiple, non-overlapping traces in parallel
- // ------------------------------------------------------------------------
-
- /**
- * Test, with two traces in parallel, when we select a timestamp that is
- * part of the first trace.
- *
- * The first trace's timestamp should be updated, but the second trace's one
- * should not change.
- */
- @Test
- public void testTwoTracesTimestampValid() {
- openTrace(trace1);
- openTrace(trace2);
- selectTrace(trace1);
- TmfTimestamp ts = new TmfTimestamp(t1start + ONE_SECOND, SCALE);
- selectTimestamp(ts);
-
- /* Timestamp of trace1 should have been updated */
- assertEquals(ts, tm.getSelectionBeginTime());
- assertEquals(ts, tm.getSelectionEndTime());
-
- /* Timestamp of trace2 should not have changed */
- selectTrace(trace2);
- assertEquals(trace2.getStartTime(), tm.getSelectionBeginTime());
- assertEquals(trace2.getStartTime(), tm.getSelectionEndTime());
- }
-
- /**
- * Test, with two traces in parallel, when we select a timestamp that is
- * between two traces.
- *
- * None of the trace's timestamps should be updated (we are not in an
- * experiment!)
- */
- @Test
- public void testTwoTracesTimestampInBetween() {
- openTrace(trace1);
- openTrace(trace2);
- selectTrace(trace1);
- TmfTimestamp ts = new TmfTimestamp(t1end + ONE_SECOND, SCALE);
- selectTimestamp(ts);
-
- /* Timestamp of trace1 should not have changed */
- assertEquals(trace1.getStartTime(), tm.getSelectionBeginTime());
- assertEquals(trace1.getStartTime(), tm.getSelectionEndTime());
-
- /* Timestamp of trace2 should not have changed */
- selectTrace(trace2);
- assertEquals(trace2.getStartTime(), tm.getSelectionBeginTime());
- assertEquals(trace2.getStartTime(), tm.getSelectionEndTime());
- }
-
- /**
- * Test, with two traces in parallel, when we select a timestamp that is
- * completely out of the trace's range.
- *
- * None of the trace's timestamps should be updated.
- */
- @Test
- public void testTwoTracesTimestampInvalid() {
- openTrace(trace1);
- openTrace(trace2);
- selectTrace(trace1);
- TmfTimestamp ts = new TmfTimestamp(t2end + ONE_SECOND, SCALE);
- selectTimestamp(ts);
-
- /* Timestamp of trace1 should not have changed */
- assertEquals(trace1.getStartTime(), tm.getSelectionBeginTime());
- assertEquals(trace1.getStartTime(), tm.getSelectionEndTime());
-
- /* Timestamp of trace2 should not have changed */
- selectTrace(trace2);
- assertEquals(trace2.getStartTime(), tm.getSelectionBeginTime());
- assertEquals(trace2.getStartTime(), tm.getSelectionEndTime());
- }
-
- /**
- * Test, with two traces opened in parallel (not in an experiment), if we
- * select a time range valid in one of them. That trace's time range should
- * be updated, but not the other one.
- */
- @Test
- public void testTwoTracesTimeRangeAllInOne() {
- openTrace(trace1);
- openTrace(trace2);
- selectTrace(trace1);
- TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t1start + ONE_SECOND, SCALE),
- new TmfTimestamp(t1end - ONE_SECOND, SCALE));
- selectTimeRange(range);
-
- /* Range of trace1 should be equal to the requested one */
- assertEquals(range, tm.getCurrentRange());
-
- /* The range of trace 2 should not have changed */
- selectTrace(trace2);
- assertEquals(getInitialRange(trace2), tm.getCurrentRange());
- }
-
- /**
- * Test, with two traces in parallel, when we select a time range that is
- * only partially valid for one of the traces.
- *
- * The first trace's time range should be clamped to a valid range, and the
- * second one's should not change.
- */
- @Test
- public void testTwoTracesTimeRangePartiallyInOne() {
- openTrace(trace1);
- openTrace(trace2);
- selectTrace(trace1);
- TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t1start + ONE_SECOND, SCALE),
- new TmfTimestamp(t1end + ONE_SECOND, SCALE));
- selectTimeRange(range);
-
- /* Range of trace1 should get clamped to its end time */
- TmfTimeRange expectedRange = new TmfTimeRange(
- new TmfTimestamp(t1start + ONE_SECOND, SCALE),
- new TmfTimestamp(t1end, SCALE));
- assertEquals(expectedRange, tm.getCurrentRange());
-
- /* Range of trace2 should not have changed */
- selectTrace(trace2);
- assertEquals(getInitialRange(trace2), tm.getCurrentRange());
- }
-
- /**
- * Test, with two traces in parallel, when we select a time range that is
- * only partially valid for both traces.
- *
- * Each trace's time range should get clamped to respectively valid ranges.
- */
- @Test
- public void testTwoTracesTimeRangeInBoth() {
- openTrace(trace1);
- openTrace(trace2);
- selectTrace(trace1);
- TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t1end - ONE_SECOND, SCALE),
- new TmfTimestamp(t2start + ONE_SECOND, SCALE));
- selectTimeRange(range);
-
- /* Range of trace1 should be clamped to its end time */
- TmfTimeRange expectedRange = new TmfTimeRange(
- new TmfTimestamp(t1end - ONE_SECOND, SCALE),
- new TmfTimestamp(t1end, SCALE));
- assertEquals(expectedRange, tm.getCurrentRange());
-
- /* Range of trace2 should be clamped to its start time */
- selectTrace(trace2);
- expectedRange = new TmfTimeRange(
- new TmfTimestamp(t2start, SCALE),
- new TmfTimestamp(t2start + ONE_SECOND, SCALE));
- assertEquals(expectedRange, tm.getCurrentRange());
- }
-
- /**
- * Test, with two traces in parallel, when we select a time range that is
- * not valid for any trace.
- *
- * Each trace's time range should not be modified.
- */
- @Test
- public void testTwoTracesTimeRangeInBetween() {
- openTrace(trace1);
- openTrace(trace2);
- selectTrace(trace1);
- TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t1end + ONE_SECOND, SCALE),
- new TmfTimestamp(t1end - ONE_SECOND, SCALE));
- selectTimeRange(range);
-
- /* Range of trace1 should not have changed */
- TmfTimeRange expectedRange = getInitialRange(trace1);
- TmfTimeRange curRange = tm.getCurrentRange();
- assertEquals(expectedRange.getStartTime(), curRange.getStartTime());
- assertEquals(expectedRange.getEndTime(), curRange.getEndTime());
-
- /* Range of trace2 should not have changed */
- selectTrace(trace2);
- expectedRange = getInitialRange(trace2);
- curRange = tm.getCurrentRange();
- assertEquals(expectedRange.getStartTime(), curRange.getStartTime());
- assertEquals(expectedRange.getEndTime(), curRange.getEndTime());
- }
-
- // ------------------------------------------------------------------------
- // Test an experiment
- // ------------------------------------------------------------------------
-
- /**
- * Test in an experiment when we select a timestamp that is part of one of
- * the experiment's traces.
- *
- * The experiment's current time should be correctly updated.
- */
- @Test
- public void testExperimentTimestampInTrace() {
- TmfExperiment exp = createExperiment(trace1, trace2);
- openTrace(exp);
- TmfTimestamp ts = new TmfTimestamp(t1start + ONE_SECOND, SCALE);
- selectTimestamp(ts);
-
- /* The experiment's current time should be updated. */
- assertEquals(ts, tm.getSelectionBeginTime());
- assertEquals(ts, tm.getSelectionEndTime());
- }
-
- /**
- * Test in an experiment when we select a timestamp that is between two
- * traces in the experiment.
- *
- * The experiment's current time should still be updated, since the
- * timestamp is valid in the experiment itself.
- */
- @Test
- public void testExperimentTimestampInBetween() {
- TmfExperiment exp = createExperiment(trace1, trace2);
- openTrace(exp);
- TmfTimestamp ts = new TmfTimestamp(t1end + ONE_SECOND, SCALE);
- selectTimestamp(ts);
-
- /* The experiment's current time should be updated. */
- assertEquals(ts, tm.getSelectionBeginTime());
- assertEquals(ts, tm.getSelectionEndTime());
- }
-
- /**
- * Test in an experiment when we select a timestamp that is outside of the
- * total range of the experiment.
- *
- * The experiment's current time should not be updated.
- */
- @Test
- public void testExperimentTimestampInvalid() {
- TmfExperiment exp = createExperiment(trace1, trace2);
- openTrace(exp);
- TmfTimestamp ts = new TmfTimestamp(t2end + ONE_SECOND, SCALE);
- selectTimestamp(ts);
-
- /* The experiment's current time should NOT be updated. */
- assertEquals(trace1.getStartTime(), tm.getSelectionBeginTime());
- assertEquals(trace1.getStartTime(), tm.getSelectionEndTime());
- }
-
- /**
- * Test the initial range of an experiment.
- */
- @Test
- public void testExperimentInitialRange() {
- TmfExperiment exp = createExperiment(trace1, trace2);
- openTrace(exp);
- /*
- * The initial range should be == to the initial range of the earliest
- * trace (here trace1).
- */
- final TmfTimeRange actualRange = tm.getCurrentRange();
-
- assertEquals(getInitialRange(trace1), actualRange);
- assertEquals(getInitialRange(exp), actualRange);
- }
-
- /**
- * Test the range clamping with the start time of the range outside of the
- * earliest trace's range. Only that start time should get clamped.
- */
- @Test
- public void testExperimentRangeClampingOne() {
- TmfExperiment exp = createExperiment(trace1, trace2);
- openTrace(exp);
-
- final TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t1start - ONE_SECOND, SCALE),
- new TmfTimestamp(t1end - ONE_SECOND, SCALE));
- selectTimeRange(range);
-
- TmfTimeRange actualRange = tm.getCurrentRange();
- assertEquals(t1start, actualRange.getStartTime().getValue());
- assertEquals(t1end - ONE_SECOND, actualRange.getEndTime().getValue());
- }
-
- /**
- * Test the range clamping when both the start and end times of the signal's
- * range are outside of the trace's range. The range should clamp to the
- * experiment's range.
- */
- @Test
- public void testExperimentRangeClampingBoth() {
- TmfExperiment exp = createExperiment(trace1, trace2);
- openTrace(exp);
-
- final TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t1start - ONE_SECOND, SCALE),
- new TmfTimestamp(t2end + ONE_SECOND, SCALE));
- selectTimeRange(range);
-
- TmfTimeRange actualRange = tm.getCurrentRange();
- assertEquals(t1start, actualRange.getStartTime().getValue());
- assertEquals(t2end, actualRange.getEndTime().getValue());
- }
-
- /**
- * Test selecting a range in-between two disjoint traces in an experiment.
- * The range should still get correctly selected, even if no trace has any
- * events in that range.
- */
- @Test
- public void testExperimentRangeInBetween() {
- TmfExperiment exp = createExperiment(trace1, trace2);
- openTrace(exp);
-
- final TmfTimeRange range = new TmfTimeRange(
- new TmfTimestamp(t1end + ONE_SECOND, SCALE),
- new TmfTimestamp(t2start - ONE_SECOND, SCALE));
- selectTimeRange(range);
-
- TmfTimeRange actualRange = tm.getCurrentRange();
- assertEquals(range, actualRange);
- }
-
- // ------------------------------------------------------------------------
- // Utility methods
- // ------------------------------------------------------------------------
-
- private static TmfExperiment createExperiment(ITmfTrace t1, ITmfTrace t2) {
- ITmfTrace[] traces = new ITmfTrace[] { t1, t2 };
- TmfExperiment exp = new TmfExperiment(ITmfEvent.class, "test-exp", traces);
- exp.indexTrace(true);
- // Deregister experiment from signal manager so that it doesn't
- // interfere with the TmfTraceManager tests
- TmfSignalManager.deregister(exp);
- return exp;
- }
-
- private static TmfTimeRange getInitialRange(ITmfTrace trace) {
- return new TmfTimeRange(
- trace.getStartTime(),
- calculateOffset(trace.getStartTime(), trace.getInitialRangeOffset()));
- }
-
- /**
- * Basically a "initial + offset" operation, but for ITmfTimetamp objects.
- */
- private static ITmfTimestamp calculateOffset(ITmfTimestamp initialTs, ITmfTimestamp offsetTs) {
- long start = initialTs.normalize(0, SCALE).getValue();
- long offset = offsetTs.normalize(0, SCALE).getValue();
- return new TmfTimestamp(start + offset, SCALE);
- }
-}
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
/**
* Dummy test ctf trace
org.eclipse.tracecompass.ctf.core;bundle-version="3.1.0",
org.eclipse.tracecompass.tmf.core;bundle-version="3.1.0"
Export-Package: org.eclipse.tracecompass.internal.tmf.ctf.core;x-internal:=true,
- org.eclipse.tracecompass.tmf.ctf.core
+ org.eclipse.tracecompass.tmf.ctf.core,
+ org.eclipse.tracecompass.tmf.ctf.core.context,
+ org.eclipse.tracecompass.tmf.ctf.core.event,
+ org.eclipse.tracecompass.tmf.ctf.core.event.lookup,
+ org.eclipse.tracecompass.tmf.ctf.core.timestamp,
+ org.eclipse.tracecompass.tmf.ctf.core.trace,
+ org.eclipse.tracecompass.tmf.ctf.core.trace.iterator
Import-Package: com.google.common.collect,
org.eclipse.emf.common.util
</category>
<type
category="org.eclipse.linuxtools.tmf.ctf.core.category.ctf"
- event_type="org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent"
+ event_type="org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent"
id="org.eclipse.linuxtools.tmf.ui.type.ctf"
isDirectory="true"
name="%tracetype.type.ctf"
- trace_type="org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace">
+ trace_type="org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace">
</type>
</extension>
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- * Florian Wininger - Performance improvements
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
-import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInputReader;
-import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
-import org.eclipse.tracecompass.internal.tmf.ctf.core.Activator;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
-
-/**
- * The CTF trace reader iterator.
- *
- * It doesn't reserve a file handle, so many iterators can be used without
- * worries of I/O errors or resource exhaustion.
- *
- * @author Matthew Khouzam
- */
-public class CtfIterator extends CTFTraceReader
- implements ITmfContext, Comparable<CtfIterator> {
-
- /** An invalid location */
- public static final CtfLocation NULL_LOCATION = new CtfLocation(CtfLocation.INVALID_LOCATION);
-
- private final CtfTmfTrace fTrace;
-
- private CtfLocation fCurLocation;
- private long fCurRank;
-
- private CtfLocation fPreviousLocation;
- private CtfTmfEvent fPreviousEvent;
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Create a new CTF trace iterator, which initially points at the first
- * event in the trace.
- *
- * @param trace
- * The trace to iterate over
- * @throws CTFReaderException
- * If the iterator couldn't not be instantiated, probably due to
- * a read error.
- */
- public CtfIterator(CtfTmfTrace trace) throws CTFReaderException {
- super(trace.getCTFTrace());
- fTrace = trace;
- if (hasMoreEvents()) {
- fCurLocation = new CtfLocation(trace.getStartTime());
- fCurRank = 0;
- } else {
- setUnknownLocation();
- }
- }
-
- /**
- * Create a new CTF trace iterator, which will initially point to the given
- * location/rank.
- *
- * @param trace
- * The trace to iterate over
- * @param ctfLocationData
- * The initial timestamp the iterator will be pointing to
- * @param rank
- * The initial rank
- * @throws CTFReaderException
- * If the iterator couldn't not be instantiated, probably due to
- * a read error.
- * @since 2.0
- */
- public CtfIterator(CtfTmfTrace trace, CtfLocationInfo ctfLocationData, long rank)
- throws CTFReaderException {
- super(trace.getCTFTrace());
-
- this.fTrace = trace;
- if (this.hasMoreEvents()) {
- this.fCurLocation = new CtfLocation(ctfLocationData);
- if (this.getCurrentEvent().getTimestamp().getValue() != ctfLocationData.getTimestamp()) {
- this.seek(ctfLocationData);
- this.fCurRank = rank;
- }
- } else {
- setUnknownLocation();
- }
- }
-
- @Override
- public void dispose() {
- close();
- }
-
- private void setUnknownLocation() {
- fCurLocation = NULL_LOCATION;
- fCurRank = UNKNOWN_RANK;
- }
-
- // ------------------------------------------------------------------------
- // Accessors
- // ------------------------------------------------------------------------
-
- /**
- * Return this iterator's trace.
- *
- * @return CtfTmfTrace The iterator's trace
- */
- public CtfTmfTrace getCtfTmfTrace() {
- return fTrace;
- }
-
- /**
- * Return the current event pointed to by the iterator.
- *
- * @return CtfTmfEvent The current event
- */
- public synchronized CtfTmfEvent getCurrentEvent() {
- final CTFStreamInputReader top = super.getPrio().peek();
- if (top != null) {
- if (!fCurLocation.equals(fPreviousLocation)) {
- fPreviousLocation = fCurLocation;
- fPreviousEvent = CtfTmfEventFactory.createEvent(top.getCurrentEvent(),
- top.getFilename(), fTrace);
- }
- return fPreviousEvent;
- }
- return null;
- }
-
- /**
- * Return the current timestamp location pointed to by the iterator.
- * This is the timestamp for use in CtfLocation, not the event timestamp.
- *
- * @return long The current timestamp location
- */
- public synchronized long getCurrentTimestamp() {
- final CTFStreamInputReader top = super.getPrio().peek();
- if (top != null) {
- long ts = top.getCurrentEvent().getTimestamp();
- return fTrace.getCTFTrace().timestampCyclesToNanos(ts);
- }
- return 0;
- }
-
- /**
- * Seek this iterator to a given location.
- *
- * @param ctfLocationData
- * The LocationData representing the position to seek to
- * @return boolean True if the seek was successful, false if there was an
- * error seeking.
- * @since 2.0
- */
- public synchronized boolean seek(CtfLocationInfo ctfLocationData) {
- boolean ret = false;
-
- /* Avoid the cost of seeking at the current location. */
- if (fCurLocation.getLocationInfo().equals(ctfLocationData)) {
- return super.hasMoreEvents();
- }
-
- /* Adjust the timestamp depending on the trace's offset */
- long currTimestamp = ctfLocationData.getTimestamp();
- final long offsetTimestamp = this.getCtfTmfTrace().getCTFTrace().timestampNanoToCycles(currTimestamp);
- try {
- if (offsetTimestamp < 0) {
- ret = super.seek(0L);
- } else {
- ret = super.seek(offsetTimestamp);
- }
- } catch (CTFReaderException e) {
- Activator.getDefault().logError(e.getMessage(), e);
- return false;
- }
- /*
- * Check if there is already one or more events for that timestamp, and
- * assign the location index correctly
- */
- long index = 0;
- final CtfTmfEvent currentEvent = this.getCurrentEvent();
- if (currentEvent != null) {
- currTimestamp = currentEvent.getTimestamp().getValue();
-
- for (long i = 0; i < ctfLocationData.getIndex(); i++) {
- if (currTimestamp == currentEvent.getTimestamp().getValue()) {
- index++;
- } else {
- index = 0;
- }
- this.advance();
- }
- } else {
- ret = false;
- }
- /* Seek the current location accordingly */
- if (ret) {
- fCurLocation = new CtfLocation(new CtfLocationInfo(getCurrentEvent().getTimestamp().getValue(), index));
- } else {
- fCurLocation = NULL_LOCATION;
- }
-
- return ret;
- }
-
- // ------------------------------------------------------------------------
- // CTFTraceReader
- // ------------------------------------------------------------------------
-
- @Override
- public boolean seek(long timestamp) {
- return seek(new CtfLocationInfo(timestamp, 0));
- }
-
- @Override
- public synchronized boolean advance() {
- boolean ret = false;
- try {
- ret = super.advance();
- } catch (CTFReaderException e) {
- Activator.getDefault().logError(e.getMessage(), e);
- }
-
- if (ret) {
- long timestamp = fCurLocation.getLocationInfo().getTimestamp();
- final long timestampValue = getCurrentTimestamp();
- if (timestamp == timestampValue) {
- long index = fCurLocation.getLocationInfo().getIndex();
- fCurLocation = new CtfLocation(timestampValue, index + 1);
- } else {
- fCurLocation = new CtfLocation(timestampValue, 0L);
- }
- } else {
- fCurLocation = NULL_LOCATION;
- }
- return ret;
- }
-
- // ------------------------------------------------------------------------
- // ITmfContext
- // ------------------------------------------------------------------------
-
- @Override
- public long getRank() {
- return fCurRank;
- }
-
- @Override
- public void setRank(long rank) {
- fCurRank = rank;
- }
-
- @Override
- public void increaseRank() {
- /* Only increase the rank if it's valid */
- if (hasValidRank()) {
- fCurRank++;
- }
- }
-
- @Override
- public boolean hasValidRank() {
- return (getRank() >= 0);
- }
-
- /**
- * @since 3.0
- */
- @Override
- public void setLocation(ITmfLocation location) {
- // FIXME alex: isn't there a cleaner way than a cast here?
- fCurLocation = (CtfLocation) location;
- seek(((CtfLocation) location).getLocationInfo());
- }
-
- @Override
- public CtfLocation getLocation() {
- return fCurLocation;
- }
-
- // ------------------------------------------------------------------------
- // Comparable
- // ------------------------------------------------------------------------
-
- @Override
- public int compareTo(final CtfIterator o) {
- if (getRank() < o.getRank()) {
- return -1;
- } else if (getRank() > o.getRank()) {
- return 1;
- }
- return 0;
- }
-
- // ------------------------------------------------------------------------
- // Object
- // ------------------------------------------------------------------------
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = (prime * result)
- + ((fTrace == null) ? 0 : fTrace.hashCode());
- result = (prime * result)
- + ((fCurLocation == null) ? 0 : fCurLocation.hashCode());
- result = (prime * result) + (int) (fCurRank ^ (fCurRank >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof CtfIterator)) {
- return false;
- }
- CtfIterator other = (CtfIterator) obj;
- if (fTrace == null) {
- if (other.fTrace != null) {
- return false;
- }
- } else if (!fTrace.equals(other.fTrace)) {
- return false;
- }
- if (fCurLocation == null) {
- if (other.fCurLocation != null) {
- return false;
- }
- } else if (!fCurLocation.equals(other.fCurLocation)) {
- return false;
- }
- if (fCurRank != other.fCurRank) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Renamed/extracted from CtfTraceManager
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Random;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * A CTF trace iterator manager.
- *
- * Each instance of {@link CtfTmfTrace} should possess one of these, which will
- * manage the iterators that are opened to read that trace. This will allow
- * controlling the number of opened file handles per trace.
- *
- * @author Matthew Khouzam
- */
-public class CtfIteratorManager {
- /*
- * Cache size. Under 1023 on linux32 systems. Number of file handles
- * created.
- */
- private final static int MAX_SIZE = 100;
-
- /** The map of the cache */
- private final HashMap<CtfTmfContext, CtfIterator> fMap;
-
- /** An array pointing to the same cache. this allows fast "random" accesses */
- private final ArrayList<CtfTmfContext> fRandomAccess;
-
- /** Lock for when we access the two previous data structures */
- private final Lock fAccessLock = new ReentrantLock();
-
- /** The parent trace */
- private final CtfTmfTrace fTrace;
-
- /** Random number generator */
- private final Random fRnd;
-
- /**
- * Constructor
- *
- * @param trace
- * The trace whose iterators this manager will manage
- */
- public CtfIteratorManager(CtfTmfTrace trace) {
- fMap = new HashMap<>();
- fRandomAccess = new ArrayList<>();
- fRnd = new Random(System.nanoTime());
- fTrace = trace;
- }
-
- /**
- * This needs explaining: the iterator table is effectively a cache.
- * Originally the contexts had a 1 to 1 structure with the file handles of a
- * trace. This failed since there is a limit to how many file handles we can
- * have opened simultaneously. Then a round-robin scheme was implemented,
- * this lead up to a two competing contexts syncing up and using the same
- * file handler, causing horrible slowdowns. Now a random replacement
- * algorithm is selected. This is the same as used by arm processors, and it
- * works quite well when many cores so this looks promising for very
- * multi-threaded systems.
- *
- * @param context
- * the context to look up
- * @return the iterator referring to the context
- */
- public CtfIterator getIterator(final CtfTmfContext context) {
- /*
- * if the element is in the map, we don't need to do anything else.
- */
- CtfIterator iter = fMap.get(context);
- if (iter == null) {
-
- fAccessLock.lock();
- try {
- /*
- * Assign an iterator to a context.
- */
- if (fRandomAccess.size() < MAX_SIZE) {
- /*
- * if we're not full yet, just add an element.
- */
- iter = fTrace.createIterator();
- addElement(context, iter);
-
- } else {
- /*
- * if we're full, randomly replace an element
- */
- iter = replaceRandomElement(context);
- }
- if (context.getLocation() != null) {
- final CtfLocationInfo location = (CtfLocationInfo) context.getLocation().getLocationInfo();
- iter.seek(location);
- }
- } finally {
- fAccessLock.unlock();
- }
- }
- return iter;
- }
-
- /**
- * Remove an iterator from this manager
- *
- * @param context
- * The context of the iterator to remove
- */
- public void removeIterator(CtfTmfContext context) {
- fAccessLock.lock();
- try {
- /* The try below is only to auto-call CtfIterator.close() */
- try (CtfIterator removed = fMap.remove(context)) {
- }
- fRandomAccess.remove(context);
-
- } finally {
- fAccessLock.unlock();
- }
- }
-
- /**
- * Add a pair of context and element to the hashmap and the arraylist.
- *
- * @param context
- * the context
- * @param elem
- * the iterator
- */
- private void addElement(final CtfTmfContext context,
- final CtfIterator elem) {
- fAccessLock.lock();
- try {
- fMap.put(context, elem);
- fRandomAccess.add(context);
-
- } finally {
- fAccessLock.unlock();
- }
- }
-
- /**
- * Replace a random element
- *
- * @param context
- * the context to swap in
- * @return the iterator of the removed elements.
- */
- private CtfIterator replaceRandomElement(final CtfTmfContext context) {
- /*
- * This needs some explanation too: We need to select a random victim
- * and remove it. The order of the elements is not important, so instead
- * of just calling arraylist.remove(element) which has an O(n)
- * complexity, we pick an random number. The element is swapped out of
- * the array and removed and replaced in the hashmap.
- */
- fAccessLock.lock(); // just in case, should only be called when already locked
- try {
- final int size = fRandomAccess.size();
- final int pos = fRnd.nextInt(size);
- final CtfTmfContext victim = fRandomAccess.get(pos);
- fRandomAccess.set(pos, context);
- final CtfIterator elem = fMap.remove(victim);
- fMap.put(context, elem);
- victim.dispose();
- return elem;
-
- } finally {
- fAccessLock.unlock();
- }
- }
-
- /**
- * Dispose this iterator manager, which will close all the remaining
- * iterators.
- */
- public void dispose() {
- fAccessLock.lock();
- try {
- for (CtfIterator iterator : fMap.values()) {
- iterator.dispose();
- }
- fMap.clear();
- fRandomAccess.clear();
-
- } finally {
- fAccessLock.unlock();
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- * Alexandre Montplaisir - Extends TmfLocation
- *******************************************************************************/
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import java.nio.ByteBuffer;
-
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.trace.location.TmfLocation;
-
-/**
- * The nugget of information that is unique to a location in a CTF trace.
- *
- * It can be copied and used to restore a position in a given trace.
- *
- * @version 1.0
- * @author Matthew Khouzam
- */
-public final class CtfLocation extends TmfLocation {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- /**
- * An invalid location
- */
- public static final CtfLocationInfo INVALID_LOCATION = new CtfLocationInfo(-1, -1);
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Basic constructor for CtfLocation. Uses a default index of 0.
- *
- * @param timestamp
- * The timestamp of this location
- * @since 2.0
- */
- public CtfLocation(final ITmfTimestamp timestamp) {
- this(timestamp.getValue(), 0);
- }
-
- /**
- * Constructor using timestamp object and index
- *
- * @param timestamp
- * The timestamp of this location
- * @param index
- * The index of this location for this timestamp
- * @since 2.0
- */
- public CtfLocation(final ITmfTimestamp timestamp, long index) {
- this(timestamp.getValue(), index);
- }
-
- /**
- * Constructor using a long value for the timestamp, and an index
- *
- * @param timestampValue
- * The new timestamp
- * @param index
- * The new index
- * @since 2.0
- */
- public CtfLocation(final long timestampValue, final long index) {
- super(new CtfLocationInfo(timestampValue, index));
- }
-
- /**
- * Constructor using a pre-made locationInfo object
- *
- * @param locationInfo
- * The locationInfo object to use
- * @since 2.0
- */
- public CtfLocation(CtfLocationInfo locationInfo) {
- super(locationInfo);
- }
-
- /**
- * Copy constructor
- *
- * @param location
- * Other location to copy
- * @since 2.0
- */
- public CtfLocation(final CtfLocation location) {
- super(location);
- }
-
- // ------------------------------------------------------------------------
- // TmfLocation
- // ------------------------------------------------------------------------
-
- /**
- * Construct the location from the ByteBuffer.
- *
- * @param bufferIn
- * the buffer to read from
- *
- * @since 3.0
- */
- public CtfLocation(ByteBuffer bufferIn) {
- super(new CtfLocationInfo(bufferIn));
- }
-
- /**
- * @since 2.0
- */
- @Override
- public CtfLocationInfo getLocationInfo() {
- return (CtfLocationInfo) super.getLocationInfo();
- }
-
- // ------------------------------------------------------------------------
- // Object
- // ------------------------------------------------------------------------
-
- @Override
- public String toString() {
- if (getLocationInfo().equals(CtfLocation.INVALID_LOCATION )) {
- return getClass().getSimpleName() + " [INVALID]"; //$NON-NLS-1$
- }
- return super.toString();
- }
-
- /**
- * Constructs the location from the ByteBuffer. This typically happens when reading from disk.
- *
- * @since 3.0
- */
- @Override
- public void serialize(ByteBuffer bufferOut) {
- getLocationInfo().serialize(bufferOut);
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import java.nio.ByteBuffer;
-
-/**
- * The data object to go in a {@link CtfLocation}.
- *
- * @author Matthew Khouzam
- * @since 2.0
- */
-public class CtfLocationInfo implements Comparable<CtfLocationInfo> {
-
- private final long fTimestamp;
- private final long fIndex;
-
- /**
- * @param ts
- * Timestamp
- * @param index
- * Index of this event (if there are N elements with the same
- * timestamp, which one is it.)
- */
- public CtfLocationInfo(long ts, long index) {
- fTimestamp = ts;
- fIndex = index;
- }
-
- /**
- * Construct the location from the ByteBuffer.
- *
- * @param bufferIn
- * the buffer to read from
- *
- * @since 3.0
- */
- public CtfLocationInfo(ByteBuffer bufferIn) {
- fTimestamp = bufferIn.getLong();
- fIndex = bufferIn.getLong();
- }
-
- /**
- * @return The timestamp
- */
- public long getTimestamp() {
- return fTimestamp;
- }
-
- /**
- * @return The index of the element
- */
- public long getIndex() {
- return fIndex;
- }
-
- // ------------------------------------------------------------------------
- // Object
- // ------------------------------------------------------------------------
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = (prime * result) + (int) (fIndex ^ (fIndex >>> 32));
- result = (prime * result) + (int) (fTimestamp ^ (fTimestamp >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof CtfLocationInfo)) {
- return false;
- }
- CtfLocationInfo other = (CtfLocationInfo) obj;
- if (fIndex != other.fIndex) {
- return false;
- }
- if (fTimestamp != other.fTimestamp) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return "Element [" + fTimestamp + '/' + fIndex + ']'; //$NON-NLS-1$
- }
-
- // ------------------------------------------------------------------------
- // Comparable
- // ------------------------------------------------------------------------
-
- @Override
- public int compareTo(CtfLocationInfo other) {
- if (fTimestamp > other.getTimestamp()) {
- return 1;
- }
- if (fTimestamp < other.getTimestamp()) {
- return -1;
- }
- if (fIndex > other.getIndex()) {
- return 1;
- }
- if (fIndex < other.getIndex()) {
- return -1;
- }
- return 0;
- }
-
- /**
- * Write the location to the ByteBuffer so that it can be saved to disk.
- *
- * @param bufferOut
- * the buffer to write to
- *
- * @since 3.0
- */
- public void serialize(ByteBuffer bufferOut) {
- bufferOut.putLong(fTimestamp);
- bufferOut.putLong(fIndex);
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Patrick Tasse - Initial API and implementation
- * Bernd Hufmann - Updated for new parent class
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import org.eclipse.tracecompass.ctf.core.event.CTFCallsite;
-import org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite;
-
-/**
- * CTF TMF call site information for source code lookup.
- *
- * @author Patrick Tasse
- * @since 2.0
- */
-public class CtfTmfCallsite extends TmfCallsite {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- /** The event name. */
- final private String fEventName;
-
- /** The instruction pointer. */
- final private long fInstructionPointer;
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Standard Constructor.
- *
- * @param callsite
- * - a CTF call site
- */
- CtfTmfCallsite(CTFCallsite callsite) {
- super(callsite.getFileName(), callsite.getFunctionName(), callsite.getLineNumber());
- fEventName = callsite.getEventName();
- fInstructionPointer = callsite.getIp();
- }
-
- // ------------------------------------------------------------------------
- // Accessors
- // ------------------------------------------------------------------------
-
- /**
- * Returns the event name of the call site.
- * @return the event name
- */
- public String getEventName() {
- return fEventName;
- }
-
- /**
- * Returns the instruction pointer of the call site.
- * @return the instruction pointer
- */
- public long getIntructionPointer() {
- return fInstructionPointer;
- }
-
- // ------------------------------------------------------------------------
- // Accessors
- // ------------------------------------------------------------------------
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((fEventName == null) ? 0 : fEventName.hashCode());
- result = prime * result + (int) (fInstructionPointer ^ (fInstructionPointer >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- CtfTmfCallsite other = (CtfTmfCallsite) obj;
- if (fEventName == null) {
- if (other.fEventName != null) {
- return false;
- }
- } else if (!fEventName.equals(other.fEventName)) {
- return false;
- }
- if (fInstructionPointer != other.fInstructionPointer) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return getEventName() + "@0x" + Long.toHexString(fInstructionPointer) + ": " + //$NON-NLS-1$ //$NON-NLS-2$
- getFileName() + ':' + Long.toString(getLineNumber()) + ' ' + getFileName() + "()"; //$NON-NLS-1$
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- * Simon Delisle - Remove the iterator in dispose()
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
-
-/**
- * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
- * a boxed Long, a long and an int.
- *
- * @author Matthew Khouzam
- * @version 1.0
- * @since 2.0
- */
-public class CtfTmfContext implements ITmfContext {
-
- // -------------------------------------------
- // Fields
- // -------------------------------------------
-
- private CtfLocation fCurLocation;
- private long fCurRank;
-
- private final CtfTmfTrace fTrace;
-
- // -------------------------------------------
- // Constructor
- // -------------------------------------------
-
- /**
- * Constructor
- *
- * @param ctfTmfTrace
- * the parent trace
- * @since 1.1
- */
- public CtfTmfContext(CtfTmfTrace ctfTmfTrace) {
- fTrace = ctfTmfTrace;
- fCurLocation = new CtfLocation(new CtfLocationInfo(0, 0));
- }
-
- // -------------------------------------------
- // TmfContext Overrides
- // -------------------------------------------
-
- @Override
- public long getRank() {
- return fCurRank;
- }
-
- /**
- * @since 3.0
- */
- @Override
- public synchronized ITmfLocation getLocation() {
- return fCurLocation;
- }
-
- @Override
- public boolean hasValidRank() {
- return fCurRank != CtfLocation.INVALID_LOCATION.getTimestamp();
- }
-
- /**
- * @since 3.0
- */
- @Override
- public synchronized void setLocation(ITmfLocation location) {
- fCurLocation = (CtfLocation) location;
- if (fCurLocation != null) {
- getIterator().seek(fCurLocation.getLocationInfo());
- }
- }
-
- @Override
- public void setRank(long rank) {
- fCurRank = rank;
-
- }
-
- @Override
- public void increaseRank() {
- if (hasValidRank()) {
- fCurRank++;
- }
- }
-
- // -------------------------------------------
- // CtfTmfTrace Helpers
- // -------------------------------------------
-
- /**
- * Gets the trace of this context.
- *
- * @return The trace of this context
- */
- public CtfTmfTrace getTrace() {
- return fTrace;
- }
-
- /**
- * Gets the current event. Wrapper to help CtfTmfTrace
- *
- * @return The event or null
- */
- public synchronized CtfTmfEvent getCurrentEvent() {
- return getIterator().getCurrentEvent();
- }
-
- /**
- * Advances to a the next event. Wrapper to help CtfTmfTrace
- *
- * @return success or not
- */
- public synchronized boolean advance() {
- final CtfLocationInfo curLocationData = fCurLocation.getLocationInfo();
- CtfIterator iterator = getIterator();
- boolean retVal = iterator.advance();
- CtfTmfEvent currentEvent = iterator.getCurrentEvent();
-
- if (currentEvent != null) {
- final long timestampValue = iterator.getCurrentTimestamp();
- if (curLocationData.getTimestamp() == timestampValue) {
- fCurLocation = new CtfLocation(timestampValue, curLocationData.getIndex() + 1);
- } else {
- fCurLocation = new CtfLocation(timestampValue, 0L);
- }
- } else {
- fCurLocation = new CtfLocation(CtfLocation.INVALID_LOCATION);
- }
-
- return retVal;
- }
-
- @Override
- public void dispose() {
- fTrace.getIteratorManager().removeIterator(this);
- }
-
- /**
- * Seeks to a given timestamp. Wrapper to help CtfTmfTrace
- *
- * @param timestamp
- * desired timestamp
- * @return success or not
- */
- public synchronized boolean seek(final long timestamp) {
- fCurLocation = new CtfLocation(timestamp, 0);
- return getIterator().seek(timestamp);
- }
-
- /**
- * Seeks to a given location. Wrapper to help CtfTmfTrace
- * @param location
- * unique location to find the event.
- *
- * @return success or not
- * @since 2.0
- */
- public synchronized boolean seek(final CtfLocationInfo location) {
- fCurLocation = new CtfLocation(location);
- return getIterator().seek(location);
- }
-
- // -------------------------------------------
- // Private helpers
- // -------------------------------------------
-
- /**
- * Get iterator, called every time to get an iterator, no local copy is
- * stored so that there is no need to "update"
- *
- * @return an iterator
- */
- private CtfIterator getIterator() {
- return fTrace.getIteratorManager().getIterator(this);
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- * Bernd Hufmann - Updated for source and model lookup interfaces
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.ctf.core.event.CTFCallsite;
-import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
-import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
-import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
-import org.eclipse.tracecompass.tmf.core.event.ITmfCustomAttributes;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
-import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup;
-import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-
-/**
- * A wrapper class around CTF's Event Definition/Declaration that maps all types
- * of Declaration to native Java types.
- *
- * @version 1.0
- * @author Alexandre Montplaisir
- * @since 2.0
- */
-public class CtfTmfEvent extends TmfEvent
- implements ITmfSourceLookup, ITmfModelLookup, ITmfCustomAttributes {
-
- // ------------------------------------------------------------------------
- // Constants
- // ------------------------------------------------------------------------
-
- private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- private final int fSourceCPU;
- private final long fTypeId;
- private final String fEventName;
- private final IEventDeclaration fEventDeclaration;
- @NonNull
- private final EventDefinition fEvent;
- private ITmfEventField fContent;
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Constructor used by {@link CtfTmfEventFactory#createEvent}
- */
- CtfTmfEvent(CtfTmfTrace trace, long rank, CtfTmfTimestamp timestamp,
- String fileName, int cpu, IEventDeclaration declaration, @NonNull EventDefinition eventDefinition) {
- super(trace,
- rank,
- timestamp,
- String.valueOf(cpu), // Source
- null, // Event type. We don't use TmfEvent's field here, we
- // re-implement getType()
- null, // Content handled with a lazy loaded re-implemented in
- // getContent()
- fileName // Reference
- );
-
- fEventDeclaration = declaration;
- fSourceCPU = cpu;
- fTypeId = declaration.getId().longValue();
- fEventName = declaration.getName();
- fEvent = eventDefinition;
-
- }
-
- /**
- * Inner constructor to create "null" events. Don't use this directly in
- * normal usage, use {@link CtfTmfEventFactory#getNullEvent(CtfTmfTrace)} to
- * get an instance of an empty event.
- *
- * There is no need to give higher visibility to this method than package
- * visible.
- *
- * @param trace
- * The trace associated with this event
- */
- CtfTmfEvent(CtfTmfTrace trace) {
- super(trace,
- ITmfContext.UNKNOWN_RANK,
- new CtfTmfTimestamp(-1),
- null,
- null,
- new TmfEventField("", null, new CtfTmfEventField[0]), //$NON-NLS-1$
- null);
- fSourceCPU = -1;
- fTypeId = -1;
- fEventName = EMPTY_CTF_EVENT_NAME;
- fEventDeclaration = null;
- fEvent = EventDefinition.NULL_EVENT;
- }
-
- /**
- * Default constructor. Do not use directly, but it needs to be present
- * because it's used in extension points, and the framework will use this
- * constructor to get the class type.
- */
- public CtfTmfEvent() {
- this(null);
- }
-
- // ------------------------------------------------------------------------
- // Getters/Setters/Predicates
- // ------------------------------------------------------------------------
-
- /**
- * Gets the cpu core the event was recorded on.
- *
- * @return The cpu id for a given source. In lttng it's from CPUINFO
- */
- public int getCPU() {
- return fSourceCPU;
- }
-
- /**
- * Return this event's ID, according to the trace's metadata.
- *
- * Watch out, this ID is not constant from one trace to another for the same
- * event types! Use "getEventName()" for a constant reference.
- *
- * @return The event ID
- */
- public long getID() {
- return fTypeId;
- }
-
- @Override
- public CtfTmfTrace getTrace() {
- /*
- * Should be of the right type, since we take a CtfTmfTrace at the
- * constructor
- */
- return (CtfTmfTrace) super.getTrace();
- }
-
- @Override
- public ITmfEventType getType() {
- CtfTmfEventType ctfTmfEventType = new CtfTmfEventType(fEventName, getContent());
-
- /* Register the event type in the owning trace, but only if there is one */
- CtfTmfTrace trace = getTrace();
- trace.registerEventType(ctfTmfEventType);
-
- return ctfTmfEventType;
- }
-
- /**
- * @since 2.0
- */
- @Override
- public Set<String> listCustomAttributes() {
- if (fEventDeclaration == null) {
- return new HashSet<>();
- }
- return fEventDeclaration.getCustomAttributes();
- }
-
- /**
- * @since 2.0
- */
- @Override
- public String getCustomAttribute(String name) {
- if (fEventDeclaration == null) {
- return null;
- }
- return fEventDeclaration.getCustomAttribute(name);
- }
-
- /**
- * Get the call site for this event.
- *
- * @return the call site information, or null if there is none
- * @since 2.0
- */
- @Override
- public CtfTmfCallsite getCallsite() {
- CTFCallsite callsite = null;
- CtfTmfTrace trace = getTrace();
- CTFTrace ctfTrace = trace.getCTFTrace();
- /* Should not happen, but it is a good check */
- if (ctfTrace == null) {
- return null;
- }
- if (getContent() != null) {
- ITmfEventField ipField = getContent().getField(CtfConstants.CONTEXT_FIELD_PREFIX + CtfConstants.IP_KEY);
- if (ipField != null && ipField.getValue() instanceof Long) {
- long ip = (Long) ipField.getValue();
- callsite = ctfTrace.getCallsite(fEventName, ip);
- }
- }
- if (callsite == null) {
- callsite = ctfTrace.getCallsite(fEventName);
- }
- if (callsite != null) {
- return new CtfTmfCallsite(callsite);
- }
- return null;
- }
-
- /**
- * @since 2.0
- */
- @Override
- public String getModelUri() {
- return getCustomAttribute(CtfConstants.MODEL_URI_KEY);
- }
-
- @Override
- public synchronized ITmfEventField getContent() {
- if (fContent == null) {
- fContent = new TmfEventField(
- ITmfEventField.ROOT_FIELD_ID, null, parseFields(fEvent));
- }
- return fContent;
- }
-
- /**
- * Extract the field information from the structDefinition haze-inducing
- * mess, and put them into something ITmfEventField can cope with.
- */
- private static CtfTmfEventField[] parseFields(@NonNull EventDefinition eventDef) {
- List<CtfTmfEventField> fields = new ArrayList<>();
-
- ICompositeDefinition structFields = eventDef.getFields();
- if (structFields != null) {
- if (structFields.getFieldNames() != null) {
- for (String curFieldName : structFields.getFieldNames()) {
- fields.add(CtfTmfEventField.parseField((IDefinition) structFields.getDefinition(curFieldName), curFieldName));
- }
- }
- }
- /* Add context information as CtfTmfEventField */
- ICompositeDefinition structContext = eventDef.getContext();
- if (structContext != null) {
- for (String contextName : structContext.getFieldNames()) {
- /* Prefix field name */
- String curContextName = CtfConstants.CONTEXT_FIELD_PREFIX + contextName;
- fields.add(CtfTmfEventField.parseField((IDefinition) structContext.getDefinition(contextName), curContextName));
- }
- }
-
- return fields.toArray(new CtfTmfEventField[fields.size()]);
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.ctf.core.CTFStrings;
-import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
-import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-
-/**
- * Factory for CtfTmfEvent's.
- *
- * This code was moved out of CtfTmfEvent to provide better separation between
- * the parsing/instantiation of events, and the usual TMF API implementations.
- *
- * @author Alexandre Montplaisir
- * @since 2.0
- */
-public final class CtfTmfEventFactory {
-
- private static final String NO_STREAM = "No stream"; //$NON-NLS-1$
-
- /**
- * Don't let anyone instantiate this class.
- */
- private CtfTmfEventFactory() {}
-
- /**
- * Factory method to instantiate new {@link CtfTmfEvent}'s.
- *
- * @param eventDef
- * CTF EventDefinition object corresponding to this trace event
- * @param fileName
- * The path to the trace file
- * @param originTrace
- * The trace from which this event originates
- * @return The newly-built CtfTmfEvent
- */
- public static CtfTmfEvent createEvent(EventDefinition eventDef,
- String fileName, CtfTmfTrace originTrace) {
-
- /* Prepare what to pass to CtfTmfEvent's constructor */
- final IEventDeclaration eventDecl = eventDef.getDeclaration();
- final long ts = eventDef.getTimestamp();
- final CtfTmfTimestamp timestamp = originTrace.createTimestamp(
- originTrace.getCTFTrace().timestampCyclesToNanos(ts));
-
- int sourceCPU = eventDef.getCPU();
-
- String reference = fileName == null ? NO_STREAM : fileName;
-
- /* Handle the special case of lost events */
- if (eventDecl.getName().equals(CTFStrings.LOST_EVENT_NAME)) {
- IDefinition nbLostEventsDef = eventDef.getFields().getDefinition(CTFStrings.LOST_EVENTS_FIELD);
- IDefinition durationDef = eventDef.getFields().getDefinition(CTFStrings.LOST_EVENTS_DURATION);
- if (!(nbLostEventsDef instanceof IntegerDefinition) || !(durationDef instanceof IntegerDefinition)) {
- /*
- * One or both of these fields doesn't exist, or is not of the
- * right type. The event claims to be a "lost event", but is
- * malformed. Log it and return a null event instead.
- */
- return getNullEvent(originTrace);
- }
- long nbLostEvents = ((IntegerDefinition) nbLostEventsDef).getValue();
- long duration = ((IntegerDefinition) durationDef).getValue();
- CtfTmfTimestamp timestampEnd = new CtfTmfTimestamp(
- originTrace.getCTFTrace().timestampCyclesToNanos(ts) + duration);
-
- CtfTmfLostEvent lostEvent = new CtfTmfLostEvent(originTrace,
- ITmfContext.UNKNOWN_RANK,
- reference, // filename
- sourceCPU,
- eventDecl,
- new TmfTimeRange(timestamp, timestampEnd),
- nbLostEvents,
- eventDef);
- return lostEvent;
- }
-
- /* Handle standard event types */
- CtfTmfEvent event = new CtfTmfEvent(
- originTrace,
- ITmfContext.UNKNOWN_RANK,
- timestamp,
- reference, // filename
- sourceCPU,
- eventDecl,
- eventDef);
- return event;
- }
-
- /* Singleton instance of a null event */
- private static CtfTmfEvent nullEvent = null;
-
- /**
- * Get an instance of a null event.
- *
- * @param trace
- * A trace to associate with this null event
- * @return An empty event
- */
- public static CtfTmfEvent getNullEvent(@NonNull CtfTmfTrace trace) {
- if (nullEvent == null) {
- nullEvent = new CtfTmfEvent(trace);
- }
- return nullEvent;
- }
-
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011, 2014 Ericsson, École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- * Alexandre Montplaisir - Initial API and implementation, extend TmfEventField
- * Bernd Hufmann - Add Enum field handling
- * Geneviève Bastien - Add Struct and Variant field handling
- * Jean-Christian Kouame - Correct handling of unsigned integer fields
- * François Doray - Add generic array field type
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.tracecompass.ctf.core.event.types.CompoundDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.Definition;
-import org.eclipse.tracecompass.ctf.core.event.types.EnumDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.FloatDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.StringDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.VariantDefinition;
-import org.eclipse.tracecompass.internal.ctf.core.event.types.ArrayDefinition;
-import org.eclipse.tracecompass.internal.ctf.core.event.types.ByteArrayDefinition;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
-
-/**
- * The CTF implementation of the TMF event field model
- *
- * @version 2.0
- * @author Matthew Khouzam
- * @author Alexandre Montplaisir
- */
-public abstract class CtfTmfEventField extends TmfEventField {
-
- // ------------------------------------------------------------------------
- // Constructor
- // ------------------------------------------------------------------------
-
- /**
- * Standard constructor. Only to be used internally, call parseField() to
- * generate a new field object.
- *
- * @param name
- * The name of this field
- * @param value
- * The value of this field. Its type should match the field type.
- * @param fields
- * The children fields. Useful for composite fields
- * @since 2.0
- */
- protected CtfTmfEventField(String name, Object value, ITmfEventField[] fields) {
- super(/* Strip the underscore from the field name if there is one */
- name.startsWith("_") ? name.substring(1) : name, //$NON-NLS-1$
- value,
- fields);
- }
-
- // ------------------------------------------------------------------------
- // Operations
- // ------------------------------------------------------------------------
-
- /**
- * Factory method to instantiate CtfTmfEventField objects.
- *
- * @param fieldDef
- * The CTF Definition of this event field
- * @param fieldName
- * String The name to assign to this field
- * @return The resulting CtfTmfEventField object
- * @deprecated use {@link CtfTmfEventField#parseField(IDefinition, String)}
- */
- @Deprecated
- public static CtfTmfEventField parseField(Definition fieldDef,
- String fieldName) {
- return parseField((IDefinition) fieldDef, fieldName);
- }
-
- /**
- * Factory method to instantiate CtfTmfEventField objects.
- *
- * @param fieldDef
- * The CTF Definition of this event field
- * @param fieldName
- * String The name to assign to this field
- * @return The resulting CtfTmfEventField object
- * @since 3.1
- */
- public static CtfTmfEventField parseField(IDefinition fieldDef,
- String fieldName) {
- CtfTmfEventField field = null;
-
- /* Determine the Definition type */
- if (fieldDef instanceof IntegerDefinition) {
- IntegerDefinition intDef = (IntegerDefinition) fieldDef;
- int base = intDef.getDeclaration().getBase();
- field = new CTFIntegerField(fieldName, intDef.getValue(), base, intDef.getDeclaration().isSigned());
-
- } else if (fieldDef instanceof EnumDefinition) {
- EnumDefinition enumDef = (EnumDefinition) fieldDef;
- field = new CTFEnumField(fieldName, new CtfEnumPair(enumDef.getValue(), enumDef.getIntegerValue()));
-
- } else if (fieldDef instanceof StringDefinition) {
- field = new CTFStringField(fieldName, ((StringDefinition) fieldDef).getValue());
-
- } else if (fieldDef instanceof FloatDefinition) {
- FloatDefinition floatDef = (FloatDefinition) fieldDef;
- field = new CTFFloatField(fieldName, floatDef.getValue());
-
- } else if (fieldDef instanceof ArrayDefinition) {
- ArrayDefinition arrayDef = (ArrayDefinition) fieldDef;
- IDeclaration decl = arrayDef.getDeclaration();
- if (!(decl instanceof CompoundDeclaration)) {
- throw new IllegalArgumentException("Array definitions should only come from sequence or array declarations"); //$NON-NLS-1$
- }
- CompoundDeclaration arrDecl = (CompoundDeclaration) decl;
- IDeclaration elemType = null;
- Collection<Definition> definitions = arrayDef.getDefinitions();
- elemType = arrDecl.getElementType();
- if (elemType instanceof IntegerDeclaration) {
- /* Array of integers => CTFIntegerArrayField, unless it's a CTFStringField */
- IntegerDeclaration elemIntType = (IntegerDeclaration) elemType;
- /* Are the integers characters and encoded? */
- if (elemIntType.isCharacter()) {
- /* it's a CTFStringField */
- field = new CTFStringField(fieldName, arrayDef.toString());
- } else {
- /* it's a CTFIntegerArrayField */
- long[] values = new long[arrayDef.getLength()];
- for (int i = 0; i < arrayDef.getLength(); i++) {
- IDefinition elem = arrayDef.getDefinitions().get(i);
- if (elem == null) {
- break;
- }
- values[i] = ((IntegerDefinition) elem).getValue();
- }
- field = new CTFIntegerArrayField(fieldName, values,
- elemIntType.getBase(),
- elemIntType.isSigned());
- }
- } else {
- /* Arrays of elements of any other type */
- CtfTmfEventField[] elements = new CtfTmfEventField[arrayDef.getLength()];
- /* Parse the elements of the array. */
- int i = 0;
- for (IDefinition definition : definitions) {
- CtfTmfEventField curField = CtfTmfEventField.parseField(
- definition, fieldName + '[' + i + ']');
- elements[i] = curField;
- i++;
- }
-
- field = new CTFArrayField(fieldName, elements);
- }
- } else if (fieldDef instanceof ByteArrayDefinition) {
- /* This is an array of ascii bytes, a.k.a. a String! */
- field = new CTFStringField(fieldName, fieldDef.toString());
-
- } else if (fieldDef instanceof ICompositeDefinition) {
- ICompositeDefinition strDef = (ICompositeDefinition) fieldDef;
-
- List<ITmfEventField> list = new ArrayList<>();
- /* Recursively parse the fields */
- for (String curFieldName : strDef.getFieldNames()) {
- list.add(CtfTmfEventField.parseField(strDef.getDefinition(curFieldName), curFieldName));
- }
- field = new CTFStructField(fieldName, list.toArray(new CtfTmfEventField[list.size()]));
-
- } else if (fieldDef instanceof VariantDefinition) {
- VariantDefinition varDef = (VariantDefinition) fieldDef;
-
- String curFieldName = varDef.getCurrentFieldName();
- IDefinition curFieldDef = varDef.getCurrentField();
- if (curFieldDef != null) {
- CtfTmfEventField subField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
- field = new CTFVariantField(fieldName, subField);
- } else {
- /* A safe-guard, but curFieldDef should never be null */
- field = new CTFStringField(curFieldName, ""); //$NON-NLS-1$
- }
-
- } else {
- /*
- * Safe-guard, to avoid null exceptions later, field is expected not
- * to be null
- */
- field = new CTFStringField(fieldName, Messages.CtfTmfEventField_UnsupportedType + fieldDef.getClass().toString());
- }
- return field;
- }
-
- @Override
- public String toString() {
- return getName() + '=' + getFormattedValue();
- }
-
-}
-
-/**
- * The CTF field implementation for integer fields.
- *
- * @author alexmont
- */
-final class CTFIntegerField extends CtfTmfEventField {
-
- private final int fBase;
- private final boolean fSigned;
-
- /**
- * A CTF "IntegerDefinition" can be an integer of any byte size, so in the
- * Java parser this is interpreted as a long.
- *
- * @param name
- * The name of this field
- * @param longValue
- * The integer value of this field
- * @param signed
- * Is the value signed or not
- */
- CTFIntegerField(String name, long longValue, int base, boolean signed) {
- super(name, longValue, null);
- fSigned = signed;
- fBase = base;
- }
-
- @Override
- public Long getValue() {
- return (Long) super.getValue();
- }
-
- @Override
- public String getFormattedValue() {
- return IntegerDefinition.formatNumber(getValue(), fBase, fSigned);
- }
-
-}
-
-/**
- * The CTF field implementation for string fields
- *
- * @author alexmont
- */
-final class CTFStringField extends CtfTmfEventField {
-
- /**
- * Constructor for CTFStringField.
- *
- * @param strValue
- * The string value of this field
- * @param name
- * The name of this field
- */
- CTFStringField(String name, String strValue) {
- super(name, strValue, null);
- }
-
- @Override
- public String getValue() {
- return (String) super.getValue();
- }
-}
-
-/**
- * CTF field implementation for arrays of integers.
- *
- * @author alexmont
- */
-final class CTFIntegerArrayField extends CtfTmfEventField {
-
- private final int fBase;
- private final boolean fSigned;
- private String fFormattedValue = null;
-
- /**
- * Constructor for CTFIntegerArrayField.
- *
- * @param name
- * The name of this field
- * @param longValues
- * The array of integers (as longs) that compose this field's
- * value
- * @param signed
- * Are the values in the array signed or not
- */
- CTFIntegerArrayField(String name, long[] longValues, int base, boolean signed) {
- super(name, longValues, null);
- fBase = base;
- fSigned = signed;
- }
-
- @Override
- public long[] getValue() {
- return (long[]) super.getValue();
- }
-
- @Override
- public synchronized String getFormattedValue() {
- if (fFormattedValue == null) {
- List<String> strings = new ArrayList<>();
- for (long value : getValue()) {
- strings.add(IntegerDefinition.formatNumber(value, fBase, fSigned));
- }
- fFormattedValue = strings.toString();
- }
- return fFormattedValue;
- }
-
-}
-
-/**
- * CTF field implementation for arrays of arbitrary types.
- *
- * @author fdoray
- */
-final class CTFArrayField extends CtfTmfEventField {
-
- private String fFormattedValue = null;
-
- /**
- * Constructor for CTFArrayField.
- *
- * @param name
- * The name of this field
- * @param elements
- * The array elements of this field
- */
- CTFArrayField(String name, CtfTmfEventField[] elements) {
- super(name, elements, elements);
- }
-
- @Override
- public CtfTmfEventField[] getValue() {
- return (CtfTmfEventField[]) super.getValue();
- }
-
- @Override
- public synchronized String getFormattedValue() {
- if (fFormattedValue == null) {
- List<String> strings = new ArrayList<>();
- for (CtfTmfEventField element : getValue()) {
- strings.add(element.getFormattedValue());
- }
- fFormattedValue = strings.toString();
- }
- return fFormattedValue;
- }
-}
-
-/**
- * CTF field implementation for floats.
- *
- * @author emathko
- */
-final class CTFFloatField extends CtfTmfEventField {
-
- /**
- * Constructor for CTFFloatField.
- *
- * @param value
- * The float value (actually a double) of this field
- * @param name
- * The name of this field
- */
- protected CTFFloatField(String name, double value) {
- super(name, value, null);
- }
-
- @Override
- public Double getValue() {
- return (Double) super.getValue();
- }
-}
-
-/**
- * The CTF field implementation for Enum fields
- *
- * @author Bernd Hufmann
- */
-final class CTFEnumField extends CtfTmfEventField {
-
- /**
- * Constructor for CTFEnumField.
- *
- * @param enumValue
- * The Enum value consisting of a pair of Enum value name and its
- * long value
- * @param name
- * The name of this field
- */
- CTFEnumField(String name, CtfEnumPair enumValue) {
- super(name, new CtfEnumPair(enumValue.getFirst(),
- enumValue.getSecond()), null);
- }
-
- @Override
- public CtfEnumPair getValue() {
- return (CtfEnumPair) super.getValue();
- }
-}
-
-/**
- * The CTF field implementation for struct fields with sub-fields
- *
- * @author gbastien
- */
-final class CTFStructField extends CtfTmfEventField {
-
- /**
- * Constructor for CTFStructField.
- *
- * @param fields
- * The children of this field
- * @param name
- * The name of this field
- */
- CTFStructField(String name, CtfTmfEventField[] fields) {
- super(name, fields, fields);
- }
-
- @Override
- public CtfTmfEventField[] getValue() {
- return (CtfTmfEventField[]) super.getValue();
- }
-
- @Override
- public String getFormattedValue() {
- return Arrays.toString(getValue());
- }
-
-}
-
-/**
- * The CTF field implementation for variant fields its child
- *
- * @author gbastien
- */
-final class CTFVariantField extends CtfTmfEventField {
-
- /**
- * Constructor for CTFVariantField.
- *
- * @param field
- * The field selected for this variant
- * @param name
- * The name of this field
- */
- CTFVariantField(String name, CtfTmfEventField field) {
- super(name, field, new CtfTmfEventField[] { field });
- }
-
- @Override
- public CtfTmfEventField getValue() {
- return (CtfTmfEventField) super.getValue();
- }
-
-}
-
-/* Implement other possible fields types here... */
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
-
-/**
- * The CTF extension of the TMF event type
- *
- * @author Matthew khouzam
- */
-public class CtfTmfEventType extends TmfEventType {
-
- /**
- * Constructor for CtfTmfEventType.
- *
- * @param eventName
- * The event name
- * @param content
- * The event field
- * @since 3.0
- */
- public CtfTmfEventType(String eventName, ITmfEventField content) {
- super(eventName, content);
- }
-
- /**
- * Method toString.
- *
- * @return String
- */
- @Override
- public String toString() {
- return getName();
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
-import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
-import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-
-/**
- * An implementation of {@link ITmfLostEvent} for use in the CTF adaptor.
- *
- * @author Alexandre Montplaisir
- * @since 2.2
- */
-public class CtfTmfLostEvent extends CtfTmfEvent implements ITmfLostEvent {
-
- private final TmfTimeRange fTimeRange;
- private final long fNbLost;
-
- /**
- * Constructor. Only {@link CtfTmfEventFactory} should call this.
- *
- * @param trace
- * The origin trace
- * @param rank
- * The rank of the event in the trace
- * @param content
- * The event's payload (fields). In case this event has some.
- * @param fileName
- * The name of the trace file from which this event comes
- * @param cpu
- * The CPU on which this event happened
- * @param declaration
- * The CTF Event Declaration object that created this event
- * @param timeRange
- * The time range of lost events indicated by this one
- * @param nbLost
- * The number of lost events in the range
- */
- CtfTmfLostEvent(CtfTmfTrace trace,
- long rank,
- String fileName,
- int cpu,
- IEventDeclaration declaration,
- TmfTimeRange timeRange,
- long nbLost,
- @NonNull EventDefinition def) {
- /*
- * Only the factory should call this method, the case to
- * (CtfTmfTimestamp) should be safe.
- */
- super(trace, rank, (CtfTmfTimestamp) timeRange.getStartTime(), fileName, cpu, declaration, def);
- fTimeRange = timeRange;
- fNbLost = nbLost;
- }
-
- @Override
- public TmfTimeRange getTimeRange() {
- return fTimeRange;
- }
-
- @Override
- public long getNbLostEvents() {
- return fNbLost;
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-
-/**
- * The CTF adapter for the TMF timestamp. It's basically the same as a
- * TmfTimestamp, but the scale is always nanoseconds, and the precision is 0.
- *
- * @version 1.2
- * @author Matthew khouzam
- */
-public final class CtfTmfTimestamp extends TmfTimestamp {
-
- /**
- * Constructor for CtfTmfTimestamp.
- *
- * @param timestamp
- * The timestamp value (in nanoseconds)
- */
- public CtfTmfTimestamp(long timestamp) {
- super(timestamp, ITmfTimestamp.NANOSECOND_SCALE);
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- * Patrick Tasse - Updated for removal of context clone
- * Geneviève Bastien - Added the createTimestamp function
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.tracecompass.ctf.core.event.CTFClock;
-import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
-import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
-import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
-import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
-import org.eclipse.tracecompass.internal.tmf.ctf.core.Activator;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfEventParser;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceProperties;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
-import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
-import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
-import org.eclipse.tracecompass.tmf.core.trace.indexer.TmfBTreeTraceIndexer;
-import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
-import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint;
-import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
-
-import com.google.common.collect.ImmutableSet;
-
-/**
- * The CTf trace handler
- *
- * @version 1.0
- * @author Matthew khouzam
- */
-public class CtfTmfTrace extends TmfTrace
- implements ITmfEventParser, ITmfTraceProperties, ITmfPersistentlyIndexable,
- ITmfTraceWithPreDefinedEvents, AutoCloseable {
-
- // -------------------------------------------
- // Constants
- // -------------------------------------------
- /**
- * Default cache size for CTF traces
- */
- protected static final int DEFAULT_CACHE_SIZE = 50000;
-
- /*
- * The Ctf clock unique identifier field
- */
- private static final String CLOCK_HOST_PROPERTY = "uuid"; //$NON-NLS-1$
- private static final int CONFIDENCE = 10;
-
- // -------------------------------------------
- // Fields
- // -------------------------------------------
-
- private final Map<String, CtfTmfEventType> fContainedEventTypes =
- Collections.synchronizedMap(new HashMap<String, CtfTmfEventType>());
-
- private final CtfIteratorManager fIteratorManager =
- new CtfIteratorManager(this);
-
- /* Reference to the CTF Trace */
- private CTFTrace fTrace;
-
- // -------------------------------------------
- // TmfTrace Overrides
- // -------------------------------------------
- /**
- * Method initTrace.
- *
- * @param resource
- * The resource associated with this trace
- * @param path
- * The path to the trace file
- * @param eventType
- * The type of events that will be read from this trace
- * @throws TmfTraceException
- * If something went wrong while reading the trace
- */
- @Override
- public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType)
- throws TmfTraceException {
- /*
- * Set the cache size. This has to be done before the call to super()
- * because the super needs to know the cache size.
- */
- setCacheSize();
-
- super.initTrace(resource, path, eventType);
-
- try {
- this.fTrace = new CTFTrace(path);
- CtfTmfContext ctx;
- /* Set the start and (current) end times for this trace */
- ctx = (CtfTmfContext) seekEvent(0L);
- CtfTmfEvent event = getNext(ctx);
- if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
- /* Handle the case where the trace is empty */
- this.setStartTime(TmfTimestamp.BIG_BANG);
- } else {
- final ITmfTimestamp curTime = event.getTimestamp();
- this.setStartTime(curTime);
- this.setEndTime(curTime);
- }
- /*
- * Register every event type. When you call getType, it will
- * register a trace to that type in the TmfEventTypeManager
- */
- try (CtfIterator iter = fIteratorManager.getIterator(ctx)) {
- for (IEventDeclaration ied : iter.getEventDeclarations()) {
- CtfTmfEventType ctfTmfEventType = fContainedEventTypes.get(ied.getName());
- if (ctfTmfEventType == null) {
- List<ITmfEventField> content = new ArrayList<>();
- /* Should only return null the first time */
- for (String fieldName : ied.getFields().getFieldsList()) {
- content.add(new TmfEventField(fieldName, null, null));
- }
- ITmfEventField contentTree = new TmfEventField(
- ITmfEventField.ROOT_FIELD_ID,
- null,
- content.toArray(new ITmfEventField[content.size()])
- );
-
- ctfTmfEventType = new CtfTmfEventType(ied.getName(), contentTree);
- fContainedEventTypes.put(ctfTmfEventType.getName(), ctfTmfEventType);
- }
- }
- }
- } catch (final CTFReaderException e) {
- /*
- * If it failed at the init(), we can assume it's because the file
- * was not found or was not recognized as a CTF trace. Throw into
- * the new type of exception expected by the rest of TMF.
- */
- throw new TmfTraceException(e.getMessage(), e);
- }
- }
-
- /**
- * Return the iterator manager of this trace
- *
- * @return The iterator manager
- */
- public CtfIteratorManager getIteratorManager() {
- return fIteratorManager;
- }
-
- @Override
- public void close() {
- dispose();
- }
-
- @Override
- public synchronized void dispose() {
- fIteratorManager.dispose();
- if (fTrace != null) {
- fTrace.close();
- fTrace = null;
- }
- super.dispose();
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * The default implementation sets the confidence to 10 if the trace is a
- * valid CTF trace.
- */
- @Override
- public IStatus validate(final IProject project, final String path) {
- IStatus status = new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
- try (final CTFTrace temp = new CTFTrace(path);) {
- if (!temp.majorIsSet()) {
- status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
- } else {
- try (CTFTraceReader ctfTraceReader = new CTFTraceReader(temp);) {
- if (!ctfTraceReader.hasMoreEvents()) {
- // TODO: This will need an additional check when we
- // support live traces
- // because having no event is valid for a live trace
- status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_NoEvent);
- }
- }
- }
- } catch (final CTFReaderException e) {
- status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString()); //$NON-NLS-1$
- } catch (final BufferOverflowException e) {
- status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + Messages.CtfTmfTrace_BufferOverflowErrorMessage); //$NON-NLS-1$
- }
-
- return status;
- }
-
- /**
- * Method getCurrentLocation. This is not applicable in CTF
- *
- * @return null, since the trace has no knowledge of the current location
- * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getCurrentLocation()
- * @since 3.0
- */
- @Override
- public ITmfLocation getCurrentLocation() {
- return null;
- }
-
- /**
- * @since 3.0
- */
- @Override
- public double getLocationRatio(ITmfLocation location) {
- final CtfLocation curLocation = (CtfLocation) location;
- final CtfTmfContext context = new CtfTmfContext(this);
- context.setLocation(curLocation);
- context.seek(curLocation.getLocationInfo());
- final CtfLocationInfo currentTime = ((CtfLocationInfo) context.getLocation().getLocationInfo());
- final long startTime = fIteratorManager.getIterator(context).getStartTime();
- final long endTime = fIteratorManager.getIterator(context).getEndTime();
- return ((double) currentTime.getTimestamp() - startTime)
- / (endTime - startTime);
- }
-
- /**
- * Method seekEvent.
- *
- * @param location
- * ITmfLocation<?>
- * @return ITmfContext
- * @since 3.0
- */
- @Override
- public synchronized ITmfContext seekEvent(final ITmfLocation location) {
- CtfLocation currentLocation = (CtfLocation) location;
- CtfTmfContext context = new CtfTmfContext(this);
- if (fTrace == null) {
- context.setLocation(null);
- context.setRank(ITmfContext.UNKNOWN_RANK);
- return context;
- }
- /*
- * The rank is set to 0 if the iterator seeks the beginning. If not, it
- * will be set to UNKNOWN_RANK, since CTF traces don't support seeking
- * by rank for now.
- */
- if (currentLocation == null) {
- currentLocation = new CtfLocation(new CtfLocationInfo(0L, 0L));
- context.setRank(0);
- }
- if (currentLocation.getLocationInfo() == CtfLocation.INVALID_LOCATION) {
- currentLocation = new CtfLocation(getCTFTrace().getCurrentEndTime() + 1, 0L);
- }
- context.setLocation(currentLocation);
- if (location == null) {
- long timestamp = fIteratorManager.getIterator(context).getCurrentTimestamp();
- currentLocation = new CtfLocation(timestamp, 0);
- }
- if (context.getRank() != 0) {
- context.setRank(ITmfContext.UNKNOWN_RANK);
- }
- return context;
- }
-
- @Override
- public synchronized ITmfContext seekEvent(double ratio) {
- CtfTmfContext context = new CtfTmfContext(this);
- if (fTrace == null) {
- context.setLocation(null);
- context.setRank(ITmfContext.UNKNOWN_RANK);
- return context;
- }
- final long end = getCTFTrace().getCurrentEndTime();
- final long start = getCTFTrace().getCurrentStartTime();
- final long diff = end - start;
- final long ratioTs = Math.round(diff * ratio) + start;
- context.seek(ratioTs);
- context.setRank(ITmfContext.UNKNOWN_RANK);
- return context;
- }
-
- /**
- * Method readNextEvent.
- *
- * @param context
- * ITmfContext
- * @return CtfTmfEvent
- * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getNext(ITmfContext)
- */
- @Override
- public synchronized CtfTmfEvent getNext(final ITmfContext context) {
- if (fTrace == null) {
- return null;
- }
- CtfTmfEvent event = null;
- if (context instanceof CtfTmfContext) {
- if (context.getLocation() == null || CtfLocation.INVALID_LOCATION.equals(context.getLocation().getLocationInfo())) {
- return null;
- }
- CtfTmfContext ctfContext = (CtfTmfContext) context;
- event = ctfContext.getCurrentEvent();
-
- if (event != null) {
- updateAttributes(context, event.getTimestamp());
- ctfContext.advance();
- ctfContext.increaseRank();
- }
- }
-
- return event;
- }
-
- /**
- * gets the CTFtrace that this is wrapping
- *
- * @return the CTF trace
- */
- public CTFTrace getCTFTrace() {
- return fTrace;
- }
-
- /**
- * Ctf traces have a clock with a unique uuid that will be used to identify
- * the host. Traces with the same clock uuid will be known to have been made
- * on the same machine.
- *
- * Note: uuid is an optional field, it may not be there for a clock.
- */
- @Override
- public String getHostId() {
- CTFClock clock = getCTFTrace().getClock();
- if (clock != null) {
- String clockHost = (String) clock.getProperty(CLOCK_HOST_PROPERTY);
- if (clockHost != null) {
- return clockHost;
- }
- }
- return super.getHostId();
- }
-
- // -------------------------------------------
- // ITmfTraceProperties
- // -------------------------------------------
-
- /**
- * @since 2.0
- */
- @Override
- public Map<String, String> getTraceProperties() {
- Map<String, String> properties = new HashMap<>();
- properties.putAll(fTrace.getEnvironment());
- properties.put(Messages.CtfTmfTrace_HostID, getHostId());
- return properties;
- }
-
- // -------------------------------------------
- // Clocks
- // -------------------------------------------
-
- /**
- * gets the clock offset
- *
- * @return the clock offset in ns
- */
- public long getOffset() {
- if (fTrace != null) {
- return fTrace.getOffset();
- }
- return 0;
- }
-
- /**
- * Gets the list of declared events
- *
- * @since 3.0
- */
- @Override
- public Set<CtfTmfEventType> getContainedEventTypes() {
- return ImmutableSet.copyOf(fContainedEventTypes.values());
- }
-
- /**
- * Register an event type to this trace.
- *
- * Package-visible so that {@link CtfTmfEvent#getType} can call it.
- *
- * FIXME This could probably be made cleaner?
- */
- void registerEventType(CtfTmfEventType eventType) {
- fContainedEventTypes.put(eventType.getName(), eventType);
- }
-
- // -------------------------------------------
- // Parser
- // -------------------------------------------
-
- @Override
- public CtfTmfEvent parseEvent(ITmfContext context) {
- CtfTmfEvent event = null;
- if (context instanceof CtfTmfContext) {
- final ITmfContext tmpContext = seekEvent(context.getLocation());
- event = getNext(tmpContext);
- }
- return event;
- }
-
- /**
- * Sets the cache size for a CtfTmfTrace.
- */
- protected void setCacheSize() {
- setCacheSize(DEFAULT_CACHE_SIZE);
- }
-
- // -------------------------------------------
- // Helpers
- // -------------------------------------------
-
- /**
- * Get an iterator to the trace
- *
- * @return an iterator to the trace
- * @since 2.0
- */
- public CtfIterator createIterator() {
- try {
- return new CtfIterator(this);
- } catch (CTFReaderException e) {
- Activator.getDefault().logError(e.getMessage(), e);
- }
- return null;
- }
-
- // ------------------------------------------------------------------------
- // Timestamp transformation functions
- // ------------------------------------------------------------------------
-
- /**
- * @since 3.0
- */
- @Override
- public CtfTmfTimestamp createTimestamp(long ts) {
- return new CtfTmfTimestamp(getTimestampTransform().transform(ts));
- }
-
- private static int fCheckpointSize = -1;
-
- /**
- * @since 3.0
- */
- @Override
- public synchronized int getCheckpointSize() {
- if (fCheckpointSize == -1) {
- TmfCheckpoint c = new TmfCheckpoint(new CtfTmfTimestamp(0), new CtfLocation(0, 0), 0);
- ByteBuffer b = ByteBuffer.allocate(ITmfCheckpoint.MAX_SERIALIZE_SIZE);
- b.clear();
- c.serialize(b);
- fCheckpointSize = b.position();
- }
-
- return fCheckpointSize;
- }
-
- @Override
- protected ITmfTraceIndexer createIndexer(int interval) {
- return new TmfBTreeTraceIndexer(this, interval);
- }
-
- /**
- * @since 3.0
- */
- @Override
- public ITmfLocation restoreLocation(ByteBuffer bufferIn) {
- return new CtfLocation(bufferIn);
- }
-
- @Override
- public boolean isComplete() {
- if (getResource() == null) {
- return true;
- }
-
- String host = null;
- String port = null;
- String sessionName = null;
- try {
- host = getResource().getPersistentProperty(CtfConstants.LIVE_HOST);
- port = getResource().getPersistentProperty(CtfConstants.LIVE_PORT);
- sessionName = getResource().getPersistentProperty(CtfConstants.LIVE_SESSION_NAME);
- } catch (CoreException e) {
- Activator.getDefault().logError(e.getMessage(), e);
- // Something happened to the resource, assume we won't get any more data from it
- return true;
- }
- return host == null || port == null || sessionName == null;
- }
-
- @Override
- public void setComplete(final boolean isComplete) {
- super.setComplete(isComplete);
- try {
- if (isComplete) {
- getResource().setPersistentProperty(CtfConstants.LIVE_HOST, null);
- getResource().setPersistentProperty(CtfConstants.LIVE_PORT, null);
- getResource().setPersistentProperty(CtfConstants.LIVE_SESSION_NAME, null);
- }
- } catch (CoreException e) {
- Activator.getDefault().logError(e.getMessage(), e);
- }
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ctf.core;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Message bundle for tmf.core.ctfadaptor
- *
- * @author Matthew Khouzam
- * @since 2.0
- */
-public class Messages extends NLS {
-
- private static final String BUNDLE_NAME = "org.eclipse.tracecompass.tmf.ctf.core.messages"; //$NON-NLS-1$
-
- /** Buffer overflow detected
- * @since 2.1*/
- public static String CtfTmfTrace_BufferOverflowErrorMessage;
-
- /**
- * Text for host ID
- *
- * @since 3.1
- */
- public static String CtfTmfTrace_HostID;
-
- /** Major version number not set */
- public static String CtfTmfTrace_MajorNotSet;
-
- /** Reading error */
- public static String CtfTmfTrace_ReadingError;
-
- /** No event */
- public static String CtfTmfTrace_NoEvent;
-
- /** Unsupported field type */
- public static String CtfTmfEventField_UnsupportedType;
-
- static {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages() {
- }
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ * Alexandre Montplaisir - Extends TmfLocation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.context;
+
+import java.nio.ByteBuffer;
+
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.location.TmfLocation;
+
+/**
+ * The nugget of information that is unique to a location in a CTF trace.
+ *
+ * It can be copied and used to restore a position in a given trace.
+ *
+ * @version 1.0
+ * @author Matthew Khouzam
+ */
+public final class CtfLocation extends TmfLocation {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ /**
+ * An invalid location
+ */
+ public static final CtfLocationInfo INVALID_LOCATION = new CtfLocationInfo(-1, -1);
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Basic constructor for CtfLocation. Uses a default index of 0.
+ *
+ * @param timestamp
+ * The timestamp of this location
+ * @since 2.0
+ */
+ public CtfLocation(final ITmfTimestamp timestamp) {
+ this(timestamp.getValue(), 0);
+ }
+
+ /**
+ * Constructor using timestamp object and index
+ *
+ * @param timestamp
+ * The timestamp of this location
+ * @param index
+ * The index of this location for this timestamp
+ * @since 2.0
+ */
+ public CtfLocation(final ITmfTimestamp timestamp, long index) {
+ this(timestamp.getValue(), index);
+ }
+
+ /**
+ * Constructor using a long value for the timestamp, and an index
+ *
+ * @param timestampValue
+ * The new timestamp
+ * @param index
+ * The new index
+ * @since 2.0
+ */
+ public CtfLocation(final long timestampValue, final long index) {
+ super(new CtfLocationInfo(timestampValue, index));
+ }
+
+ /**
+ * Constructor using a pre-made locationInfo object
+ *
+ * @param locationInfo
+ * The locationInfo object to use
+ * @since 2.0
+ */
+ public CtfLocation(CtfLocationInfo locationInfo) {
+ super(locationInfo);
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param location
+ * Other location to copy
+ * @since 2.0
+ */
+ public CtfLocation(final CtfLocation location) {
+ super(location);
+ }
+
+ // ------------------------------------------------------------------------
+ // TmfLocation
+ // ------------------------------------------------------------------------
+
+ /**
+ * Construct the location from the ByteBuffer.
+ *
+ * @param bufferIn
+ * the buffer to read from
+ *
+ * @since 3.0
+ */
+ public CtfLocation(ByteBuffer bufferIn) {
+ super(new CtfLocationInfo(bufferIn));
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public CtfLocationInfo getLocationInfo() {
+ return (CtfLocationInfo) super.getLocationInfo();
+ }
+
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ @Override
+ public String toString() {
+ if (getLocationInfo().equals(CtfLocation.INVALID_LOCATION )) {
+ return getClass().getSimpleName() + " [INVALID]"; //$NON-NLS-1$
+ }
+ return super.toString();
+ }
+
+ /**
+ * Constructs the location from the ByteBuffer. This typically happens when reading from disk.
+ *
+ * @since 3.0
+ */
+ @Override
+ public void serialize(ByteBuffer bufferOut) {
+ getLocationInfo().serialize(bufferOut);
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.context;
+
+import java.nio.ByteBuffer;
+
+/**
+ * The data object to go in a {@link CtfLocation}.
+ *
+ * @author Matthew Khouzam
+ * @since 2.0
+ */
+public class CtfLocationInfo implements Comparable<CtfLocationInfo> {
+
+ private final long fTimestamp;
+ private final long fIndex;
+
+ /**
+ * @param ts
+ * Timestamp
+ * @param index
+ * Index of this event (if there are N elements with the same
+ * timestamp, which one is it.)
+ */
+ public CtfLocationInfo(long ts, long index) {
+ fTimestamp = ts;
+ fIndex = index;
+ }
+
+ /**
+ * Construct the location from the ByteBuffer.
+ *
+ * @param bufferIn
+ * the buffer to read from
+ *
+ * @since 3.0
+ */
+ public CtfLocationInfo(ByteBuffer bufferIn) {
+ fTimestamp = bufferIn.getLong();
+ fIndex = bufferIn.getLong();
+ }
+
+ /**
+ * @return The timestamp
+ */
+ public long getTimestamp() {
+ return fTimestamp;
+ }
+
+ /**
+ * @return The index of the element
+ */
+ public long getIndex() {
+ return fIndex;
+ }
+
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = (prime * result) + (int) (fIndex ^ (fIndex >>> 32));
+ result = (prime * result) + (int) (fTimestamp ^ (fTimestamp >>> 32));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof CtfLocationInfo)) {
+ return false;
+ }
+ CtfLocationInfo other = (CtfLocationInfo) obj;
+ if (fIndex != other.fIndex) {
+ return false;
+ }
+ if (fTimestamp != other.fTimestamp) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Element [" + fTimestamp + '/' + fIndex + ']'; //$NON-NLS-1$
+ }
+
+ // ------------------------------------------------------------------------
+ // Comparable
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int compareTo(CtfLocationInfo other) {
+ if (fTimestamp > other.getTimestamp()) {
+ return 1;
+ }
+ if (fTimestamp < other.getTimestamp()) {
+ return -1;
+ }
+ if (fIndex > other.getIndex()) {
+ return 1;
+ }
+ if (fIndex < other.getIndex()) {
+ return -1;
+ }
+ return 0;
+ }
+
+ /**
+ * Write the location to the ByteBuffer so that it can be saved to disk.
+ *
+ * @param bufferOut
+ * the buffer to write to
+ *
+ * @since 3.0
+ */
+ public void serialize(ByteBuffer bufferOut) {
+ bufferOut.putLong(fTimestamp);
+ bufferOut.putLong(fIndex);
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ * Simon Delisle - Remove the iterator in dispose()
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.context;
+
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.iterator.CtfIterator;
+
+/**
+ * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
+ * a boxed Long, a long and an int.
+ *
+ * @author Matthew Khouzam
+ * @version 1.0
+ * @since 2.0
+ */
+public class CtfTmfContext implements ITmfContext {
+
+ // -------------------------------------------
+ // Fields
+ // -------------------------------------------
+
+ private CtfLocation fCurLocation;
+ private long fCurRank;
+
+ private final CtfTmfTrace fTrace;
+
+ // -------------------------------------------
+ // Constructor
+ // -------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param ctfTmfTrace
+ * the parent trace
+ * @since 1.1
+ */
+ public CtfTmfContext(CtfTmfTrace ctfTmfTrace) {
+ fTrace = ctfTmfTrace;
+ fCurLocation = new CtfLocation(new CtfLocationInfo(0, 0));
+ }
+
+ // -------------------------------------------
+ // TmfContext Overrides
+ // -------------------------------------------
+
+ @Override
+ public long getRank() {
+ return fCurRank;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public synchronized ITmfLocation getLocation() {
+ return fCurLocation;
+ }
+
+ @Override
+ public boolean hasValidRank() {
+ return fCurRank != CtfLocation.INVALID_LOCATION.getTimestamp();
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public synchronized void setLocation(ITmfLocation location) {
+ fCurLocation = (CtfLocation) location;
+ if (fCurLocation != null) {
+ getIterator().seek(fCurLocation.getLocationInfo());
+ }
+ }
+
+ @Override
+ public void setRank(long rank) {
+ fCurRank = rank;
+
+ }
+
+ @Override
+ public void increaseRank() {
+ if (hasValidRank()) {
+ fCurRank++;
+ }
+ }
+
+ // -------------------------------------------
+ // CtfTmfTrace Helpers
+ // -------------------------------------------
+
+ /**
+ * Gets the trace of this context.
+ *
+ * @return The trace of this context
+ */
+ public CtfTmfTrace getTrace() {
+ return fTrace;
+ }
+
+ /**
+ * Gets the current event. Wrapper to help CtfTmfTrace
+ *
+ * @return The event or null
+ */
+ public synchronized CtfTmfEvent getCurrentEvent() {
+ return getIterator().getCurrentEvent();
+ }
+
+ /**
+ * Advances to a the next event. Wrapper to help CtfTmfTrace
+ *
+ * @return success or not
+ */
+ public synchronized boolean advance() {
+ final CtfLocationInfo curLocationData = fCurLocation.getLocationInfo();
+ CtfIterator iterator = getIterator();
+ boolean retVal = iterator.advance();
+ CtfTmfEvent currentEvent = iterator.getCurrentEvent();
+
+ if (currentEvent != null) {
+ final long timestampValue = iterator.getCurrentTimestamp();
+ if (curLocationData.getTimestamp() == timestampValue) {
+ fCurLocation = new CtfLocation(timestampValue, curLocationData.getIndex() + 1);
+ } else {
+ fCurLocation = new CtfLocation(timestampValue, 0L);
+ }
+ } else {
+ fCurLocation = new CtfLocation(CtfLocation.INVALID_LOCATION);
+ }
+
+ return retVal;
+ }
+
+ @Override
+ public void dispose() {
+ fTrace.getIteratorManager().removeIterator(this);
+ }
+
+ /**
+ * Seeks to a given timestamp. Wrapper to help CtfTmfTrace
+ *
+ * @param timestamp
+ * desired timestamp
+ * @return success or not
+ */
+ public synchronized boolean seek(final long timestamp) {
+ fCurLocation = new CtfLocation(timestamp, 0);
+ return getIterator().seek(timestamp);
+ }
+
+ /**
+ * Seeks to a given location. Wrapper to help CtfTmfTrace
+ * @param location
+ * unique location to find the event.
+ *
+ * @return success or not
+ * @since 2.0
+ */
+ public synchronized boolean seek(final CtfLocationInfo location) {
+ fCurLocation = new CtfLocation(location);
+ return getIterator().seek(location);
+ }
+
+ // -------------------------------------------
+ // Private helpers
+ // -------------------------------------------
+
+ /**
+ * Get iterator, called every time to get an iterator, no local copy is
+ * stored so that there is no need to "update"
+ *
+ * @return an iterator
+ */
+ private CtfIterator getIterator() {
+ return fTrace.getIteratorManager().getIterator(this);
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ * Bernd Hufmann - Updated for source and model lookup interfaces
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.event;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.ctf.core.event.CTFCallsite;
+import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
+import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
+import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
+import org.eclipse.tracecompass.tmf.core.event.ITmfCustomAttributes;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup;
+import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+import org.eclipse.tracecompass.tmf.ctf.core.CtfConstants;
+import org.eclipse.tracecompass.tmf.ctf.core.event.lookup.CtfTmfCallsite;
+import org.eclipse.tracecompass.tmf.ctf.core.timestamp.CtfTmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * A wrapper class around CTF's Event Definition/Declaration that maps all types
+ * of Declaration to native Java types.
+ *
+ * @version 1.0
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+public class CtfTmfEvent extends TmfEvent
+ implements ITmfSourceLookup, ITmfModelLookup, ITmfCustomAttributes {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private final int fSourceCPU;
+ private final long fTypeId;
+ private final String fEventName;
+ private final IEventDeclaration fEventDeclaration;
+ @NonNull
+ private final EventDefinition fEvent;
+ private ITmfEventField fContent;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor used by {@link CtfTmfEventFactory#createEvent}
+ */
+ CtfTmfEvent(CtfTmfTrace trace, long rank, CtfTmfTimestamp timestamp,
+ String fileName, int cpu, IEventDeclaration declaration, @NonNull EventDefinition eventDefinition) {
+ super(trace,
+ rank,
+ timestamp,
+ String.valueOf(cpu), // Source
+ null, // Event type. We don't use TmfEvent's field here, we
+ // re-implement getType()
+ null, // Content handled with a lazy loaded re-implemented in
+ // getContent()
+ fileName // Reference
+ );
+
+ fEventDeclaration = declaration;
+ fSourceCPU = cpu;
+ fTypeId = declaration.getId().longValue();
+ fEventName = declaration.getName();
+ fEvent = eventDefinition;
+
+ }
+
+ /**
+ * Inner constructor to create "null" events. Don't use this directly in
+ * normal usage, use {@link CtfTmfEventFactory#getNullEvent(CtfTmfTrace)} to
+ * get an instance of an empty event.
+ *
+ * There is no need to give higher visibility to this method than package
+ * visible.
+ *
+ * @param trace
+ * The trace associated with this event
+ */
+ CtfTmfEvent(CtfTmfTrace trace) {
+ super(trace,
+ ITmfContext.UNKNOWN_RANK,
+ new CtfTmfTimestamp(-1),
+ null,
+ null,
+ new TmfEventField("", null, new CtfTmfEventField[0]), //$NON-NLS-1$
+ null);
+ fSourceCPU = -1;
+ fTypeId = -1;
+ fEventName = EMPTY_CTF_EVENT_NAME;
+ fEventDeclaration = null;
+ fEvent = EventDefinition.NULL_EVENT;
+ }
+
+ /**
+ * Default constructor. Do not use directly, but it needs to be present
+ * because it's used in extension points, and the framework will use this
+ * constructor to get the class type.
+ */
+ public CtfTmfEvent() {
+ this(null);
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+ /**
+ * Gets the cpu core the event was recorded on.
+ *
+ * @return The cpu id for a given source. In lttng it's from CPUINFO
+ */
+ public int getCPU() {
+ return fSourceCPU;
+ }
+
+ /**
+ * Return this event's ID, according to the trace's metadata.
+ *
+ * Watch out, this ID is not constant from one trace to another for the same
+ * event types! Use "getEventName()" for a constant reference.
+ *
+ * @return The event ID
+ */
+ public long getID() {
+ return fTypeId;
+ }
+
+ @Override
+ public CtfTmfTrace getTrace() {
+ /*
+ * Should be of the right type, since we take a CtfTmfTrace at the
+ * constructor
+ */
+ return (CtfTmfTrace) super.getTrace();
+ }
+
+ @Override
+ public ITmfEventType getType() {
+ CtfTmfEventType ctfTmfEventType = new CtfTmfEventType(fEventName, getContent());
+
+ /* Register the event type in the owning trace, but only if there is one */
+ CtfTmfTrace trace = getTrace();
+ trace.registerEventType(ctfTmfEventType);
+
+ return ctfTmfEventType;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public Set<String> listCustomAttributes() {
+ if (fEventDeclaration == null) {
+ return new HashSet<>();
+ }
+ return fEventDeclaration.getCustomAttributes();
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String getCustomAttribute(String name) {
+ if (fEventDeclaration == null) {
+ return null;
+ }
+ return fEventDeclaration.getCustomAttribute(name);
+ }
+
+ /**
+ * Get the call site for this event.
+ *
+ * @return the call site information, or null if there is none
+ * @since 2.0
+ */
+ @Override
+ public CtfTmfCallsite getCallsite() {
+ CTFCallsite callsite = null;
+ CtfTmfTrace trace = getTrace();
+ CTFTrace ctfTrace = trace.getCTFTrace();
+ /* Should not happen, but it is a good check */
+ if (ctfTrace == null) {
+ return null;
+ }
+ if (getContent() != null) {
+ ITmfEventField ipField = getContent().getField(CtfConstants.CONTEXT_FIELD_PREFIX + CtfConstants.IP_KEY);
+ if (ipField != null && ipField.getValue() instanceof Long) {
+ long ip = (Long) ipField.getValue();
+ callsite = ctfTrace.getCallsite(fEventName, ip);
+ }
+ }
+ if (callsite == null) {
+ callsite = ctfTrace.getCallsite(fEventName);
+ }
+ if (callsite != null) {
+ return new CtfTmfCallsite(callsite);
+ }
+ return null;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String getModelUri() {
+ return getCustomAttribute(CtfConstants.MODEL_URI_KEY);
+ }
+
+ @Override
+ public synchronized ITmfEventField getContent() {
+ if (fContent == null) {
+ fContent = new TmfEventField(
+ ITmfEventField.ROOT_FIELD_ID, null, parseFields(fEvent));
+ }
+ return fContent;
+ }
+
+ /**
+ * Extract the field information from the structDefinition haze-inducing
+ * mess, and put them into something ITmfEventField can cope with.
+ */
+ private static CtfTmfEventField[] parseFields(@NonNull EventDefinition eventDef) {
+ List<CtfTmfEventField> fields = new ArrayList<>();
+
+ ICompositeDefinition structFields = eventDef.getFields();
+ if (structFields != null) {
+ if (structFields.getFieldNames() != null) {
+ for (String curFieldName : structFields.getFieldNames()) {
+ fields.add(CtfTmfEventField.parseField((IDefinition) structFields.getDefinition(curFieldName), curFieldName));
+ }
+ }
+ }
+ /* Add context information as CtfTmfEventField */
+ ICompositeDefinition structContext = eventDef.getContext();
+ if (structContext != null) {
+ for (String contextName : structContext.getFieldNames()) {
+ /* Prefix field name */
+ String curContextName = CtfConstants.CONTEXT_FIELD_PREFIX + contextName;
+ fields.add(CtfTmfEventField.parseField((IDefinition) structContext.getDefinition(contextName), curContextName));
+ }
+ }
+
+ return fields.toArray(new CtfTmfEventField[fields.size()]);
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.event;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.ctf.core.CTFStrings;
+import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
+import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+import org.eclipse.tracecompass.tmf.ctf.core.timestamp.CtfTmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * Factory for CtfTmfEvent's.
+ *
+ * This code was moved out of CtfTmfEvent to provide better separation between
+ * the parsing/instantiation of events, and the usual TMF API implementations.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+public final class CtfTmfEventFactory {
+
+ private static final String NO_STREAM = "No stream"; //$NON-NLS-1$
+
+ /**
+ * Don't let anyone instantiate this class.
+ */
+ private CtfTmfEventFactory() {}
+
+ /**
+ * Factory method to instantiate new {@link CtfTmfEvent}'s.
+ *
+ * @param eventDef
+ * CTF EventDefinition object corresponding to this trace event
+ * @param fileName
+ * The path to the trace file
+ * @param originTrace
+ * The trace from which this event originates
+ * @return The newly-built CtfTmfEvent
+ */
+ public static CtfTmfEvent createEvent(EventDefinition eventDef,
+ String fileName, CtfTmfTrace originTrace) {
+
+ /* Prepare what to pass to CtfTmfEvent's constructor */
+ final IEventDeclaration eventDecl = eventDef.getDeclaration();
+ final long ts = eventDef.getTimestamp();
+ final CtfTmfTimestamp timestamp = originTrace.createTimestamp(
+ originTrace.getCTFTrace().timestampCyclesToNanos(ts));
+
+ int sourceCPU = eventDef.getCPU();
+
+ String reference = fileName == null ? NO_STREAM : fileName;
+
+ /* Handle the special case of lost events */
+ if (eventDecl.getName().equals(CTFStrings.LOST_EVENT_NAME)) {
+ IDefinition nbLostEventsDef = eventDef.getFields().getDefinition(CTFStrings.LOST_EVENTS_FIELD);
+ IDefinition durationDef = eventDef.getFields().getDefinition(CTFStrings.LOST_EVENTS_DURATION);
+ if (!(nbLostEventsDef instanceof IntegerDefinition) || !(durationDef instanceof IntegerDefinition)) {
+ /*
+ * One or both of these fields doesn't exist, or is not of the
+ * right type. The event claims to be a "lost event", but is
+ * malformed. Log it and return a null event instead.
+ */
+ return getNullEvent(originTrace);
+ }
+ long nbLostEvents = ((IntegerDefinition) nbLostEventsDef).getValue();
+ long duration = ((IntegerDefinition) durationDef).getValue();
+ CtfTmfTimestamp timestampEnd = new CtfTmfTimestamp(
+ originTrace.getCTFTrace().timestampCyclesToNanos(ts) + duration);
+
+ CtfTmfLostEvent lostEvent = new CtfTmfLostEvent(originTrace,
+ ITmfContext.UNKNOWN_RANK,
+ reference, // filename
+ sourceCPU,
+ eventDecl,
+ new TmfTimeRange(timestamp, timestampEnd),
+ nbLostEvents,
+ eventDef);
+ return lostEvent;
+ }
+
+ /* Handle standard event types */
+ CtfTmfEvent event = new CtfTmfEvent(
+ originTrace,
+ ITmfContext.UNKNOWN_RANK,
+ timestamp,
+ reference, // filename
+ sourceCPU,
+ eventDecl,
+ eventDef);
+ return event;
+ }
+
+ /* Singleton instance of a null event */
+ private static CtfTmfEvent nullEvent = null;
+
+ /**
+ * Get an instance of a null event.
+ *
+ * @param trace
+ * A trace to associate with this null event
+ * @return An empty event
+ */
+ public static CtfTmfEvent getNullEvent(@NonNull CtfTmfTrace trace) {
+ if (nullEvent == null) {
+ nullEvent = new CtfTmfEvent(trace);
+ }
+ return nullEvent;
+ }
+
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Ericsson, École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ * Alexandre Montplaisir - Initial API and implementation, extend TmfEventField
+ * Bernd Hufmann - Add Enum field handling
+ * Geneviève Bastien - Add Struct and Variant field handling
+ * Jean-Christian Kouame - Correct handling of unsigned integer fields
+ * François Doray - Add generic array field type
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.event;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.tracecompass.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.Definition;
+import org.eclipse.tracecompass.ctf.core.event.types.EnumDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.FloatDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.StringDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.VariantDefinition;
+import org.eclipse.tracecompass.internal.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.tracecompass.internal.ctf.core.event.types.ByteArrayDefinition;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.ctf.core.CtfEnumPair;
+
+/**
+ * The CTF implementation of the TMF event field model
+ *
+ * @version 2.0
+ * @author Matthew Khouzam
+ * @author Alexandre Montplaisir
+ */
+public abstract class CtfTmfEventField extends TmfEventField {
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Standard constructor. Only to be used internally, call parseField() to
+ * generate a new field object.
+ *
+ * @param name
+ * The name of this field
+ * @param value
+ * The value of this field. Its type should match the field type.
+ * @param fields
+ * The children fields. Useful for composite fields
+ * @since 2.0
+ */
+ protected CtfTmfEventField(String name, Object value, ITmfEventField[] fields) {
+ super(/* Strip the underscore from the field name if there is one */
+ name.startsWith("_") ? name.substring(1) : name, //$NON-NLS-1$
+ value,
+ fields);
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ /**
+ * Factory method to instantiate CtfTmfEventField objects.
+ *
+ * @param fieldDef
+ * The CTF Definition of this event field
+ * @param fieldName
+ * String The name to assign to this field
+ * @return The resulting CtfTmfEventField object
+ * @deprecated use {@link CtfTmfEventField#parseField(IDefinition, String)}
+ */
+ @Deprecated
+ public static CtfTmfEventField parseField(Definition fieldDef,
+ String fieldName) {
+ return parseField((IDefinition) fieldDef, fieldName);
+ }
+
+ /**
+ * Factory method to instantiate CtfTmfEventField objects.
+ *
+ * @param fieldDef
+ * The CTF Definition of this event field
+ * @param fieldName
+ * String The name to assign to this field
+ * @return The resulting CtfTmfEventField object
+ * @since 3.1
+ */
+ public static CtfTmfEventField parseField(IDefinition fieldDef,
+ String fieldName) {
+ CtfTmfEventField field = null;
+
+ /* Determine the Definition type */
+ if (fieldDef instanceof IntegerDefinition) {
+ IntegerDefinition intDef = (IntegerDefinition) fieldDef;
+ int base = intDef.getDeclaration().getBase();
+ field = new CTFIntegerField(fieldName, intDef.getValue(), base, intDef.getDeclaration().isSigned());
+
+ } else if (fieldDef instanceof EnumDefinition) {
+ EnumDefinition enumDef = (EnumDefinition) fieldDef;
+ field = new CTFEnumField(fieldName, new CtfEnumPair(enumDef.getValue(), enumDef.getIntegerValue()));
+
+ } else if (fieldDef instanceof StringDefinition) {
+ field = new CTFStringField(fieldName, ((StringDefinition) fieldDef).getValue());
+
+ } else if (fieldDef instanceof FloatDefinition) {
+ FloatDefinition floatDef = (FloatDefinition) fieldDef;
+ field = new CTFFloatField(fieldName, floatDef.getValue());
+
+ } else if (fieldDef instanceof ArrayDefinition) {
+ ArrayDefinition arrayDef = (ArrayDefinition) fieldDef;
+ IDeclaration decl = arrayDef.getDeclaration();
+ if (!(decl instanceof CompoundDeclaration)) {
+ throw new IllegalArgumentException("Array definitions should only come from sequence or array declarations"); //$NON-NLS-1$
+ }
+ CompoundDeclaration arrDecl = (CompoundDeclaration) decl;
+ IDeclaration elemType = null;
+ Collection<Definition> definitions = arrayDef.getDefinitions();
+ elemType = arrDecl.getElementType();
+ if (elemType instanceof IntegerDeclaration) {
+ /* Array of integers => CTFIntegerArrayField, unless it's a CTFStringField */
+ IntegerDeclaration elemIntType = (IntegerDeclaration) elemType;
+ /* Are the integers characters and encoded? */
+ if (elemIntType.isCharacter()) {
+ /* it's a CTFStringField */
+ field = new CTFStringField(fieldName, arrayDef.toString());
+ } else {
+ /* it's a CTFIntegerArrayField */
+ long[] values = new long[arrayDef.getLength()];
+ for (int i = 0; i < arrayDef.getLength(); i++) {
+ IDefinition elem = arrayDef.getDefinitions().get(i);
+ if (elem == null) {
+ break;
+ }
+ values[i] = ((IntegerDefinition) elem).getValue();
+ }
+ field = new CTFIntegerArrayField(fieldName, values,
+ elemIntType.getBase(),
+ elemIntType.isSigned());
+ }
+ } else {
+ /* Arrays of elements of any other type */
+ CtfTmfEventField[] elements = new CtfTmfEventField[arrayDef.getLength()];
+ /* Parse the elements of the array. */
+ int i = 0;
+ for (IDefinition definition : definitions) {
+ CtfTmfEventField curField = CtfTmfEventField.parseField(
+ definition, fieldName + '[' + i + ']');
+ elements[i] = curField;
+ i++;
+ }
+
+ field = new CTFArrayField(fieldName, elements);
+ }
+ } else if (fieldDef instanceof ByteArrayDefinition) {
+ /* This is an array of ascii bytes, a.k.a. a String! */
+ field = new CTFStringField(fieldName, fieldDef.toString());
+
+ } else if (fieldDef instanceof ICompositeDefinition) {
+ ICompositeDefinition strDef = (ICompositeDefinition) fieldDef;
+
+ List<ITmfEventField> list = new ArrayList<>();
+ /* Recursively parse the fields */
+ for (String curFieldName : strDef.getFieldNames()) {
+ list.add(CtfTmfEventField.parseField(strDef.getDefinition(curFieldName), curFieldName));
+ }
+ field = new CTFStructField(fieldName, list.toArray(new CtfTmfEventField[list.size()]));
+
+ } else if (fieldDef instanceof VariantDefinition) {
+ VariantDefinition varDef = (VariantDefinition) fieldDef;
+
+ String curFieldName = varDef.getCurrentFieldName();
+ IDefinition curFieldDef = varDef.getCurrentField();
+ if (curFieldDef != null) {
+ CtfTmfEventField subField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
+ field = new CTFVariantField(fieldName, subField);
+ } else {
+ /* A safe-guard, but curFieldDef should never be null */
+ field = new CTFStringField(curFieldName, ""); //$NON-NLS-1$
+ }
+
+ } else {
+ /*
+ * Safe-guard, to avoid null exceptions later, field is expected not
+ * to be null
+ */
+ field = new CTFStringField(fieldName, Messages.CtfTmfEventField_UnsupportedType + fieldDef.getClass().toString());
+ }
+ return field;
+ }
+
+ @Override
+ public String toString() {
+ return getName() + '=' + getFormattedValue();
+ }
+
+}
+
+/**
+ * The CTF field implementation for integer fields.
+ *
+ * @author alexmont
+ */
+final class CTFIntegerField extends CtfTmfEventField {
+
+ private final int fBase;
+ private final boolean fSigned;
+
+ /**
+ * A CTF "IntegerDefinition" can be an integer of any byte size, so in the
+ * Java parser this is interpreted as a long.
+ *
+ * @param name
+ * The name of this field
+ * @param longValue
+ * The integer value of this field
+ * @param signed
+ * Is the value signed or not
+ */
+ CTFIntegerField(String name, long longValue, int base, boolean signed) {
+ super(name, longValue, null);
+ fSigned = signed;
+ fBase = base;
+ }
+
+ @Override
+ public Long getValue() {
+ return (Long) super.getValue();
+ }
+
+ @Override
+ public String getFormattedValue() {
+ return IntegerDefinition.formatNumber(getValue(), fBase, fSigned);
+ }
+
+}
+
+/**
+ * The CTF field implementation for string fields
+ *
+ * @author alexmont
+ */
+final class CTFStringField extends CtfTmfEventField {
+
+ /**
+ * Constructor for CTFStringField.
+ *
+ * @param strValue
+ * The string value of this field
+ * @param name
+ * The name of this field
+ */
+ CTFStringField(String name, String strValue) {
+ super(name, strValue, null);
+ }
+
+ @Override
+ public String getValue() {
+ return (String) super.getValue();
+ }
+}
+
+/**
+ * CTF field implementation for arrays of integers.
+ *
+ * @author alexmont
+ */
+final class CTFIntegerArrayField extends CtfTmfEventField {
+
+ private final int fBase;
+ private final boolean fSigned;
+ private String fFormattedValue = null;
+
+ /**
+ * Constructor for CTFIntegerArrayField.
+ *
+ * @param name
+ * The name of this field
+ * @param longValues
+ * The array of integers (as longs) that compose this field's
+ * value
+ * @param signed
+ * Are the values in the array signed or not
+ */
+ CTFIntegerArrayField(String name, long[] longValues, int base, boolean signed) {
+ super(name, longValues, null);
+ fBase = base;
+ fSigned = signed;
+ }
+
+ @Override
+ public long[] getValue() {
+ return (long[]) super.getValue();
+ }
+
+ @Override
+ public synchronized String getFormattedValue() {
+ if (fFormattedValue == null) {
+ List<String> strings = new ArrayList<>();
+ for (long value : getValue()) {
+ strings.add(IntegerDefinition.formatNumber(value, fBase, fSigned));
+ }
+ fFormattedValue = strings.toString();
+ }
+ return fFormattedValue;
+ }
+
+}
+
+/**
+ * CTF field implementation for arrays of arbitrary types.
+ *
+ * @author fdoray
+ */
+final class CTFArrayField extends CtfTmfEventField {
+
+ private String fFormattedValue = null;
+
+ /**
+ * Constructor for CTFArrayField.
+ *
+ * @param name
+ * The name of this field
+ * @param elements
+ * The array elements of this field
+ */
+ CTFArrayField(String name, CtfTmfEventField[] elements) {
+ super(name, elements, elements);
+ }
+
+ @Override
+ public CtfTmfEventField[] getValue() {
+ return (CtfTmfEventField[]) super.getValue();
+ }
+
+ @Override
+ public synchronized String getFormattedValue() {
+ if (fFormattedValue == null) {
+ List<String> strings = new ArrayList<>();
+ for (CtfTmfEventField element : getValue()) {
+ strings.add(element.getFormattedValue());
+ }
+ fFormattedValue = strings.toString();
+ }
+ return fFormattedValue;
+ }
+}
+
+/**
+ * CTF field implementation for floats.
+ *
+ * @author emathko
+ */
+final class CTFFloatField extends CtfTmfEventField {
+
+ /**
+ * Constructor for CTFFloatField.
+ *
+ * @param value
+ * The float value (actually a double) of this field
+ * @param name
+ * The name of this field
+ */
+ protected CTFFloatField(String name, double value) {
+ super(name, value, null);
+ }
+
+ @Override
+ public Double getValue() {
+ return (Double) super.getValue();
+ }
+}
+
+/**
+ * The CTF field implementation for Enum fields
+ *
+ * @author Bernd Hufmann
+ */
+final class CTFEnumField extends CtfTmfEventField {
+
+ /**
+ * Constructor for CTFEnumField.
+ *
+ * @param enumValue
+ * The Enum value consisting of a pair of Enum value name and its
+ * long value
+ * @param name
+ * The name of this field
+ */
+ CTFEnumField(String name, CtfEnumPair enumValue) {
+ super(name, new CtfEnumPair(enumValue.getFirst(),
+ enumValue.getSecond()), null);
+ }
+
+ @Override
+ public CtfEnumPair getValue() {
+ return (CtfEnumPair) super.getValue();
+ }
+}
+
+/**
+ * The CTF field implementation for struct fields with sub-fields
+ *
+ * @author gbastien
+ */
+final class CTFStructField extends CtfTmfEventField {
+
+ /**
+ * Constructor for CTFStructField.
+ *
+ * @param fields
+ * The children of this field
+ * @param name
+ * The name of this field
+ */
+ CTFStructField(String name, CtfTmfEventField[] fields) {
+ super(name, fields, fields);
+ }
+
+ @Override
+ public CtfTmfEventField[] getValue() {
+ return (CtfTmfEventField[]) super.getValue();
+ }
+
+ @Override
+ public String getFormattedValue() {
+ return Arrays.toString(getValue());
+ }
+
+}
+
+/**
+ * The CTF field implementation for variant fields its child
+ *
+ * @author gbastien
+ */
+final class CTFVariantField extends CtfTmfEventField {
+
+ /**
+ * Constructor for CTFVariantField.
+ *
+ * @param field
+ * The field selected for this variant
+ * @param name
+ * The name of this field
+ */
+ CTFVariantField(String name, CtfTmfEventField field) {
+ super(name, field, new CtfTmfEventField[] { field });
+ }
+
+ @Override
+ public CtfTmfEventField getValue() {
+ return (CtfTmfEventField) super.getValue();
+ }
+
+}
+
+/* Implement other possible fields types here... */
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.event;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
+
+/**
+ * The CTF extension of the TMF event type
+ *
+ * @author Matthew khouzam
+ */
+public class CtfTmfEventType extends TmfEventType {
+
+ /**
+ * Constructor for CtfTmfEventType.
+ *
+ * @param eventName
+ * The event name
+ * @param content
+ * The event field
+ * @since 3.0
+ */
+ public CtfTmfEventType(String eventName, ITmfEventField content) {
+ super(eventName, content);
+ }
+
+ /**
+ * Method toString.
+ *
+ * @return String
+ */
+ @Override
+ public String toString() {
+ return getName();
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.event;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
+import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
+import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.ctf.core.timestamp.CtfTmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * An implementation of {@link ITmfLostEvent} for use in the CTF adaptor.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.2
+ */
+public class CtfTmfLostEvent extends CtfTmfEvent implements ITmfLostEvent {
+
+ private final TmfTimeRange fTimeRange;
+ private final long fNbLost;
+
+ /**
+ * Constructor. Only {@link CtfTmfEventFactory} should call this.
+ *
+ * @param trace
+ * The origin trace
+ * @param rank
+ * The rank of the event in the trace
+ * @param content
+ * The event's payload (fields). In case this event has some.
+ * @param fileName
+ * The name of the trace file from which this event comes
+ * @param cpu
+ * The CPU on which this event happened
+ * @param declaration
+ * The CTF Event Declaration object that created this event
+ * @param timeRange
+ * The time range of lost events indicated by this one
+ * @param nbLost
+ * The number of lost events in the range
+ */
+ CtfTmfLostEvent(CtfTmfTrace trace,
+ long rank,
+ String fileName,
+ int cpu,
+ IEventDeclaration declaration,
+ TmfTimeRange timeRange,
+ long nbLost,
+ @NonNull EventDefinition def) {
+ /*
+ * Only the factory should call this method, the case to
+ * (CtfTmfTimestamp) should be safe.
+ */
+ super(trace, rank, (CtfTmfTimestamp) timeRange.getStartTime(), fileName, cpu, declaration, def);
+ fTimeRange = timeRange;
+ fNbLost = nbLost;
+ }
+
+ @Override
+ public TmfTimeRange getTimeRange() {
+ return fTimeRange;
+ }
+
+ @Override
+ public long getNbLostEvents() {
+ return fNbLost;
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.event;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Message bundle for tmf.ctf.core.event
+ *
+ * @author Matthew Khouzam
+ */
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.tracecompass.tmf.ctf.core.event.messages"; //$NON-NLS-1$
+
+ /** Unsupported field type */
+ public static String CtfTmfEventField_UnsupportedType;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ * Bernd Hufmann - Updated for new parent class
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.event.lookup;
+
+import org.eclipse.tracecompass.ctf.core.event.CTFCallsite;
+import org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite;
+
+/**
+ * CTF TMF call site information for source code lookup.
+ *
+ * @author Patrick Tasse
+ * @since 2.0
+ */
+public class CtfTmfCallsite extends TmfCallsite {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ /** The event name. */
+ private final String fEventName;
+
+ /** The instruction pointer. */
+ private final long fInstructionPointer;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Standard Constructor.
+ *
+ * @param callsite
+ * - a CTF call site
+ */
+ public CtfTmfCallsite(CTFCallsite callsite) {
+ super(callsite.getFileName(), callsite.getFunctionName(), callsite.getLineNumber());
+ fEventName = callsite.getEventName();
+ fInstructionPointer = callsite.getIp();
+ }
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Returns the event name of the call site.
+ * @return the event name
+ */
+ public String getEventName() {
+ return fEventName;
+ }
+
+ /**
+ * Returns the instruction pointer of the call site.
+ * @return the instruction pointer
+ */
+ public long getIntructionPointer() {
+ return fInstructionPointer;
+ }
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((fEventName == null) ? 0 : fEventName.hashCode());
+ result = prime * result + (int) (fInstructionPointer ^ (fInstructionPointer >>> 32));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ CtfTmfCallsite other = (CtfTmfCallsite) obj;
+ if (fEventName == null) {
+ if (other.fEventName != null) {
+ return false;
+ }
+ } else if (!fEventName.equals(other.fEventName)) {
+ return false;
+ }
+ if (fInstructionPointer != other.fInstructionPointer) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return getEventName() + "@0x" + Long.toHexString(fInstructionPointer) + ": " + //$NON-NLS-1$ //$NON-NLS-2$
+ getFileName() + ':' + Long.toString(getLineNumber()) + ' ' + getFileName() + "()"; //$NON-NLS-1$
+ }
+}
--- /dev/null
+###############################################################################
+# Copyright (c) 2014 Ericsson
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Ericsson - Initial API and implementation
+###############################################################################
+
+CtfTmfEventField_UnsupportedType=Unsupported field type:
\ No newline at end of file
+++ /dev/null
-###############################################################################
-# Copyright (c) 2013 Ericsson
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# Ericsson - Initial API and implementation
-###############################################################################
-
-CtfTmfTrace_BufferOverflowErrorMessage=Buffer overflow exception, trace is malformed
-CtfTmfTrace_HostID=host ID
-CtfTmfTrace_MajorNotSet=Major version number not set
-CtfTmfTrace_ReadingError=Reading error
-CtfTmfTrace_NoEvent=Trace has no events
-CtfTmfEventField_UnsupportedType=Unsupported field type:
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.timestamp;
+
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+
+/**
+ * The CTF adapter for the TMF timestamp. It's basically the same as a
+ * TmfTimestamp, but the scale is always nanoseconds, and the precision is 0.
+ *
+ * @version 1.2
+ * @author Matthew khouzam
+ */
+public final class CtfTmfTimestamp extends TmfTimestamp {
+
+ /**
+ * Constructor for CtfTmfTimestamp.
+ *
+ * @param timestamp
+ * The timestamp value (in nanoseconds)
+ */
+ public CtfTmfTimestamp(long timestamp) {
+ super(timestamp, ITmfTimestamp.NANOSECOND_SCALE);
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ * Patrick Tasse - Updated for removal of context clone
+ * Geneviève Bastien - Added the createTimestamp function
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.trace;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.tracecompass.ctf.core.event.CTFClock;
+import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
+import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
+import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
+import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
+import org.eclipse.tracecompass.internal.tmf.ctf.core.Activator;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfEventParser;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceProperties;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.TmfBTreeTraceIndexer;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint;
+import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.tracecompass.tmf.ctf.core.CtfConstants;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType;
+import org.eclipse.tracecompass.tmf.ctf.core.timestamp.CtfTmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.iterator.CtfIterator;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.iterator.CtfIteratorManager;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * The CTf trace handler
+ *
+ * @version 1.0
+ * @author Matthew khouzam
+ */
+public class CtfTmfTrace extends TmfTrace
+ implements ITmfEventParser, ITmfTraceProperties, ITmfPersistentlyIndexable,
+ ITmfTraceWithPreDefinedEvents, AutoCloseable {
+
+ // -------------------------------------------
+ // Constants
+ // -------------------------------------------
+ /**
+ * Default cache size for CTF traces
+ */
+ protected static final int DEFAULT_CACHE_SIZE = 50000;
+
+ /*
+ * The Ctf clock unique identifier field
+ */
+ private static final String CLOCK_HOST_PROPERTY = "uuid"; //$NON-NLS-1$
+ private static final int CONFIDENCE = 10;
+
+ // -------------------------------------------
+ // Fields
+ // -------------------------------------------
+
+ private final Map<String, CtfTmfEventType> fContainedEventTypes =
+ Collections.synchronizedMap(new HashMap<String, CtfTmfEventType>());
+
+ private final CtfIteratorManager fIteratorManager =
+ new CtfIteratorManager(this);
+
+ /* Reference to the CTF Trace */
+ private CTFTrace fTrace;
+
+ // -------------------------------------------
+ // TmfTrace Overrides
+ // -------------------------------------------
+ /**
+ * Method initTrace.
+ *
+ * @param resource
+ * The resource associated with this trace
+ * @param path
+ * The path to the trace file
+ * @param eventType
+ * The type of events that will be read from this trace
+ * @throws TmfTraceException
+ * If something went wrong while reading the trace
+ */
+ @Override
+ public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType)
+ throws TmfTraceException {
+ /*
+ * Set the cache size. This has to be done before the call to super()
+ * because the super needs to know the cache size.
+ */
+ setCacheSize();
+
+ super.initTrace(resource, path, eventType);
+
+ try {
+ this.fTrace = new CTFTrace(path);
+ CtfTmfContext ctx;
+ /* Set the start and (current) end times for this trace */
+ ctx = (CtfTmfContext) seekEvent(0L);
+ CtfTmfEvent event = getNext(ctx);
+ if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
+ /* Handle the case where the trace is empty */
+ this.setStartTime(TmfTimestamp.BIG_BANG);
+ } else {
+ final ITmfTimestamp curTime = event.getTimestamp();
+ this.setStartTime(curTime);
+ this.setEndTime(curTime);
+ }
+ /*
+ * Register every event type. When you call getType, it will
+ * register a trace to that type in the TmfEventTypeManager
+ */
+ try (CtfIterator iter = fIteratorManager.getIterator(ctx)) {
+ for (IEventDeclaration ied : iter.getEventDeclarations()) {
+ CtfTmfEventType ctfTmfEventType = fContainedEventTypes.get(ied.getName());
+ if (ctfTmfEventType == null) {
+ List<ITmfEventField> content = new ArrayList<>();
+ /* Should only return null the first time */
+ for (String fieldName : ied.getFields().getFieldsList()) {
+ content.add(new TmfEventField(fieldName, null, null));
+ }
+ ITmfEventField contentTree = new TmfEventField(
+ ITmfEventField.ROOT_FIELD_ID,
+ null,
+ content.toArray(new ITmfEventField[content.size()])
+ );
+
+ ctfTmfEventType = new CtfTmfEventType(ied.getName(), contentTree);
+ fContainedEventTypes.put(ctfTmfEventType.getName(), ctfTmfEventType);
+ }
+ }
+ }
+ } catch (final CTFReaderException e) {
+ /*
+ * If it failed at the init(), we can assume it's because the file
+ * was not found or was not recognized as a CTF trace. Throw into
+ * the new type of exception expected by the rest of TMF.
+ */
+ throw new TmfTraceException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Return the iterator manager of this trace
+ *
+ * @return The iterator manager
+ */
+ public CtfIteratorManager getIteratorManager() {
+ return fIteratorManager;
+ }
+
+ @Override
+ public void close() {
+ dispose();
+ }
+
+ @Override
+ public synchronized void dispose() {
+ fIteratorManager.dispose();
+ if (fTrace != null) {
+ fTrace.close();
+ fTrace = null;
+ }
+ super.dispose();
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * The default implementation sets the confidence to 10 if the trace is a
+ * valid CTF trace.
+ */
+ @Override
+ public IStatus validate(final IProject project, final String path) {
+ IStatus status = new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
+ try (final CTFTrace temp = new CTFTrace(path);) {
+ if (!temp.majorIsSet()) {
+ status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
+ } else {
+ try (CTFTraceReader ctfTraceReader = new CTFTraceReader(temp);) {
+ if (!ctfTraceReader.hasMoreEvents()) {
+ // TODO: This will need an additional check when we
+ // support live traces
+ // because having no event is valid for a live trace
+ status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_NoEvent);
+ }
+ }
+ }
+ } catch (final CTFReaderException e) {
+ status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString()); //$NON-NLS-1$
+ } catch (final BufferOverflowException e) {
+ status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + Messages.CtfTmfTrace_BufferOverflowErrorMessage); //$NON-NLS-1$
+ }
+
+ return status;
+ }
+
+ /**
+ * Method getCurrentLocation. This is not applicable in CTF
+ *
+ * @return null, since the trace has no knowledge of the current location
+ * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getCurrentLocation()
+ * @since 3.0
+ */
+ @Override
+ public ITmfLocation getCurrentLocation() {
+ return null;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public double getLocationRatio(ITmfLocation location) {
+ final CtfLocation curLocation = (CtfLocation) location;
+ final CtfTmfContext context = new CtfTmfContext(this);
+ context.setLocation(curLocation);
+ context.seek(curLocation.getLocationInfo());
+ final CtfLocationInfo currentTime = ((CtfLocationInfo) context.getLocation().getLocationInfo());
+ final long startTime = fIteratorManager.getIterator(context).getStartTime();
+ final long endTime = fIteratorManager.getIterator(context).getEndTime();
+ return ((double) currentTime.getTimestamp() - startTime)
+ / (endTime - startTime);
+ }
+
+ /**
+ * Method seekEvent.
+ *
+ * @param location
+ * ITmfLocation<?>
+ * @return ITmfContext
+ * @since 3.0
+ */
+ @Override
+ public synchronized ITmfContext seekEvent(final ITmfLocation location) {
+ CtfLocation currentLocation = (CtfLocation) location;
+ CtfTmfContext context = new CtfTmfContext(this);
+ if (fTrace == null) {
+ context.setLocation(null);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+ return context;
+ }
+ /*
+ * The rank is set to 0 if the iterator seeks the beginning. If not, it
+ * will be set to UNKNOWN_RANK, since CTF traces don't support seeking
+ * by rank for now.
+ */
+ if (currentLocation == null) {
+ currentLocation = new CtfLocation(new CtfLocationInfo(0L, 0L));
+ context.setRank(0);
+ }
+ if (currentLocation.getLocationInfo() == CtfLocation.INVALID_LOCATION) {
+ currentLocation = new CtfLocation(getCTFTrace().getCurrentEndTime() + 1, 0L);
+ }
+ context.setLocation(currentLocation);
+ if (location == null) {
+ long timestamp = fIteratorManager.getIterator(context).getCurrentTimestamp();
+ currentLocation = new CtfLocation(timestamp, 0);
+ }
+ if (context.getRank() != 0) {
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+ }
+ return context;
+ }
+
+ @Override
+ public synchronized ITmfContext seekEvent(double ratio) {
+ CtfTmfContext context = new CtfTmfContext(this);
+ if (fTrace == null) {
+ context.setLocation(null);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+ return context;
+ }
+ final long end = getCTFTrace().getCurrentEndTime();
+ final long start = getCTFTrace().getCurrentStartTime();
+ final long diff = end - start;
+ final long ratioTs = Math.round(diff * ratio) + start;
+ context.seek(ratioTs);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+ return context;
+ }
+
+ /**
+ * Method readNextEvent.
+ *
+ * @param context
+ * ITmfContext
+ * @return CtfTmfEvent
+ * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getNext(ITmfContext)
+ */
+ @Override
+ public synchronized CtfTmfEvent getNext(final ITmfContext context) {
+ if (fTrace == null) {
+ return null;
+ }
+ CtfTmfEvent event = null;
+ if (context instanceof CtfTmfContext) {
+ if (context.getLocation() == null || CtfLocation.INVALID_LOCATION.equals(context.getLocation().getLocationInfo())) {
+ return null;
+ }
+ CtfTmfContext ctfContext = (CtfTmfContext) context;
+ event = ctfContext.getCurrentEvent();
+
+ if (event != null) {
+ updateAttributes(context, event.getTimestamp());
+ ctfContext.advance();
+ ctfContext.increaseRank();
+ }
+ }
+
+ return event;
+ }
+
+ /**
+ * gets the CTFtrace that this is wrapping
+ *
+ * @return the CTF trace
+ */
+ public CTFTrace getCTFTrace() {
+ return fTrace;
+ }
+
+ /**
+ * Ctf traces have a clock with a unique uuid that will be used to identify
+ * the host. Traces with the same clock uuid will be known to have been made
+ * on the same machine.
+ *
+ * Note: uuid is an optional field, it may not be there for a clock.
+ */
+ @Override
+ public String getHostId() {
+ CTFClock clock = getCTFTrace().getClock();
+ if (clock != null) {
+ String clockHost = (String) clock.getProperty(CLOCK_HOST_PROPERTY);
+ if (clockHost != null) {
+ return clockHost;
+ }
+ }
+ return super.getHostId();
+ }
+
+ // -------------------------------------------
+ // ITmfTraceProperties
+ // -------------------------------------------
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public Map<String, String> getTraceProperties() {
+ Map<String, String> properties = new HashMap<>();
+ properties.putAll(fTrace.getEnvironment());
+ properties.put(Messages.CtfTmfTrace_HostID, getHostId());
+ return properties;
+ }
+
+ // -------------------------------------------
+ // Clocks
+ // -------------------------------------------
+
+ /**
+ * gets the clock offset
+ *
+ * @return the clock offset in ns
+ */
+ public long getOffset() {
+ if (fTrace != null) {
+ return fTrace.getOffset();
+ }
+ return 0;
+ }
+
+ /**
+ * Gets the list of declared events
+ *
+ * @since 3.0
+ */
+ @Override
+ public Set<CtfTmfEventType> getContainedEventTypes() {
+ return ImmutableSet.copyOf(fContainedEventTypes.values());
+ }
+
+ /**
+ * Register an event type to this trace.
+ *
+ * Public visibility so that {@link CtfTmfEvent#getType} can call it.
+ *
+ * FIXME This could probably be made cleaner?
+ *
+ * @param eventType
+ * The event type to register
+ */
+ public void registerEventType(CtfTmfEventType eventType) {
+ fContainedEventTypes.put(eventType.getName(), eventType);
+ }
+
+ // -------------------------------------------
+ // Parser
+ // -------------------------------------------
+
+ @Override
+ public CtfTmfEvent parseEvent(ITmfContext context) {
+ CtfTmfEvent event = null;
+ if (context instanceof CtfTmfContext) {
+ final ITmfContext tmpContext = seekEvent(context.getLocation());
+ event = getNext(tmpContext);
+ }
+ return event;
+ }
+
+ /**
+ * Sets the cache size for a CtfTmfTrace.
+ */
+ protected void setCacheSize() {
+ setCacheSize(DEFAULT_CACHE_SIZE);
+ }
+
+ // -------------------------------------------
+ // Helpers
+ // -------------------------------------------
+
+ /**
+ * Get an iterator to the trace
+ *
+ * @return an iterator to the trace
+ * @since 2.0
+ */
+ public CtfIterator createIterator() {
+ try {
+ return new CtfIterator(this);
+ } catch (CTFReaderException e) {
+ Activator.getDefault().logError(e.getMessage(), e);
+ }
+ return null;
+ }
+
+ // ------------------------------------------------------------------------
+ // Timestamp transformation functions
+ // ------------------------------------------------------------------------
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public CtfTmfTimestamp createTimestamp(long ts) {
+ return new CtfTmfTimestamp(getTimestampTransform().transform(ts));
+ }
+
+ private static int fCheckpointSize = -1;
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public synchronized int getCheckpointSize() {
+ if (fCheckpointSize == -1) {
+ TmfCheckpoint c = new TmfCheckpoint(new CtfTmfTimestamp(0), new CtfLocation(0, 0), 0);
+ ByteBuffer b = ByteBuffer.allocate(ITmfCheckpoint.MAX_SERIALIZE_SIZE);
+ b.clear();
+ c.serialize(b);
+ fCheckpointSize = b.position();
+ }
+
+ return fCheckpointSize;
+ }
+
+ @Override
+ protected ITmfTraceIndexer createIndexer(int interval) {
+ return new TmfBTreeTraceIndexer(this, interval);
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public ITmfLocation restoreLocation(ByteBuffer bufferIn) {
+ return new CtfLocation(bufferIn);
+ }
+
+ @Override
+ public boolean isComplete() {
+ if (getResource() == null) {
+ return true;
+ }
+
+ String host = null;
+ String port = null;
+ String sessionName = null;
+ try {
+ host = getResource().getPersistentProperty(CtfConstants.LIVE_HOST);
+ port = getResource().getPersistentProperty(CtfConstants.LIVE_PORT);
+ sessionName = getResource().getPersistentProperty(CtfConstants.LIVE_SESSION_NAME);
+ } catch (CoreException e) {
+ Activator.getDefault().logError(e.getMessage(), e);
+ // Something happened to the resource, assume we won't get any more data from it
+ return true;
+ }
+ return host == null || port == null || sessionName == null;
+ }
+
+ @Override
+ public void setComplete(final boolean isComplete) {
+ super.setComplete(isComplete);
+ try {
+ if (isComplete) {
+ getResource().setPersistentProperty(CtfConstants.LIVE_HOST, null);
+ getResource().setPersistentProperty(CtfConstants.LIVE_PORT, null);
+ getResource().setPersistentProperty(CtfConstants.LIVE_SESSION_NAME, null);
+ }
+ } catch (CoreException e) {
+ Activator.getDefault().logError(e.getMessage(), e);
+ }
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.trace;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Message bundle for tmf.ctf.core.trace
+ *
+ * @author Matthew Khouzam
+ */
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.tracecompass.tmf.ctf.core.trace.messages"; //$NON-NLS-1$
+
+ /** Buffer overflow detected */
+ public static String CtfTmfTrace_BufferOverflowErrorMessage;
+
+ /** Text for host ID */
+ public static String CtfTmfTrace_HostID;
+
+ /** Major version number not set */
+ public static String CtfTmfTrace_MajorNotSet;
+
+ /** Reading error */
+ public static String CtfTmfTrace_ReadingError;
+
+ /** No event */
+ public static String CtfTmfTrace_NoEvent;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ * Florian Wininger - Performance improvements
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.trace.iterator;
+
+import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
+import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInputReader;
+import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
+import org.eclipse.tracecompass.internal.tmf.ctf.core.Activator;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventFactory;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * The CTF trace reader iterator.
+ *
+ * It doesn't reserve a file handle, so many iterators can be used without
+ * worries of I/O errors or resource exhaustion.
+ *
+ * @author Matthew Khouzam
+ */
+public class CtfIterator extends CTFTraceReader
+ implements ITmfContext, Comparable<CtfIterator> {
+
+ /** An invalid location */
+ public static final CtfLocation NULL_LOCATION = new CtfLocation(CtfLocation.INVALID_LOCATION);
+
+ private final CtfTmfTrace fTrace;
+
+ private CtfLocation fCurLocation;
+ private long fCurRank;
+
+ private CtfLocation fPreviousLocation;
+ private CtfTmfEvent fPreviousEvent;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Create a new CTF trace iterator, which initially points at the first
+ * event in the trace.
+ *
+ * @param trace
+ * The trace to iterate over
+ * @throws CTFReaderException
+ * If the iterator couldn't not be instantiated, probably due to
+ * a read error.
+ */
+ public CtfIterator(CtfTmfTrace trace) throws CTFReaderException {
+ super(trace.getCTFTrace());
+ fTrace = trace;
+ if (hasMoreEvents()) {
+ fCurLocation = new CtfLocation(trace.getStartTime());
+ fCurRank = 0;
+ } else {
+ setUnknownLocation();
+ }
+ }
+
+ /**
+ * Create a new CTF trace iterator, which will initially point to the given
+ * location/rank.
+ *
+ * @param trace
+ * The trace to iterate over
+ * @param ctfLocationData
+ * The initial timestamp the iterator will be pointing to
+ * @param rank
+ * The initial rank
+ * @throws CTFReaderException
+ * If the iterator couldn't not be instantiated, probably due to
+ * a read error.
+ * @since 2.0
+ */
+ public CtfIterator(CtfTmfTrace trace, CtfLocationInfo ctfLocationData, long rank)
+ throws CTFReaderException {
+ super(trace.getCTFTrace());
+
+ this.fTrace = trace;
+ if (this.hasMoreEvents()) {
+ this.fCurLocation = new CtfLocation(ctfLocationData);
+ if (this.getCurrentEvent().getTimestamp().getValue() != ctfLocationData.getTimestamp()) {
+ this.seek(ctfLocationData);
+ this.fCurRank = rank;
+ }
+ } else {
+ setUnknownLocation();
+ }
+ }
+
+ @Override
+ public void dispose() {
+ close();
+ }
+
+ private void setUnknownLocation() {
+ fCurLocation = NULL_LOCATION;
+ fCurRank = UNKNOWN_RANK;
+ }
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Return this iterator's trace.
+ *
+ * @return CtfTmfTrace The iterator's trace
+ */
+ public CtfTmfTrace getCtfTmfTrace() {
+ return fTrace;
+ }
+
+ /**
+ * Return the current event pointed to by the iterator.
+ *
+ * @return CtfTmfEvent The current event
+ */
+ public synchronized CtfTmfEvent getCurrentEvent() {
+ final CTFStreamInputReader top = super.getPrio().peek();
+ if (top != null) {
+ if (!fCurLocation.equals(fPreviousLocation)) {
+ fPreviousLocation = fCurLocation;
+ fPreviousEvent = CtfTmfEventFactory.createEvent(top.getCurrentEvent(),
+ top.getFilename(), fTrace);
+ }
+ return fPreviousEvent;
+ }
+ return null;
+ }
+
+ /**
+ * Return the current timestamp location pointed to by the iterator.
+ * This is the timestamp for use in CtfLocation, not the event timestamp.
+ *
+ * @return long The current timestamp location
+ */
+ public synchronized long getCurrentTimestamp() {
+ final CTFStreamInputReader top = super.getPrio().peek();
+ if (top != null) {
+ long ts = top.getCurrentEvent().getTimestamp();
+ return fTrace.getCTFTrace().timestampCyclesToNanos(ts);
+ }
+ return 0;
+ }
+
+ /**
+ * Seek this iterator to a given location.
+ *
+ * @param ctfLocationData
+ * The LocationData representing the position to seek to
+ * @return boolean True if the seek was successful, false if there was an
+ * error seeking.
+ * @since 2.0
+ */
+ public synchronized boolean seek(CtfLocationInfo ctfLocationData) {
+ boolean ret = false;
+
+ /* Avoid the cost of seeking at the current location. */
+ if (fCurLocation.getLocationInfo().equals(ctfLocationData)) {
+ return super.hasMoreEvents();
+ }
+
+ /* Adjust the timestamp depending on the trace's offset */
+ long currTimestamp = ctfLocationData.getTimestamp();
+ final long offsetTimestamp = this.getCtfTmfTrace().getCTFTrace().timestampNanoToCycles(currTimestamp);
+ try {
+ if (offsetTimestamp < 0) {
+ ret = super.seek(0L);
+ } else {
+ ret = super.seek(offsetTimestamp);
+ }
+ } catch (CTFReaderException e) {
+ Activator.getDefault().logError(e.getMessage(), e);
+ return false;
+ }
+ /*
+ * Check if there is already one or more events for that timestamp, and
+ * assign the location index correctly
+ */
+ long index = 0;
+ final CtfTmfEvent currentEvent = this.getCurrentEvent();
+ if (currentEvent != null) {
+ currTimestamp = currentEvent.getTimestamp().getValue();
+
+ for (long i = 0; i < ctfLocationData.getIndex(); i++) {
+ if (currTimestamp == currentEvent.getTimestamp().getValue()) {
+ index++;
+ } else {
+ index = 0;
+ }
+ this.advance();
+ }
+ } else {
+ ret = false;
+ }
+ /* Seek the current location accordingly */
+ if (ret) {
+ fCurLocation = new CtfLocation(new CtfLocationInfo(getCurrentEvent().getTimestamp().getValue(), index));
+ } else {
+ fCurLocation = NULL_LOCATION;
+ }
+
+ return ret;
+ }
+
+ // ------------------------------------------------------------------------
+ // CTFTraceReader
+ // ------------------------------------------------------------------------
+
+ @Override
+ public boolean seek(long timestamp) {
+ return seek(new CtfLocationInfo(timestamp, 0));
+ }
+
+ @Override
+ public synchronized boolean advance() {
+ boolean ret = false;
+ try {
+ ret = super.advance();
+ } catch (CTFReaderException e) {
+ Activator.getDefault().logError(e.getMessage(), e);
+ }
+
+ if (ret) {
+ long timestamp = fCurLocation.getLocationInfo().getTimestamp();
+ final long timestampValue = getCurrentTimestamp();
+ if (timestamp == timestampValue) {
+ long index = fCurLocation.getLocationInfo().getIndex();
+ fCurLocation = new CtfLocation(timestampValue, index + 1);
+ } else {
+ fCurLocation = new CtfLocation(timestampValue, 0L);
+ }
+ } else {
+ fCurLocation = NULL_LOCATION;
+ }
+ return ret;
+ }
+
+ // ------------------------------------------------------------------------
+ // ITmfContext
+ // ------------------------------------------------------------------------
+
+ @Override
+ public long getRank() {
+ return fCurRank;
+ }
+
+ @Override
+ public void setRank(long rank) {
+ fCurRank = rank;
+ }
+
+ @Override
+ public void increaseRank() {
+ /* Only increase the rank if it's valid */
+ if (hasValidRank()) {
+ fCurRank++;
+ }
+ }
+
+ @Override
+ public boolean hasValidRank() {
+ return (getRank() >= 0);
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public void setLocation(ITmfLocation location) {
+ // FIXME alex: isn't there a cleaner way than a cast here?
+ fCurLocation = (CtfLocation) location;
+ seek(((CtfLocation) location).getLocationInfo());
+ }
+
+ @Override
+ public CtfLocation getLocation() {
+ return fCurLocation;
+ }
+
+ // ------------------------------------------------------------------------
+ // Comparable
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int compareTo(final CtfIterator o) {
+ if (getRank() < o.getRank()) {
+ return -1;
+ } else if (getRank() > o.getRank()) {
+ return 1;
+ }
+ return 0;
+ }
+
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = (prime * result)
+ + ((fTrace == null) ? 0 : fTrace.hashCode());
+ result = (prime * result)
+ + ((fCurLocation == null) ? 0 : fCurLocation.hashCode());
+ result = (prime * result) + (int) (fCurRank ^ (fCurRank >>> 32));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof CtfIterator)) {
+ return false;
+ }
+ CtfIterator other = (CtfIterator) obj;
+ if (fTrace == null) {
+ if (other.fTrace != null) {
+ return false;
+ }
+ } else if (!fTrace.equals(other.fTrace)) {
+ return false;
+ }
+ if (fCurLocation == null) {
+ if (other.fCurLocation != null) {
+ return false;
+ }
+ } else if (!fCurLocation.equals(other.fCurLocation)) {
+ return false;
+ }
+ if (fCurRank != other.fCurRank) {
+ return false;
+ }
+ return true;
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Renamed/extracted from CtfTraceManager
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.trace.iterator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Random;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
+import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * A CTF trace iterator manager.
+ *
+ * Each instance of {@link CtfTmfTrace} should possess one of these, which will
+ * manage the iterators that are opened to read that trace. This will allow
+ * controlling the number of opened file handles per trace.
+ *
+ * @author Matthew Khouzam
+ */
+public class CtfIteratorManager {
+ /*
+ * Cache size. Under 1023 on linux32 systems. Number of file handles
+ * created.
+ */
+ private final static int MAX_SIZE = 100;
+
+ /** The map of the cache */
+ private final HashMap<CtfTmfContext, CtfIterator> fMap;
+
+ /** An array pointing to the same cache. this allows fast "random" accesses */
+ private final ArrayList<CtfTmfContext> fRandomAccess;
+
+ /** Lock for when we access the two previous data structures */
+ private final Lock fAccessLock = new ReentrantLock();
+
+ /** The parent trace */
+ private final CtfTmfTrace fTrace;
+
+ /** Random number generator */
+ private final Random fRnd;
+
+ /**
+ * Constructor
+ *
+ * @param trace
+ * The trace whose iterators this manager will manage
+ */
+ public CtfIteratorManager(CtfTmfTrace trace) {
+ fMap = new HashMap<>();
+ fRandomAccess = new ArrayList<>();
+ fRnd = new Random(System.nanoTime());
+ fTrace = trace;
+ }
+
+ /**
+ * This needs explaining: the iterator table is effectively a cache.
+ * Originally the contexts had a 1 to 1 structure with the file handles of a
+ * trace. This failed since there is a limit to how many file handles we can
+ * have opened simultaneously. Then a round-robin scheme was implemented,
+ * this lead up to a two competing contexts syncing up and using the same
+ * file handler, causing horrible slowdowns. Now a random replacement
+ * algorithm is selected. This is the same as used by arm processors, and it
+ * works quite well when many cores so this looks promising for very
+ * multi-threaded systems.
+ *
+ * @param context
+ * the context to look up
+ * @return the iterator referring to the context
+ */
+ public CtfIterator getIterator(final CtfTmfContext context) {
+ /*
+ * if the element is in the map, we don't need to do anything else.
+ */
+ CtfIterator iter = fMap.get(context);
+ if (iter == null) {
+
+ fAccessLock.lock();
+ try {
+ /*
+ * Assign an iterator to a context.
+ */
+ if (fRandomAccess.size() < MAX_SIZE) {
+ /*
+ * if we're not full yet, just add an element.
+ */
+ iter = fTrace.createIterator();
+ addElement(context, iter);
+
+ } else {
+ /*
+ * if we're full, randomly replace an element
+ */
+ iter = replaceRandomElement(context);
+ }
+ if (context.getLocation() != null) {
+ final CtfLocationInfo location = (CtfLocationInfo) context.getLocation().getLocationInfo();
+ iter.seek(location);
+ }
+ } finally {
+ fAccessLock.unlock();
+ }
+ }
+ return iter;
+ }
+
+ /**
+ * Remove an iterator from this manager
+ *
+ * @param context
+ * The context of the iterator to remove
+ */
+ public void removeIterator(CtfTmfContext context) {
+ fAccessLock.lock();
+ try {
+ /* The try below is only to auto-call CtfIterator.close() */
+ try (CtfIterator removed = fMap.remove(context)) {
+ }
+ fRandomAccess.remove(context);
+
+ } finally {
+ fAccessLock.unlock();
+ }
+ }
+
+ /**
+ * Add a pair of context and element to the hashmap and the arraylist.
+ *
+ * @param context
+ * the context
+ * @param elem
+ * the iterator
+ */
+ private void addElement(final CtfTmfContext context,
+ final CtfIterator elem) {
+ fAccessLock.lock();
+ try {
+ fMap.put(context, elem);
+ fRandomAccess.add(context);
+
+ } finally {
+ fAccessLock.unlock();
+ }
+ }
+
+ /**
+ * Replace a random element
+ *
+ * @param context
+ * the context to swap in
+ * @return the iterator of the removed elements.
+ */
+ private CtfIterator replaceRandomElement(final CtfTmfContext context) {
+ /*
+ * This needs some explanation too: We need to select a random victim
+ * and remove it. The order of the elements is not important, so instead
+ * of just calling arraylist.remove(element) which has an O(n)
+ * complexity, we pick an random number. The element is swapped out of
+ * the array and removed and replaced in the hashmap.
+ */
+ fAccessLock.lock(); // just in case, should only be called when already locked
+ try {
+ final int size = fRandomAccess.size();
+ final int pos = fRnd.nextInt(size);
+ final CtfTmfContext victim = fRandomAccess.get(pos);
+ fRandomAccess.set(pos, context);
+ final CtfIterator elem = fMap.remove(victim);
+ fMap.put(context, elem);
+ victim.dispose();
+ return elem;
+
+ } finally {
+ fAccessLock.unlock();
+ }
+ }
+
+ /**
+ * Dispose this iterator manager, which will close all the remaining
+ * iterators.
+ */
+ public void dispose() {
+ fAccessLock.lock();
+ try {
+ for (CtfIterator iterator : fMap.values()) {
+ iterator.dispose();
+ }
+ fMap.clear();
+ fRandomAccess.clear();
+
+ } finally {
+ fAccessLock.unlock();
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+###############################################################################
+# Copyright (c) 2013 Ericsson
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Ericsson - Initial API and implementation
+###############################################################################
+
+CtfTmfTrace_BufferOverflowErrorMessage=Buffer overflow exception, trace is malformed
+CtfTmfTrace_HostID=host ID
+CtfTmfTrace_MajorNotSet=Major version number not set
+CtfTmfTrace_ReadingError=Reading error
+CtfTmfTrace_NoEvent=Trace has no events
\ No newline at end of file
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
+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.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfTracesFolder;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.SWTBotUtil;