javaCompiler...args
build.xml
target
+Tests/*
+*.bz2
/kernel
/trace2
+*.ht
+
Bundle-SymbolicName: org.eclipse.linuxtools.lttng.core.tests
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Import-Package: org.eclipse.linuxtools.lttng.jni
Fragment-Host: org.eclipse.linuxtools.lttng.core
Require-Bundle: org.junit;bundle-version="3.8.2",
org.eclipse.core.runtime;bundle-version="3.7.0",
final ITmfTrace<LttngEvent> trace = prepareStreamToTest();
traces[0] = trace;
- // create experiment and associate traces
fTestExperiment = new TmfExperiment<LttngEvent>(LttngEvent.class,
expId, traces, TmfTimestamp.ZERO, TmfExperiment.DEFAULT_BLOCK_SIZE, true);
- // fTestExperiment.indexExperiment(waitForCompletion);
// Set the current selected experiment as the test experiment
final TmfExperimentSelectedSignal<LttngEvent> signal = new TmfExperimentSelectedSignal<LttngEvent>(
try {
testStream = null;
final LTTngTextTrace tmpStream = initializeEventStream();
- tmpEventContent = (LttngEventContent)tmpStream.readNextEvent( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent();
+ tmpEventContent = (LttngEventContent)tmpStream.getNext( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent();
}
catch (final Exception e) {
fail("ERROR : Failed to get content!");
// Require an event
tmpStream = initializeEventStream();
tmpContext = new TmfContext(new TmfLocation<Long>(0L), 0);
- tmpEvent = (LttngEvent)tmpStream.readNextEvent(tmpContext);
+ tmpEvent = (LttngEvent)tmpStream.getNext(tmpContext);
testContent = prepareToTest();
// getFieldS()
assertNotSame("getFields() returned null!", null, testContent.getFields() );
// Skip first events and seek to event pass metadata
tmpContext= tmpStream.seekEvent(new LttngTimestamp(timestampAfterMetadata) );
// Skip first one
- tmpEvent = (LttngEvent)tmpStream.readNextEvent(tmpContext);
+ tmpEvent = (LttngEvent)tmpStream.getNext(tmpContext);
// Second event past metadata should have more fields
- tmpEvent = (LttngEvent)tmpStream.readNextEvent(tmpContext);
+ tmpEvent = (LttngEvent)tmpStream.getNext(tmpContext);
// Get the content
testContent = tmpEvent.getContent();
// Require an event
tmpStream = initializeEventStream();
tmpContext = new TmfContext(new TmfLocation<Long>(0L), 0);
- tmpEvent = (LttngEvent)tmpStream.readNextEvent(tmpContext);
+ tmpEvent = (LttngEvent)tmpStream.getNext(tmpContext);
final LttngEventContent tmpContent = prepareToTest();
try {
// Require an event
tmpStream = initializeEventStream();
tmpContext = new TmfContext(new TmfLocation<Long>(0L), 0);
- tmpEvent = (LttngEvent)tmpStream.readNextEvent(tmpContext);
+ tmpEvent = (LttngEvent)tmpStream.getNext(tmpContext);
// Get the content
testContent = tmpEvent.getContent();
// Get all the fields to make sure there is something in the HashMap
// This trace should be valid
try {
final LTTngTextTrace tmpStream = initializeEventStream();
- tmpField = (LttngEventField)tmpStream.readNextEvent( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0);
+ tmpField = (LttngEventField)tmpStream.getNext( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0);
}
catch (final Exception e) {
fail("ERROR : Failed to get field!");
LttngEventField testField = null;
// try {
- testField = (LttngEventField) tmpStream.readNextEvent( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0);
+ testField = (LttngEventField) tmpStream.getNext( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0);
// } catch (TmfNoSuchFieldException e) {
// e.printStackTrace();
// }
try {
final LTTngTextTrace tmpStream = initializeEventStream();
- tmpEvent = (LttngEvent)tmpStream.readNextEvent(new TmfContext(new TmfLocation<Long>(0L), 0) );
+ tmpEvent = (LttngEvent)tmpStream.getNext(new TmfContext(new TmfLocation<Long>(0L), 0) );
}
catch (final Exception e) {
System.out.println("ERROR : Could not open " + tracepath1);
// This trace should be valid
try {
final LTTngTextTrace tmpStream = initializeEventStream();
- tmpEventType = (LttngEventType)tmpStream.readNextEvent( new TmfContext(null, 0) ).getType();
+ tmpEventType = (LttngEventType)tmpStream.getNext( new TmfContext(null, 0) ).getType();
}
catch (final Exception e) {
fail("ERROR : Failed to get reference!");
// This trace should be valid
try {
final LTTngTextTrace tmpStream = initializeEventStream();
- tmpTime = (LttngTimestamp) tmpStream.readNextEvent(new TmfContext(null, 0)).getTimestamp();
+ tmpTime = (LttngTimestamp) tmpStream.getNext(new TmfContext(null, 0)).getTimestamp();
} catch (final Exception e) {
fail("ERROR : Failed to get reference!");
}
// Seek to the beginning of the trace
tmpContext = tmptrace.seekEvent( tmpTime );
- tmpevent = (LttngEvent)tmptrace.readNextEvent(tmpContext);
+ tmpevent = (LttngEvent)tmptrace.getNext(tmpContext);
while ( tmpevent != null ) {
- tmpevent = (LttngEvent)tmptrace.readNextEvent(tmpContext);
+ tmpevent = (LttngEvent)tmptrace.getNext(tmpContext);
// Parse the events if it was asked
if ( (tmpevent != null) && (PARSE_EVENTS) )
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
+import org.eclipse.linuxtools.internal.lttng.core.event.LttngTimestamp;
import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTrace;
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfLegacyExperiment;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.osgi.framework.FrameworkUtil;
private static int NB_EVENTS = 15316;
// Note: Start/end times are for the LTTng *trace*, not the actual events
- private static final TmfTimestamp fStartTime = new TmfTimestamp(13589759412128L, (byte) -9);
- private static final TmfTimestamp fEndTime = new TmfTimestamp(13589907059242L, (byte) -9);
+ private static final TmfTimestamp fStartTime = new LttngTimestamp(13589759412128L);
+ private static final TmfTimestamp fEndTime = new LttngTimestamp(13589906758692L);
- private static ITmfTrace<LttngEvent>[] fTraces;
- private static TmfExperiment<LttngEvent> fExperiment;
+ private static ITmfTrace<LttngEvent>[] fTestTraces;
+ private static TmfLegacyExperiment<LttngEvent> fExperiment;
// ------------------------------------------------------------------------
// Housekeeping
@SuppressWarnings("unchecked")
private synchronized static ITmfTrace<LttngEvent>[] setupTrace(final String path) {
- if (fTraces == null) {
- fTraces = new ITmfTrace[1];
+ if (fTestTraces == null) {
+ fTestTraces = new ITmfTrace[1];
try {
final URL location = FileLocator.find(FrameworkUtil.getBundle(LTTngExperimentTest.class), new Path(path), null);
final File testfile = new File(FileLocator.toFileURL(location).toURI());
- final LTTngTrace trace = new LTTngTrace(null, testfile.getPath(), false);
- fTraces[0] = trace;
+ final LTTngTrace trace = new LTTngTrace(null, testfile.getPath(), true);
+ fTestTraces[0] = trace;
} catch (final URISyntaxException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
}
}
- return fTraces;
+ return fTestTraces;
}
private synchronized static void setupExperiment() {
- if (fExperiment == null)
- fExperiment = new TmfExperiment<LttngEvent>(LttngEvent.class, EXPERIMENT, fTraces, TmfTimestamp.ZERO, 1000, true);
+ if (fExperiment == null) {
+ fExperiment = new TmfLegacyExperiment<LttngEvent>(LttngEvent.class, EXPERIMENT, fTestTraces, TmfTimestamp.ZERO, 1000, true);
+ }
}
public LTTngExperimentTest(final String name) throws Exception {
public void testBasicTmfExperimentConstructor() {
assertEquals("GetId", EXPERIMENT, fExperiment.getName());
- assertEquals("GetEpoch", TmfTimestamp.ZERO, fExperiment.getEpoch());
assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents();
assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents);
final TmfTimeRange timeRange = fExperiment.getTimeRange();
- assertTrue("getStartTime", fStartTime.equals(timeRange.getStartTime()));
- assertTrue("getEndTime", fEndTime.equals(timeRange.getEndTime()));
+ assertEquals("getStartTime", fStartTime, timeRange.getStartTime());
+ assertEquals("getEndTime", fEndTime, timeRange.getEndTime());
}
}
\ No newline at end of file
final TmfContext tmpContext = new TmfContext(null, 0);
// We should be at the beginning of the trace, so we will just read the
// first event now
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpEvent is null after first getNextEvent()", null, tmpEvent);
assertEquals("tmpEvent has wrong timestamp after first getNextEvent()", firstEventTimestamp, tmpEvent.getTimestamp().getValue());
// Read the next event as well
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpEvent is null after second getNextEvent()", null, tmpEvent);
assertEquals("tmpEvent has wrong timestamp after second getNextEvent()", secondEventTimestamp, tmpEvent.getTimestamp().getValue());
}
// We should be at the beginning of the trace, we will seek at a certain
// timestamp
tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekTest1, (byte) -9, 0));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext);
assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekTest1, tmpEvent.getTimestamp().getValue());
assertNotSame("tmpEvent is null after first seekEvent()", null, tmpEvent);
// Seek to the last timestamp
tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after seekEvent() to last", null, tmpContext);
assertEquals("tmpContext has wrong timestamp after seekEvent() to last", contextValueAfterSeekLast, tmpEvent.getTimestamp().getValue());
assertNotSame("tmpEvent is null after seekEvent() to last ", null, tmpEvent);
// Seek to the first timestamp (startTime)
tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpEvent is null after seekEvent() to start ", null, tmpEvent);
assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains(tmpEvent.getReference()));
assertNotSame("tmpContext is null after seekEvent() to first", null, tmpContext);
// We should be at the beginning of the trace, we will seek at a certain
// timestamp
tmpContext = testStream1.seekEvent(indexToSeekTest1);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext);
assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekTest1, tmpEvent.getTimestamp().getValue());
assertNotSame("tmpEvent is null after first seekEvent()", null, tmpEvent);
// Seek to the last timestamp
tmpContext = testStream1.seekEvent(indexToSeekLast);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext);
assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekLast, tmpEvent.getTimestamp().getValue());
assertNotSame("tmpEvent is null after seekEvent() to last ", null, tmpEvent);
// Seek to the first timestamp (startTime)
tmpContext = testStream1.seekEvent(indexToSeekFirst);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext);
assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterFirstEvent, tmpEvent.getTimestamp().getValue());
assertNotSame("tmpEvent is null after seekEvent() to start ", null, tmpEvent);
// We should be at the beginning of the trace, we will seek at a certain
// timestamp
tmpContext = testStream1.seekEvent(new TmfLocation<Long>(locationToSeekTest1));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekLocation()", null, tmpContext);
assertEquals("tmpContext has wrong timestamp after first seekLocation()", contextValueAfterSeekTest1, tmpEvent.getTimestamp().getValue());
assertNotSame("tmpEvent is null after first seekLocation()", null, tmpEvent);
// Seek to the last timestamp
tmpContext = testStream1.seekEvent(new TmfLocation<Long>(locationToSeekLast));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekLocation()", null, tmpContext);
assertEquals("tmpContext has wrong timestamp after first seekLocation()", contextValueAfterSeekLast, tmpEvent.getTimestamp().getValue());
assertNotSame("tmpEvent is null after seekLocation() to last ", null, tmpEvent);
// Seek to the first timestamp (startTime)
tmpContext = testStream1.seekEvent(new TmfLocation<Long>(locationToSeekFirst));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekLocation()", null, tmpContext);
assertEquals("tmpContext has wrong timestamp after first seekLocation()", contextValueAfterFirstEvent, tmpEvent.getTimestamp().getValue());
assertNotSame("tmpEvent is null after seekLocation() to start ", null, tmpEvent);
import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTrace;
import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.osgi.framework.FrameworkUtil;
final TmfContext tmpContext = new TmfContext(null, 0);
// We should be at the beginning of the trace, so we will just read the first event now
- tmpEvent = testStream1.readNextEvent(tmpContext );
+ tmpEvent = testStream1.getNext(tmpContext );
assertNotSame("tmpEvent is null after first getNextEvent()",null,tmpEvent );
assertEquals("tmpEvent has wrong timestamp after first getNextEvent()",firstEventTimestamp,tmpEvent.getTimestamp().getValue() );
// Read the next event as well
- tmpEvent = testStream1.readNextEvent( tmpContext);
+ tmpEvent = testStream1.getNext( tmpContext);
assertNotSame("tmpEvent is null after second getNextEvent()",null,tmpEvent );
assertEquals("tmpEvent has wrong timestamp after second getNextEvent()",secondEventTimestamp,tmpEvent.getTimestamp().getValue() );
}
public void testSeekEventTimestamp() {
TmfEvent tmpEvent = null;
- TmfContext tmpContext = new TmfContext(null, 0);
+ ITmfContext tmpContext = new TmfContext(null, 0);
final LTTngTrace testStream1 = prepareStreamToTest();
// We should be at the beginning of the trace, we will seek at a certain timestamp
tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekTest1, (byte) -9, 0));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
// Seek to the last timestamp
tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext );
assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
// Seek to the first timestamp (startTime)
tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent );
assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains(tmpEvent.getReference()));
assertNotSame("tmpContext is null after seekEvent() to first",null,tmpContext );
public void testSeekEventIndex() {
TmfEvent tmpEvent = null;
- TmfContext tmpContext = new TmfContext(null, 0);
+ ITmfContext tmpContext = new TmfContext(null, 0);
final LTTngTrace testStream1 = prepareStreamToTest();
// We should be at the beginning of the trace, we will seek at a certain timestamp
tmpContext = testStream1.seekEvent(indexToSeekTest1);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
// Seek to the last timestamp
tmpContext = testStream1.seekEvent(indexToSeekLast);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
// Seek to the first timestamp (startTime)
tmpContext = testStream1.seekEvent(indexToSeekFirst);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent );
public void testSeekLocation() {
TmfEvent tmpEvent = null;
- TmfContext tmpContext = new TmfContext(null, 0);
+ ITmfContext tmpContext = new TmfContext(null, 0);
final LTTngTrace testStream1 = prepareStreamToTest();
// We should be at the beginning of the trace, we will seek at a certain timestamp
tmpContext = testStream1.seekEvent(new LttngLocation(locationToSeekTest1));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent );
// Seek to the last timestamp
tmpContext = testStream1.seekEvent(new LttngLocation(locationToSeekLast));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent );
// Seek to the first timestamp (startTime)
tmpContext = testStream1.seekEvent(new LttngLocation(locationToSeekFirst));
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent );
public void testLocationOperations() {
TmfEvent tmpEvent = null;
- TmfContext tmpContext = new TmfContext(null, 0);
+ ITmfContext tmpContext = new TmfContext(null, 0);
final LTTngTrace testStream1 = prepareStreamToTest();
// Test LttngLocation after a seek
assertTrue("location has wrong flag", location.isLastOperationSeek());
assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
assertTrue("location has wrong flag", location.isLastOperationParse());
assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
// Test LttngLocation after a getNext
tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
location = (LttngLocation) tmpContext.getLocation().clone();
assertTrue("location has wrong flag", location.isLastOperationReadNext());
assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
assertTrue("location has wrong flag", location.isLastOperationParse());
assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
// Test LttngLocation after a getNext and getNext
tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
location = (LttngLocation) tmpContext.getLocation().clone();
assertTrue("location has wrong flag", location.isLastOperationReadNext());
assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
// Test LttngLocation after a getNext and parse
tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
tmpEvent = testStream.parseEvent(tmpContext);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
assertTrue("location has wrong flag", location.isLastOperationParse());
assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
tmpEvent = testStream.parseEvent(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
location = (LttngLocation) tmpContext.getLocation().clone();
assertTrue("location has wrong flag", location.isLastOperationReadNext());
assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
tmpEvent = testStream.parseEvent(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
tmpEvent = testStream.parseEvent(tmpContext);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
assertTrue("location has wrong flag", location.isLastOperationParse());
assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
tmpEvent = testStream.parseEvent(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
location = (LttngLocation) tmpContext.getLocation().clone();
assertTrue("location has wrong flag", location.isLastOperationReadNext());
assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
// Test LttngLocation after a getNext, parse and parse
tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
tmpEvent = testStream.parseEvent(tmpContext);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
assertTrue("location has wrong flag", location.isLastOperationParse());
assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
// Test LttngLocation after a getNext, parse and getNext
tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
tmpEvent = testStream.parseEvent(tmpContext);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
location = (LttngLocation) tmpContext.getLocation().clone();
assertTrue("location has wrong flag", location.isLastOperationReadNext());
assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
// Test LttngLocation after a getNext, getNext and parse
tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
- tmpEvent = testStream.readNextEvent(tmpContext);
+ tmpEvent = testStream.getNext(tmpContext);
assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
tmpEvent = testStream.parseEvent(tmpContext);
assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
assertTrue("location has wrong flag", location.isLastOperationParse());
assertEquals("location has wrong operation time", nextnextEventTimestamp, location.getOperationTimeValue());
tmpContext = testStream1.seekEvent(location);
- tmpEvent = testStream1.readNextEvent(tmpContext);
+ tmpEvent = testStream1.getNext(tmpContext);
assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
}
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEventType;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngSyntheticEvent;
-import org.eclipse.linuxtools.internal.lttng.core.event.LttngTimestamp;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngSyntheticEvent.SequenceInd;
+import org.eclipse.linuxtools.internal.lttng.core.event.LttngTimestamp;
import org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNode;
import org.eclipse.linuxtools.internal.lttng.core.request.LttngBaseEventRequest;
import org.eclipse.linuxtools.internal.lttng.core.state.evProcessor.ITransEventProcessor;
@Override
public LttngLocation clone() {
-
- LttngLocation newLocation = null;
-
- try {
- newLocation = (LttngLocation)super.clone();
-
- // *** IMPORTANT ***
- // Basic type in java are immutable!
- // Thus, using assignation ("=") on basic type is VALID.
- newLocation.isLastOperationParse = this.isLastOperationParse;
- newLocation.isLastOperationReadNext = this.isLastOperationReadNext;
- newLocation.isLastOperationSeek = this.isLastOperationSeek;
-
- // For other type, we need to create a new timestamp
- newLocation.operationTime = new LttngTimestamp( this.operationTime );
- }
- catch (final CloneNotSupportedException e) {
- System.out.println("Cloning failed with : " + e.getMessage()); //$NON-NLS-1$
- }
-
+ LttngLocation newLocation = new LttngLocation(this);
+ newLocation.operationTime = new LttngTimestamp( this.operationTime );
return newLocation;
}
if ( positionToFirstEvent() == false )
throw new IOException("Fail to position to the beginning of the trace"); //$NON-NLS-1$
else {
-// fCacheSize = 1000;
-
- // Skip indexing if asked
- // if ( skipIndexing == true ) {
-// fCheckpoints.add(new TmfCheckpoint(new LttngTimestamp(0L), new TmfLocation<Long>(0L)));
+ setCacheSize(1000);
ITmfContext context = new TmfContext(new TmfLocation<Long>(0L), 0);
- fIndexer.updateIndex(context, new LttngTimestamp(0L));
- fParser = (ITmfEventParser<LttngEvent>) this;
- // }
- // else {
- // indexTrace(true);
- // }
+ getIndexer().updateIndex(context, new LttngTimestamp(0L));
+ setParser((ITmfEventParser<LttngEvent>) this);
final Long endTime = currentLttngEvent.getTimestamp().getValue();
positionToFirstEvent();
- readNextEvent(new TmfContext(null, 0));
+ getNext(new TmfContext(null, 0));
final Long starTime = currentLttngEvent.getTimestamp().getValue();
positionToFirstEvent();
initialize(resource, path, eventType);
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected synchronized void initialize(final IResource resource, final String path, final Class<LttngEvent> eventType)
throws TmfTraceException {
// Set the currentEvent to the eventContent
eventContent.setEvent(currentLttngEvent);
- fParser = (ITmfEventParser<LttngEvent>) this;
- fCacheSize = CHECKPOINT_PAGE_SIZE;
+ setParser((ITmfEventParser<LttngEvent>) this);
+ setCacheSize(CHECKPOINT_PAGE_SIZE);
// // Bypass indexing if asked
// if ( bypassIndexing == false ) {
if (jniTrace == null
|| (!jniTrace.isLiveTraceSupported() || !LiveTraceManager.isLiveTrace(jniTrace.getTracepath()))) {
// Set the time range of the trace
- final TmfContext context = seekEvent(0);
- final LttngEvent event = readNextEvent(context);
+ final ITmfContext context = seekEvent(0);
+ final LttngEvent event = getNext(context);
final LttngTimestamp startTime = new LttngTimestamp(event.getTimestamp());
final LttngTimestamp endTime = new LttngTimestamp(currentJniTrace.getEndTime().getTime());
setTimeRange(new TmfTimeRange(startTime, endTime));
}
// Set the time range of the trace
- final TmfContext context = seekEvent(0);
- final LttngEvent event = readNextEvent(context);
+ final ITmfContext context = seekEvent(0);
+ final LttngEvent event = getNext(context);
setEndTime(TmfTimestamp.BIG_BANG);
final long startTime = event != null ? event.getTimestamp().getValue() : TmfTimestamp.BIG_BANG.getValue();
- fStreamingInterval = LTTNG_STREAMING_INTERVAL;
+ setStreamingInterval(LTTNG_STREAMING_INTERVAL);
final Thread thread = new Thread("Streaming Monitor for trace " + getName()) { //$NON-NLS-1$
* @see org.eclipse.linuxtools.tmf.core.trace.TmfContext
*/
@Override
- public synchronized TmfContext seekEvent(final ITmfLocation<?> location) {
-
- // // [lmcfrch]
- // lastTime = 0;
+ public synchronized ITmfContext seekEvent(final ITmfLocation<?> location) {
if (PRINT_DEBUG)
System.out.println("seekLocation(location) location -> " + location); //$NON-NLS-1$
// If the location in context is null, create a new one
- LttngLocation curLocation = null;
if (location == null) {
- curLocation = new LttngLocation();
- final TmfContext context = seekEvent(curLocation.getOperationTime());
+ LttngLocation curLocation = new LttngLocation();
+ final ITmfContext context = seekEvent(curLocation.getOperationTime());
context.setRank(0);
return context;
- } else
- curLocation = (LttngLocation) location;
-
- // *** NOTE :
- // Update to location should (and will) be done in SeekEvent.
-
+ }
+
// The only seek valid in LTTng is with the time, we call
// seekEvent(timestamp)
- final TmfContext context = seekEvent(curLocation.getOperationTime());
+ LttngLocation curLocation = (LttngLocation) location;
+ final ITmfContext context = seekEvent(curLocation.getOperationTime());
// If the location is marked with the read next flag
// then it is pointing to the next event following the operation time
if (curLocation.isLastOperationReadNext())
- readNextEvent(context);
+ getNext(context);
return context;
}
// timestamp = getStartTime();
// Position the trace at the checkpoint
- final ITmfContext checkpointContext = fIndexer.seekIndex(rank);
+ final ITmfContext checkpointContext = getIndexer().seekIndex(rank);
LttngLocation location = (LttngLocation) checkpointContext.getLocation();
ITmfTimestamp timestamp = location.getLocation();
long index = rank / getCacheSize();
// Seek to the found time
final TmfContext tmpContext = seekEvent(timestamp);
- tmpContext.setRank((index + 1) * fCacheSize);
+ tmpContext.setRank((index + 1) * getCacheSize());
previousLocation = (LttngLocation) tmpContext.getLocation();
// Ajust the index of the event we found at this check point position
public int nbEventsRead = 0;
@Override
- public synchronized LttngEvent readNextEvent(final ITmfContext context) {
+ public synchronized LttngEvent getNext(final ITmfContext context) {
if (PRINT_DEBUG)
System.out.println("getNextEvent(context) context.getLocation() -> " //$NON-NLS-1$
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
* @throws FileNotFoundException
*/
public LTTngTraceStub(final IResource resource) throws TmfTraceException {
- this(resource, DEFAULT_TRACE_CACHE_SIZE);
+ this(resource, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE);
}
/**
}
public void indexTrace() {
- fIndexer.buildIndex(true);
+ getIndexer().buildIndex(true);
}
// ========================================================================
CtfTmfTrace fixture = initTrace();
ITmfContext context = fixture.seekEvent(0);
- CtfTmfEvent result = fixture.readNextEvent(context);
+ CtfTmfEvent result = fixture.getNext(context);
// add additional test code here
// An unexpected exception was thrown in user code while executing this test:
import org.eclipse.linuxtools.internal.tmf.core.TmfCorePlugin;
/**
- * <b><u>AllTests</u></b>
- * <p>
+ * Test suite for org.eclipse.linuxtools.tmf.core.event
*/
@SuppressWarnings("nls")
public class AllTests {
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
/**
- * <b><u>TmfEventFieldTest</u></b>
- * <p>
* Test suite for the TmfEventField class.
*/
@SuppressWarnings("nls")
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
/**
- * <b><u>TmfEventTest</u></b>
- * <p>
* Test suite for the TmfEvent class.
*/
@SuppressWarnings("nls")
import org.eclipse.linuxtools.tmf.core.event.TmfEventTypeManager;
/**
- * <b><u>TmfEventTypeManagerTest</u></b>
- * <p>
* Test suite for the TmfEventTypeManager class.
- * <p>
*/
@SuppressWarnings("nls")
public class TmfEventTypeManagerTest extends TestCase {
import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
/**
- * <b><u>TmfEventTypeTest</u></b>
- * <p>
* Test suite for the TmfEventType class.
*/
@SuppressWarnings("nls")
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
/**
- * <b><u>TmfSimpleTimestampTest</u></b>
- * <p>
* Test suite for the TmfSimpleTimestampTest class.
*/
@SuppressWarnings("nls")
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
/**
- * <b><u>TmfTimeRangeTest</u></b>
- * <p>
* Test suite for the TmfTimeRange class.
*/
@SuppressWarnings("nls")
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
/**
- * <b><u>TmfTimestampTest</u></b>
- * <p>
* Test suite for the TmfTimestamp class.
*/
@SuppressWarnings("nls")
+/*******************************************************************************
+ * Copyright (c) 2009, 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:
+ * Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Adjusted for new Trace Model
+ *******************************************************************************/
+
package org.eclipse.linuxtools.tmf.core.tests.experiment;
import junit.framework.Test;
import org.eclipse.linuxtools.internal.tmf.core.TmfCorePlugin;
+/**
+ * Test suite for org.eclipse.linuxtools.tmf.core.experiment
+ */
@SuppressWarnings("nls")
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test suite for " + TmfCorePlugin.PLUGIN_ID + ".experiment"); //$NON-NLS-1$);
//$JUnit-BEGIN$
- suite.addTestSuite(TmfExperimentTest.class);
+ suite.addTestSuite(TmfExperimentCheckpointIndexTest.class);
+ suite.addTestSuite(TmfExperimentTest.class);
suite.addTestSuite(TmfMultiTraceExperimentTest.class);
//$JUnit-END$
return suite;
--- /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:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.experiment;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfExperimentContext;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfExperimentLocation;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfLocationArray;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
+import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+
+/**
+ * Test suite for the TmfCheckpointIndexTest class.
+ */
+@SuppressWarnings("nls")
+public class TmfExperimentCheckpointIndexTest extends TestCase {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private static final String DIRECTORY = "testfiles";
+ private static final String TEST_STREAM1 = "O-Test-10K";
+ private static final String TEST_STREAM2 = "E-Test-10K";
+ private static final String EXPERIMENT = "MyExperiment";
+ private static int NB_EVENTS = 20000;
+ private static int BLOCK_SIZE = 1000;
+
+ private static ITmfTrace<?>[] fTestTraces;
+ private static TestExperiment fExperiment;
+
+ // ------------------------------------------------------------------------
+ // Helper classes
+ // ------------------------------------------------------------------------
+
+ private class TestIndexer extends TmfCheckpointIndexer<ITmfTrace<ITmfEvent>> {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public TestIndexer(TestExperiment testExperiment) {
+ super((ITmfTrace) testExperiment, BLOCK_SIZE);
+ }
+ public List<TmfCheckpoint> getCheckpoints() {
+ return getTraceIndex();
+ }
+ }
+
+ private class TestExperiment extends TmfExperiment<ITmfEvent> {
+ @SuppressWarnings("unchecked")
+ public TestExperiment() {
+ super(ITmfEvent.class, EXPERIMENT, (ITmfTrace<ITmfEvent>[]) fTestTraces, TmfTimestamp.ZERO, BLOCK_SIZE, false);
+ setIndexer(new TestIndexer(this));
+ getIndexer().buildIndex(true);
+ }
+ @Override
+ public TestIndexer getIndexer() {
+ return (TestIndexer) super.getIndexer();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Housekeeping
+ // ------------------------------------------------------------------------
+
+ public TmfExperimentCheckpointIndexTest(final String name) throws Exception {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2);
+ if (fExperiment == null) {
+ fExperiment = new TestExperiment();
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ fExperiment.dispose();
+ fExperiment = null;
+ }
+
+ private static ITmfTrace<?>[] setupTrace(final String path1, final String path2) {
+ if (fTestTraces == null) {
+ fTestTraces = new ITmfTrace[2];
+ try {
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null);
+ File test = new File(FileLocator.toFileURL(location).toURI());
+ final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true);
+ fTestTraces[0] = trace1;
+ location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null);
+ test = new File(FileLocator.toFileURL(location).toURI());
+ final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true);
+ fTestTraces[1] = trace2;
+ } catch (final TmfTraceException e) {
+ e.printStackTrace();
+ } catch (final URISyntaxException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return fTestTraces;
+ }
+
+ // ------------------------------------------------------------------------
+ // Verify checkpoints
+ // ------------------------------------------------------------------------
+
+ public void testTmfTraceIndexing() throws Exception {
+ assertEquals("getCacheSize", BLOCK_SIZE, fExperiment.getCacheSize());
+ assertEquals("getTraceSize", NB_EVENTS, fExperiment.getNbEvents());
+ assertEquals("getRange-start", 1, fExperiment.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, fExperiment.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, fExperiment.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, fExperiment.getEndTime().getValue());
+
+ List<TmfCheckpoint> checkpoints = fExperiment.getIndexer().getCheckpoints();
+ int pageSize = fExperiment.getCacheSize();
+ assertTrue("Checkpoints exist", checkpoints != null);
+ assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
+
+ // Validate that each checkpoint points to the right event
+ for (int i = 0; i < checkpoints.size(); i++) {
+ TmfCheckpoint checkpoint = checkpoints.get(i);
+ TmfExperimentLocation expLocation = (TmfExperimentLocation) checkpoint.getLocation();
+ TmfLocationArray locations = expLocation.getLocation();
+ ITmfContext[] trcContexts = new ITmfContext[2];
+ trcContexts[0] = new TmfContext(locations.getLocations()[0], (i * pageSize) / 2);
+ trcContexts[1] = new TmfContext(locations.getLocations()[1], (i * pageSize) / 2);
+ TmfExperimentContext expContext = new TmfExperimentContext(trcContexts);
+ expContext.getEvents()[0] = fTestTraces[0].getNext(fTestTraces[0].seekEvent((i * pageSize) / 2));
+ expContext.getEvents()[1] = fTestTraces[1].getNext(fTestTraces[1].seekEvent((i * pageSize) / 2));
+ ITmfEvent event = fExperiment.parseEvent(expContext);
+ assertTrue(expContext.getRank() == i * pageSize);
+ assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+ }
+ }
+
+}
\ No newline at end of file
/*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009, 2010, 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
*
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Adjusted for new Trace Model
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.tests.experiment;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
-import org.eclipse.linuxtools.tmf.core.experiment.TmfExperimentContext;
import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
/**
- * <b><u>TmfExperimentTest</u></b>
- * <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfExperiment class (single trace).
*/
@SuppressWarnings("nls")
public class TmfExperimentTest extends TestCase {
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
private static final String DIRECTORY = "testfiles";
private static final String TEST_STREAM = "A-Test-10K";
private static final String EXPERIMENT = "MyExperiment";
private static int NB_EVENTS = 10000;
- private static int fDefaultBlockSize = 1000;
+ private static int BLOCK_SIZE = 1000;
private static ITmfTrace<?>[] fTraces;
private static TmfExperiment<TmfEvent> fExperiment;
public void testBasicTmfExperimentConstructor() {
assertEquals("GetId", EXPERIMENT, fExperiment.getName());
- assertEquals("GetEpoch", TmfTimestamp.ZERO, fExperiment.getEpoch());
assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
+ final long nbExperimentEvents = fExperiment.getNbEvents();
+ assertEquals("GetNbEvents", NB_EVENTS, nbExperimentEvents);
+
final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents();
assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents);
}
// ------------------------------------------------------------------------
- // Verify checkpoints
+ // seekEvent on rank
// ------------------------------------------------------------------------
- public void testValidateCheckpoints() throws Exception {
-
- final Vector<TmfCheckpoint> checkpoints = fExperiment.getCheckpoints();
- final int pageSize = fExperiment.getCacheSize();
- assertTrue("Checkpoints exist", checkpoints != null);
-
- // Validate that each checkpoint points to the right event
- for (int i = 0; i < checkpoints.size(); i++) {
- final TmfCheckpoint checkpoint = checkpoints.get(i);
- final TmfExperimentContext context = fExperiment.seekEvent(checkpoint.getLocation());
- final ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event rank", i * pageSize, context.getRank());
- assertTrue("Timestamp", (checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
- }
- }
-
- // ------------------------------------------------------------------------
- // seekLocation
- // ------------------------------------------------------------------------
+ public void testSeekRankOnCacheBoundary() throws Exception {
- public void testSeekLocationOnCacheBoundary() throws Exception {
+ long cacheSize = fExperiment.getCacheSize();
- // Position trace at event rank 0
- TmfContext context = fExperiment.seekEvent(0);
- assertEquals("Event rank", 0, context.getRank());
+ // On lower bound, returns the first event (TS = 1)
+ ITmfContext context = fExperiment.seekEvent(0);
+ assertEquals("Context rank", 0, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
+ assertEquals("Context rank", 1, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
-
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- assertEquals("Event rank", 2, context.getRank());
+ // Position trace at event rank [cacheSize]
+ context = fExperiment.seekEvent(cacheSize);
+ assertEquals("Context rank", cacheSize, context.getRank());
- // Position trace at event rank 1000
- TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 1000, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue());
+ assertEquals("Context rank", cacheSize + 1, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
-
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
+ // Position trace at event rank [4 * cacheSize]
+ context = fExperiment.seekEvent(4 * cacheSize);
+ assertEquals("Context rank", 4 * cacheSize, context.getRank());
- // Position trace at event rank 4000
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 4000, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4000, context.getRank());
-
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4001, context.getRank());
-
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4002, event.getTimestamp().getValue());
- assertEquals("Event rank", 4002, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue());
+ assertEquals("Context rank", 4 * cacheSize + 1, context.getRank());
}
- public void testSeekLocationNotOnCacheBoundary() throws Exception {
+ public void testSeekRankNotOnCacheBoundary() throws Exception {
- // Position trace at event rank 9
- TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0));
- TmfContext context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 9, context.getRank());
+ long cacheSize = fExperiment.getCacheSize();
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 9, context.getRank());
+ // Position trace at event rank 9
+ ITmfContext context = fExperiment.seekEvent(9);
+ assertEquals("Context rank", 9, context.getRank());
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 10, context.getRank());
-
- // Position trace at event rank 999
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 999, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 999, context.getRank());
+ assertEquals("Context rank", 10, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ // Position trace at event rank [cacheSize - 1]
+ context = fExperiment.seekEvent(cacheSize - 1);
+ assertEquals("Context rank", cacheSize - 1, context.getRank());
- // Position trace at event rank 1001
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 1001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue());
+ assertEquals("Context rank", cacheSize, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ // Position trace at event rank [cacheSize + 1]
+ context = fExperiment.seekEvent(cacheSize + 1);
+ assertEquals("Context rank", cacheSize + 1, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue());
+ assertEquals("Context rank", cacheSize + 2, context.getRank());
// Position trace at event rank 4500
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 4500, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4500, context.getRank());
+ context = fExperiment.seekEvent(4500);
+ assertEquals("Context rank", 4500, context.getRank());
- event = fExperiment.readNextEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4501, context.getRank());
+ assertEquals("Context rank", 4501, context.getRank());
}
- public void testSeekLocationOutOfScope() throws Exception {
+ public void testSeekRankOutOfScope() throws Exception {
// Position trace at beginning
- TmfContext tmpContext = fExperiment.seekEvent(0);
- final TmfContext context = fExperiment.seekEvent(tmpContext.getLocation());
+ ITmfContext context = fExperiment.seekEvent(-1);
assertEquals("Event rank", 0, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
-
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
+ assertEquals("Context rank", 1, context.getRank());
// Position trace at event passed the end
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
- assertEquals("Event location", null, tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, tmpContext.getRank());
+ context = fExperiment.seekEvent(NB_EVENTS);
+ assertEquals("Context rank", NB_EVENTS, context.getRank());
+
+ event = fExperiment.getNext(context);
+ assertNull("Event", event);
+ assertEquals("Context rank", NB_EVENTS, context.getRank());
}
// ------------------------------------------------------------------------
// seekEvent on timestamp
// ------------------------------------------------------------------------
- public void testSeekEventOnTimestampOnCacheBoundary() throws Exception {
+ public void testSeekTimestampOnCacheBoundary() throws Exception {
- // Position trace at event rank 0
- TmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0));
- assertEquals("Event rank", 0, context.getRank());
+ long cacheSize = fExperiment.getCacheSize();
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
+ // Position trace at event rank 0
+ ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0));
+ assertEquals("Context rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event rank 1000
- context = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0));
- assertEquals("Event rank", 1000, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ assertEquals("Context rank", 1, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ // Position trace at event rank [cacheSize]
+ context = fExperiment.seekEvent(new TmfTimestamp(cacheSize + 1, SCALE, 0));
+ assertEquals("Event rank", cacheSize, context.getRank());
- // Position trace at event rank 4000
- context = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0));
- assertEquals("Event rank", 4000, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue());
+ assertEquals("Context rank", cacheSize + 1, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4000, context.getRank());
+ // Position trace at event rank [4 * cacheSize]
+ context = fExperiment.seekEvent(new TmfTimestamp(4 * cacheSize + 1, SCALE, 0));
+ assertEquals("Context rank", 4 * cacheSize, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue());
+ assertEquals("Context rank", 4 * cacheSize + 1, context.getRank());
}
- public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception {
+ public void testSeekTimestampNotOnCacheBoundary() throws Exception {
- // Position trace at event rank 1
- TmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0));
- assertEquals("Event rank", 1, context.getRank());
-
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
+ // Position trace at event rank 1 (TS = 2)
+ ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0));
+ assertEquals("Context rank", 1, context.getRank());
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- assertEquals("Event rank", 2, context.getRank());
+ assertEquals("Context rank", 2, context.getRank());
- // Position trace at event rank 9
+ // Position trace at event rank 9 (TS = 10)
context = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0));
- assertEquals("Event rank", 9, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 9, context.getRank());
+ assertEquals("Context rank", 9, context.getRank());
- event = fExperiment.readNextEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 10, context.getRank());
+ assertEquals("Context rank", 10, context.getRank());
- // Position trace at event rank 999
+ // Position trace at event rank 999 (TS = 1000)
context = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0));
- assertEquals("Event rank", 999, context.getRank());
+ assertEquals("Context rank", 999, context.getRank());
- event = fExperiment.parseEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 999, context.getRank());
+ assertEquals("Context rank", 1000, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
-
- // Position trace at event rank 1001
+ // Position trace at event rank 1001 (TS = 1002)
context = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0));
- assertEquals("Event rank", 1001, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ assertEquals("Context rank", 1001, context.getRank());
- event = fExperiment.readNextEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
+ assertEquals("Context rank", 1002, context.getRank());
- // Position trace at event rank 4500
+ // Position trace at event rank 4500 (TS = 4501)
context = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0));
- assertEquals("Event rank", 4500, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4500, context.getRank());
+ assertEquals("Context rank", 4500, context.getRank());
- event = fExperiment.readNextEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4501, context.getRank());
+ assertEquals("Context rank", 4501, context.getRank());
}
- public void testSeekEventOnTimestampoutOfScope() throws Exception {
+ public void testSeekTimestampOutOfScope() throws Exception {
// Position trace at beginning
- TmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0));
- assertEquals("Event rank", 0, context.getRank());
-
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0));
assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 1, context.getRank());
// Position trace at event passed the end
context = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
- assertEquals("Event location", null, context.getLocation());
+ event = fExperiment.getNext(context);
+ assertNull("Event location", event);
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
}
// ------------------------------------------------------------------------
- // seekEvent on rank
+ // seekEvent by location (context rank is undefined)
// ------------------------------------------------------------------------
- public void testSeekOnRankOnCacheBoundary() throws Exception {
+ public void testSeekLocationOnCacheBoundary() throws Exception {
+
+ long cacheSize = fExperiment.getCacheSize();
- // On lower bound, returns the first event (ts = 1)
- TmfContext context = fExperiment.seekEvent(0);
- assertEquals("Event rank", 0, context.getRank());
+ // Position trace at event rank 0
+ ITmfContext tmpContext = fExperiment.seekEvent(0);
+ ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation());
- ITmfEvent event = fExperiment.parseEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- // Position trace at event rank 1000
- context = fExperiment.seekEvent(1000);
- assertEquals("Event rank", 1000, context.getRank());
+ // Position trace at event rank 'cacheSize'
+ tmpContext = fExperiment.seekEvent(cacheSize);
+ context = fExperiment.seekEvent(tmpContext.getLocation());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue());
- // Position trace at event rank 4000
- context = fExperiment.seekEvent(4000);
- assertEquals("Event rank", 4000, context.getRank());
+ // Position trace at event rank 4 * 'cacheSize'
+ tmpContext = fExperiment.seekEvent(4 * cacheSize);
+ context = fExperiment.seekEvent(tmpContext.getLocation());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4000, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue());
}
- public void testSeekOnRankNotOnCacheBoundary() throws Exception {
-
- // Position trace at event rank 9
- TmfContext context = fExperiment.seekEvent(9);
- assertEquals("Event rank", 9, context.getRank());
-
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 9, context.getRank());
+ public void testSeekLocationNotOnCacheBoundary() throws Exception {
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 10, context.getRank());
+ long cacheSize = fExperiment.getCacheSize();
- // Position trace at event rank 999
- context = fExperiment.seekEvent(999);
- assertEquals("Event rank", 999, context.getRank());
+ // Position trace at event 'cacheSize' - 1
+ ITmfContext tmpContext = fExperiment.seekEvent(cacheSize - 1);
+ ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 999, context.getRank());
+ ITmfEvent event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue());
- // Position trace at event rank 1001
- context = fExperiment.seekEvent(1001);
- assertEquals("Event rank", 1001, context.getRank());
+ // Position trace at event rank 2 * 'cacheSize' - 1
+ tmpContext = fExperiment.seekEvent(2 * cacheSize - 1);
+ context = fExperiment.seekEvent(tmpContext.getLocation());
+ context = fExperiment.seekEvent(2 * cacheSize - 1);
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 2 * cacheSize, event.getTimestamp().getValue());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 2 * cacheSize + 1, event.getTimestamp().getValue());
// Position trace at event rank 4500
- context = fExperiment.seekEvent(4500);
- assertEquals("Event rank", 4500, context.getRank());
+ tmpContext = fExperiment.seekEvent(4500);
+ context = fExperiment.seekEvent(tmpContext.getLocation());
- event = fExperiment.parseEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4500, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4501, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4502, event.getTimestamp().getValue());
}
- public void testSeekEventOnRankOutOfScope() throws Exception {
+ public void testSeekLocationOutOfScope() throws Exception {
// Position trace at beginning
- TmfContext context = fExperiment.seekEvent(-1);
- assertEquals("Event rank", 0, context.getRank());
-
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
+ ITmfContext context = fExperiment.seekEvent((ITmfLocation<?>) null);
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event passed the end
- context = fExperiment.seekEvent(NB_EVENTS);
- assertEquals("Event location", null, context.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
}
// ------------------------------------------------------------------------
- // parseEvent - make sure parseEvent doesn't update the context
- // Note: This test is essentially the same as the one from TmfTraceTest
+ // readtNextEvent - updates the context
// ------------------------------------------------------------------------
- public void testParseEvent() throws Exception {
-
- final int NB_READS = 20;
-
- // On lower bound, returns the first event (ts = 1)
- final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0));
-
- // Read NB_EVENTS
- ITmfEvent event = null;;
- for (int i = 0; i < NB_READS; i++) {
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue());
- assertEquals("Event rank", i + 1, context.getRank());
- }
-
- // Make sure we stay positioned
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue());
- assertEquals("Event rank", NB_READS, context.getRank());
- }
-
- // ------------------------------------------------------------------------
- // getNextEvent - updates the context
- // ------------------------------------------------------------------------
-
- public void testGetNextEvent() throws Exception {
+ public void testReadNextEvent() throws Exception {
// On lower bound, returns the first event (ts = 0)
- final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0));
- ITmfEvent event = fExperiment.readNextEvent(context);
+ final ITmfContext context = fExperiment.seekEvent(0);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
for (int i = 2; i < 20; i++) {
- event = fExperiment.readNextEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", i, event.getTimestamp().getValue());
}
}
public void testCancel() throws Exception {
final int nbEvents = NB_EVENTS;
- final int blockSize = fDefaultBlockSize;
+ final int blockSize = BLOCK_SIZE;
final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
assertTrue("isCancelled", request.isCancelled());
}
- // ------------------------------------------------------------------------
- // getRank
- // ------------------------------------------------------------------------
-
- // public void testGetRank() throws Exception {
- //
- // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp()));
- // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp( 1, (byte) -3)));
- // assertEquals("getRank", 10, fExperiment.getRank(new TmfTimestamp( 11, (byte) -3)));
- // assertEquals("getRank", 100, fExperiment.getRank(new TmfTimestamp( 101, (byte) -3)));
- // assertEquals("getRank", 1000, fExperiment.getRank(new TmfTimestamp(1001, (byte) -3)));
- // assertEquals("getRank", 2000, fExperiment.getRank(new TmfTimestamp(2001, (byte) -3)));
- // assertEquals("getRank", 2500, fExperiment.getRank(new TmfTimestamp(2501, (byte) -3)));
- // }
-
// ------------------------------------------------------------------------
// getTimestamp
// ------------------------------------------------------------------------
/*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009, 2010, 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
*
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Adjusted for new Trace Model
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.tests.experiment;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
-import org.eclipse.linuxtools.tmf.core.experiment.TmfExperimentContext;
import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
/**
- * <b><u>TmfExperimentTest</u></b>
- * <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfExperiment class (multiple traces).
*/
@SuppressWarnings("nls")
public class TmfMultiTraceExperimentTest extends TestCase {
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
private static final String DIRECTORY = "testfiles";
private static final String TEST_STREAM1 = "O-Test-10K";
private static final String TEST_STREAM2 = "E-Test-10K";
return fTraces;
}
- @SuppressWarnings("unchecked")
- private synchronized static void setupExperiment() {
- synchronized (TmfMultiTraceExperimentTest.class) {
- if (fExperiment == null) {
- fExperiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, (ITmfTrace<TmfEvent>[]) fTraces, TmfTimestamp.ZERO, BLOCK_SIZE, true);
- }
- }
- }
-
public TmfMultiTraceExperimentTest(final String name) throws Exception {
super(name);
}
+ @SuppressWarnings("unchecked")
@Override
protected void setUp() throws Exception {
super.setUp();
setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2);
- setupExperiment();
+ if (fExperiment == null) {
+ fExperiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, (ITmfTrace<TmfEvent>[]) fTraces, TmfTimestamp.ZERO, BLOCK_SIZE, true);
+ }
}
@Override
public void testBasicTmfExperimentConstructor() {
assertEquals("GetId", EXPERIMENT, fExperiment.getName());
- assertEquals("GetEpoch", TmfTimestamp.ZERO, fExperiment.getEpoch());
assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
final TmfTimeRange timeRange = fExperiment.getTimeRange();
}
// ------------------------------------------------------------------------
- // Verify checkpoints
- // ------------------------------------------------------------------------
-
- public void testValidateCheckpoints() throws Exception {
-
- final Vector<TmfCheckpoint> checkpoints = fExperiment.getCheckpoints();
- final int pageSize = fExperiment.getCacheSize();
- assertTrue("Checkpoints exist", checkpoints != null);
-
- // Validate that each checkpoint points to the right event
- for (int i = 0; i < checkpoints.size(); i++) {
- final TmfCheckpoint checkpoint = checkpoints.get(i);
- final TmfExperimentContext context = fExperiment.seekEvent(checkpoint.getLocation());
- final ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event rank", context.getRank(), i * pageSize);
- assertTrue("Timestamp", (checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
- }
- }
-
- // ------------------------------------------------------------------------
- // seekLocation
+ // seekEvent on rank
// ------------------------------------------------------------------------
- public void testSeekLocationOnCacheBoundary() throws Exception {
+ public void testSeekRankOnCacheBoundary() throws Exception {
- // Position trace at event rank 0
- TmfContext context = fExperiment.seekEvent(0);
- assertEquals("Event rank", 0, context.getRank());
+ long cacheSize = fExperiment.getCacheSize();
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
+ // On lower bound, returns the first event (TS = 1)
+ ITmfContext context = fExperiment.seekEvent(0);
+ assertEquals("Context rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
+ assertEquals("Context rank", 1, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- assertEquals("Event rank", 2, context.getRank());
-
- // Position trace at event rank 1000
- TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 1000, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ // Position trace at event rank [cacheSize]
+ context = fExperiment.seekEvent(cacheSize);
+ assertEquals("Context rank", cacheSize, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
-
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
-
- // Position trace at event rank 4000
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 4000, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue());
+ assertEquals("Context rank", cacheSize + 1, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4000, context.getRank());
+ // Position trace at event rank [4 * cacheSize]
+ context = fExperiment.seekEvent(4 * cacheSize);
+ assertEquals("Context rank", 4 * cacheSize, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4001, context.getRank());
-
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4002, event.getTimestamp().getValue());
- assertEquals("Event rank", 4002, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue());
+ assertEquals("Context rank", 4 * cacheSize + 1, context.getRank());
}
- public void testSeekLocationNotOnCacheBoundary() throws Exception {
+ public void testSeekRankNotOnCacheBoundary() throws Exception {
- // Position trace at event rank 9
- TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0));
- TmfContext context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 9, context.getRank());
+ long cacheSize = fExperiment.getCacheSize();
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 9, context.getRank());
+ // Position trace at event rank 9
+ ITmfContext context = fExperiment.seekEvent(9);
+ assertEquals("Context rank", 9, context.getRank());
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 10, context.getRank());
-
- // Position trace at event rank 999
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 999, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 999, context.getRank());
+ assertEquals("Context rank", 10, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ // Position trace at event rank [cacheSize - 1]
+ context = fExperiment.seekEvent(cacheSize - 1);
+ assertEquals("Context rank", cacheSize - 1, context.getRank());
- // Position trace at event rank 1001
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 1001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue());
+ assertEquals("Context rank", cacheSize, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ // Position trace at event rank [cacheSize + 1]
+ context = fExperiment.seekEvent(cacheSize + 1);
+ assertEquals("Context rank", cacheSize + 1, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue());
+ assertEquals("Context rank", cacheSize + 2, context.getRank());
// Position trace at event rank 4500
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 4500, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4500, context.getRank());
+ context = fExperiment.seekEvent(4500);
+ assertEquals("Context rank", 4500, context.getRank());
- event = fExperiment.readNextEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4501, context.getRank());
+ assertEquals("Context rank", 4501, context.getRank());
}
- public void testSeekLocationOutOfScope() throws Exception {
+ public void testSeekRankOutOfScope() throws Exception {
// Position trace at beginning
- TmfContext tmpContext = fExperiment.seekEvent(0);
- final TmfContext context = fExperiment.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", 0, context.getRank());
-
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ ITmfContext context = fExperiment.seekEvent(-1);
assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
+ assertEquals("Context rank", 1, context.getRank());
// Position trace at event passed the end
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
- assertEquals("Event location", null, tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, tmpContext.getRank());
+ context = fExperiment.seekEvent(NB_EVENTS);
+ assertEquals("Context rank", NB_EVENTS, context.getRank());
+
+ event = fExperiment.getNext(context);
+ assertNull("Event", event);
+ assertEquals("Context rank", NB_EVENTS, context.getRank());
}
// ------------------------------------------------------------------------
// seekEvent on timestamp
// ------------------------------------------------------------------------
- public void testSeekEventOnTimestampOnCacheBoundary() throws Exception {
+ public void testSeekTimestampOnCacheBoundary() throws Exception {
- // Position trace at event rank 0
- TmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0));
- assertEquals("Event rank", 0, context.getRank());
+ long cacheSize = fExperiment.getCacheSize();
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
+ // Position trace at event rank 0
+ ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0));
+ assertEquals("Context rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event rank 1000
- context = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0));
- assertEquals("Event rank", 1000, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ assertEquals("Context rank", 1, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ // Position trace at event rank [cacheSize]
+ context = fExperiment.seekEvent(new TmfTimestamp(cacheSize + 1, SCALE, 0));
+ assertEquals("Event rank", cacheSize, context.getRank());
- // Position trace at event rank 4000
- context = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0));
- assertEquals("Event rank", 4000, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue());
+ assertEquals("Context rank", cacheSize + 1, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4000, context.getRank());
+ // Position trace at event rank [4 * cacheSize]
+ context = fExperiment.seekEvent(new TmfTimestamp(4 * cacheSize + 1, SCALE, 0));
+ assertEquals("Context rank", 4 * cacheSize, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue());
+ assertEquals("Context rank", 4 * cacheSize + 1, context.getRank());
}
- public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception {
+ public void testSeekTimestampNotOnCacheBoundary() throws Exception {
- // Position trace at event rank 1
- TmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0));
- assertEquals("Event rank", 1, context.getRank());
+ // Position trace at event rank 1 (TS = 2)
+ ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0));
+ assertEquals("Context rank", 1, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
+ assertEquals("Context rank", 2, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- assertEquals("Event rank", 2, context.getRank());
-
- // Position trace at event rank 9
+ // Position trace at event rank 9 (TS = 10)
context = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0));
- assertEquals("Event rank", 9, context.getRank());
+ assertEquals("Context rank", 9, context.getRank());
- event = fExperiment.parseEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 9, context.getRank());
+ assertEquals("Context rank", 10, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 10, context.getRank());
-
- // Position trace at event rank 999
+ // Position trace at event rank 999 (TS = 1000)
context = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0));
- assertEquals("Event rank", 999, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 999, context.getRank());
+ assertEquals("Context rank", 999, context.getRank());
- event = fExperiment.readNextEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ assertEquals("Context rank", 1000, context.getRank());
- // Position trace at event rank 1001
+ // Position trace at event rank 1001 (TS = 1002)
context = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0));
- assertEquals("Event rank", 1001, context.getRank());
+ assertEquals("Context rank", 1001, context.getRank());
- event = fExperiment.parseEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ assertEquals("Context rank", 1002, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
-
- // Position trace at event rank 4500
+ // Position trace at event rank 4500 (TS = 4501)
context = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0));
- assertEquals("Event rank", 4500, context.getRank());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4500, context.getRank());
+ assertEquals("Context rank", 4500, context.getRank());
- event = fExperiment.readNextEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4501, context.getRank());
+ assertEquals("Context rank", 4501, context.getRank());
}
- public void testSeekEventOnTimestampOutOfScope() throws Exception {
+ public void testSeekTimestampOutOfScope() throws Exception {
// Position trace at beginning
- TmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0));
- assertEquals("Event rank", 0, context.getRank());
-
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0));
assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 1, context.getRank());
// Position trace at event passed the end
context = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
- assertEquals("Event location", null, context.getLocation());
+ event = fExperiment.getNext(context);
+ assertNull("Event location", event);
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
}
// ------------------------------------------------------------------------
- // seekEvent on rank
+ // seekEvent by location (context rank is undefined)
// ------------------------------------------------------------------------
- public void testSeekOnRankOnCacheBoundary() throws Exception {
+ public void testSeekLocationOnCacheBoundary() throws Exception {
+
+ long cacheSize = fExperiment.getCacheSize();
- // On lower bound, returns the first event (ts = 1)
- TmfContext context = fExperiment.seekEvent(0);
- assertEquals("Event rank", 0, context.getRank());
+ // Position trace at event rank 0
+ ITmfContext tmpContext = fExperiment.seekEvent(0);
+ ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation());
- ITmfEvent event = fExperiment.parseEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- // Position trace at event rank 1000
- context = fExperiment.seekEvent(1000);
- assertEquals("Event rank", 1000, context.getRank());
+ // Position trace at event rank 'cacheSize'
+ tmpContext = fExperiment.seekEvent(cacheSize);
+ context = fExperiment.seekEvent(tmpContext.getLocation());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue());
- // Position trace at event rank 4000
- context = fExperiment.seekEvent(4000);
- assertEquals("Event rank", 4000, context.getRank());
+ // Position trace at event rank 4 * 'cacheSize'
+ tmpContext = fExperiment.seekEvent(4 * cacheSize);
+ context = fExperiment.seekEvent(tmpContext.getLocation());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4000, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue());
}
- public void testSeekOnRankNotOnCacheBoundary() throws Exception {
-
- // Position trace at event rank 9
- TmfContext context = fExperiment.seekEvent(9);
- assertEquals("Event rank", 9, context.getRank());
+ public void testSeekLocationNotOnCacheBoundary() throws Exception {
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 9, context.getRank());
+ long cacheSize = fExperiment.getCacheSize();
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 10, context.getRank());
+ // Position trace at event 'cacheSize' - 1
+ ITmfContext tmpContext = fExperiment.seekEvent(cacheSize - 1);
+ ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation());
- // Position trace at event rank 999
- context = fExperiment.seekEvent(999);
- assertEquals("Event rank", 999, context.getRank());
+ ITmfEvent event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 999, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
-
- // Position trace at event rank 1001
- context = fExperiment.seekEvent(1001);
- assertEquals("Event rank", 1001, context.getRank());
+ // Position trace at event rank 2 * 'cacheSize' - 1
+ tmpContext = fExperiment.seekEvent(2 * cacheSize - 1);
+ context = fExperiment.seekEvent(tmpContext.getLocation());
+ context = fExperiment.seekEvent(2 * cacheSize - 1);
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 2 * cacheSize, event.getTimestamp().getValue());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 2 * cacheSize + 1, event.getTimestamp().getValue());
// Position trace at event rank 4500
- context = fExperiment.seekEvent(4500);
- assertEquals("Event rank", 4500, context.getRank());
+ tmpContext = fExperiment.seekEvent(4500);
+ context = fExperiment.seekEvent(tmpContext.getLocation());
- event = fExperiment.parseEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4500, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4501, context.getRank());
+ event = fExperiment.getNext(context);
+ assertEquals("Event timestamp", 4502, event.getTimestamp().getValue());
}
- public void testSeekEventOnRankOutOfScope() throws Exception {
+ public void testSeekLocationOutOfScope() throws Exception {
// Position trace at beginning
- TmfContext context = fExperiment.seekEvent(-1);
- assertEquals("Event rank", 0, context.getRank());
-
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
+ ITmfContext context = fExperiment.seekEvent((ITmfLocation<?>) null);
- event = fExperiment.readNextEvent(context);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event passed the end
- context = fExperiment.seekEvent(NB_EVENTS);
- assertEquals("Event location", null, context.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- }
-
- // ------------------------------------------------------------------------
- // parseEvent - make sure parseEvent doesn't update the context
- // Note: This test is essentially the same as the one from TmfTraceTest
- // ------------------------------------------------------------------------
-
- public void testParseEvent() throws Exception {
-
- final int NB_READS = 20;
-
- // On lower bound, returns the first event (ts = 1)
- final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0));
-
- // Read NB_EVENTS
- ITmfEvent event = null;;
- for (int i = 0; i < NB_READS; i++) {
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue());
- assertEquals("Event rank", i + 1, context.getRank());
- }
-
- // Make sure we stay positioned
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue());
- assertEquals("Event rank", NB_READS, context.getRank());
}
// ------------------------------------------------------------------------
- // getNextEvent - updates the context
+ // readtNextEvent - updates the context
// ------------------------------------------------------------------------
- public void testGetNextEvent() throws Exception {
+ public void testReadNextEvent() throws Exception {
// On lower bound, returns the first event (ts = 0)
- final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0));
- ITmfEvent event = fExperiment.readNextEvent(context);
+ final ITmfContext context = fExperiment.seekEvent(0);
+ ITmfEvent event = fExperiment.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
for (int i = 2; i < 20; i++) {
- event = fExperiment.readNextEvent(context);
+ event = fExperiment.getNext(context);
assertEquals("Event timestamp", i, event.getTimestamp().getValue());
}
}
assertTrue("isCancelled", request.isCancelled());
}
- // ------------------------------------------------------------------------
- // getRank
- // ------------------------------------------------------------------------
-
- // public void testGetRank() throws Exception {
- //
- // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp()));
- // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp( 1, (byte) -3)));
- // assertEquals("getRank", 10, fExperiment.getRank(new TmfTimestamp( 11, (byte) -3)));
- // assertEquals("getRank", 100, fExperiment.getRank(new TmfTimestamp( 101, (byte) -3)));
- // assertEquals("getRank", 1000, fExperiment.getRank(new TmfTimestamp(1001, (byte) -3)));
- // assertEquals("getRank", 2000, fExperiment.getRank(new TmfTimestamp(2001, (byte) -3)));
- // assertEquals("getRank", 2500, fExperiment.getRank(new TmfTimestamp(2501, (byte) -3)));
- // }
-
// ------------------------------------------------------------------------
// getTimestamp
// ------------------------------------------------------------------------
import org.eclipse.linuxtools.internal.tmf.core.TmfCorePlugin;
/**
- * <b><u>AllTests</u></b>
- * <p>
+ * Test suite for org.eclipse.linuxtools.tmf.core.trace
*/
@SuppressWarnings("nls")
public class AllTests {
/*******************************************************************************
- * Copyright (c) 2009, 2010, 20112 Ericsson
+ * Copyright (c) 2009, 2010, 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
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.Vector;
+import java.util.List;
import junit.framework.TestCase;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
/**
- * <b><u>TmfTraceTest</u></b>
- * <p>
- * Test suite for the TmfTrace class.
+ * Test suite for the TmfCheckpointIndexTest class.
*/
@SuppressWarnings("nls")
public class TmfCheckpointIndexTest extends TestCase {
private static final String DIRECTORY = "testfiles";
private static final String TEST_STREAM = "A-Test-10K";
- private static final int BLOCK_SIZE = 500;
+ private static final int BLOCK_SIZE = 100;
private static final int NB_EVENTS = 10000;
private static TestTrace fTrace = null;
private class TestIndexer extends TmfCheckpointIndexer<ITmfTrace<ITmfEvent>> {
@SuppressWarnings({ "unchecked", "rawtypes" })
public TestIndexer(TestTrace testTrace) {
- super((ITmfTrace) testTrace);
+ super((ITmfTrace) testTrace, BLOCK_SIZE);
}
- public Vector<TmfCheckpoint> getCheckpoints() {
- return fTraceIndex;
+ public List<TmfCheckpoint> getCheckpoints() {
+ return getTraceIndex();
}
}
private class TestTrace extends TmfTraceStub {
public TestTrace(String path, int blockSize) throws TmfTraceException {
super(path, blockSize);
- fIndexer = new TestIndexer(this);
+ setIndexer(new TestIndexer(this));
}
+ @Override
public TestIndexer getIndexer() {
- return (TestIndexer) fIndexer;
+ return (TestIndexer) super.getIndexer();
}
}
assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue());
- Vector<TmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
+ List<TmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
int pageSize = fTrace.getCacheSize();
assertTrue("Checkpoints exist", checkpoints != null);
+ assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
// Validate that each checkpoint points to the right event
for (int i = 0; i < checkpoints.size(); i++) {
*
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Adapted for TMF Trace Model 1.0
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.tests.trace;
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
/**
- * <b><u>TmfCheckpointTest</u></b>
- * <p>
* Test suite for the TmfCheckpoint class.
*/
@SuppressWarnings("nls")
*
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Adapted for TMF Trace Model 1.0
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.tests.trace;
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
/**
- * <b><u>TmfContextTest</u></b>
- * <p>
* Test suite for the TmfContext class.
*/
@SuppressWarnings("nls")
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2009, 2010 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:
- * Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.trace;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Vector;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
-import org.eclipse.linuxtools.tmf.core.experiment.TmfExperimentContext;
-import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
-import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
-
-/**
- * <b><u>TmfExperimentTest</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-@SuppressWarnings("nls")
-public class TmfExperimentTest extends TestCase {
-
- private static final String DIRECTORY = "testfiles";
- private static final String TEST_STREAM = "A-Test-10K";
- private static final String EXPERIMENT = "MyExperiment";
- private static int NB_EVENTS = 10000;
- private static int fDefaultBlockSize = 1000;
-
- private static ITmfTrace<?>[] fTraces;
- private static TmfExperiment<TmfEvent> fExperiment;
-
- private static byte SCALE = (byte) -3;
-
- // ------------------------------------------------------------------------
- // Housekeeping
- // ------------------------------------------------------------------------
-
- private synchronized ITmfTrace<?>[] setupTrace(final String path) {
- if (fTraces == null) {
- fTraces = new ITmfTrace[1];
- try {
- final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
- final File test = new File(FileLocator.toFileURL(location).toURI());
- final TmfTraceStub trace = new TmfTraceStub(test.getPath(), true);
- fTraces[0] = trace;
- } catch (final TmfTraceException e) {
- e.printStackTrace();
- } catch (final URISyntaxException e) {
- e.printStackTrace();
- } catch (final IOException e) {
- e.printStackTrace();
- }
- }
- return fTraces;
- }
-
- @SuppressWarnings("unchecked")
- private synchronized void setupExperiment() {
- if (fExperiment == null)
- fExperiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, (ITmfTrace<TmfEvent>[]) fTraces);
- // fExperiment.indexExperiment();
- }
-
- public TmfExperimentTest(final String name) throws Exception {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- setupTrace(DIRECTORY + File.separator + TEST_STREAM);
- setupExperiment();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- // ------------------------------------------------------------------------
- // Constructor
- // ------------------------------------------------------------------------
-
- public void testBasicTmfExperimentConstructor() {
- assertEquals("GetId", EXPERIMENT, fExperiment.getName());
- assertEquals("GetEpoch", TmfTimestamp.ZERO, fExperiment.getEpoch());
- assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
-
- final TmfTimeRange timeRange = fExperiment.getTimeRange();
- assertEquals("getStartTime", 1, timeRange.getStartTime().getValue());
- assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue());
- }
-
- // ------------------------------------------------------------------------
- // Verify checkpoints
- // Note: seekLocation() does not reliably set the rank
- // ------------------------------------------------------------------------
-
- public void testValidateCheckpoints() throws Exception {
-
- final Vector<TmfCheckpoint> checkpoints = fExperiment.getCheckpoints();
- // int pageSize = fExperiment.getCacheSize();
- assertTrue("Checkpoints exist", checkpoints != null);
-
- // Validate that each checkpoint points to the right event
- for (int i = 0; i < checkpoints.size(); i++) {
- final TmfCheckpoint checkpoint = checkpoints.get(i);
- final TmfExperimentContext context = fExperiment.seekEvent(checkpoint.getLocation());
- final ITmfEvent event = fExperiment.parseEvent(context);
- // assertEquals("Event rank", context.getRank(), i * pageSize);
- assertTrue("Timestamp", (checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
- }
- }
-
- // ------------------------------------------------------------------------
- // parseEvent - make sure parseEvent doesn't update the context
- // ------------------------------------------------------------------------
-
- public void testParseEvent() throws Exception {
-
- // On lower bound, returns the first event (ts = 0)
- final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0));
-
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
-
- for (int i = 1; i < 20; i++) {
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", i, event.getTimestamp().getValue());
- }
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 20, event.getTimestamp().getValue());
-
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 20, event.getTimestamp().getValue());
- }
-
- // ------------------------------------------------------------------------
- // getNextEvent - updates the context
- // ------------------------------------------------------------------------
-
- public void testGetNextEvent() throws Exception {
-
- // On lower bound, returns the first event (ts = 0)
- final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0));
- ITmfEvent event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
-
- for (int i = 2; i < 20; i++) {
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", i, event.getTimestamp().getValue());
- }
- }
-
- // ------------------------------------------------------------------------
- // seekLocation
- // Note: seekLocation() does not reliably set the rank
- // ------------------------------------------------------------------------
-
- public void testSeekLocationOnCacheBoundary() throws Exception {
-
- // Position trace at event rank 0
- TmfContext context = fExperiment.seekEvent(0);
- // assertEquals("Event rank", 0, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- // assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- // assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event rank 1000
- TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation().clone());
- // assertEquals("Event rank", 1000, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- // assertEquals("Event rank", 1000, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- // assertEquals("Event rank", 1001, context.getRank());
-
- // Position trace at event rank 4000
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation().clone());
- // assertEquals("Event rank", 4000, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- // assertEquals("Event rank", 4000, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- // assertEquals("Event rank", 4001, context.getRank());
- }
-
- public void testSeekLocationNotOnCacheBoundary() throws Exception {
-
- // Position trace at event rank 9
- TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0));
- TmfContext context = fExperiment.seekEvent(tmpContext.getLocation().clone());
- // assertEquals("Event rank", 9, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- // assertEquals("Event rank", 9, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- // assertEquals("Event rank", 10, context.getRank());
-
- // Position trace at event rank 999
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation().clone());
- // assertEquals("Event rank", 999, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- // assertEquals("Event rank", 999, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- // assertEquals("Event rank", 1000, context.getRank());
-
- // Position trace at event rank 1001
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation().clone());
- // assertEquals("Event rank", 1001, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- // assertEquals("Event rank", 1001, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- // assertEquals("Event rank", 1002, context.getRank());
-
- // Position trace at event rank 4500
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation().clone());
- // assertEquals("Event rank", 4500, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- // assertEquals("Event rank", 4500, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- // assertEquals("Event rank", 4501, context.getRank());
- }
-
- public void testSeekLocationOutOfScope() throws Exception {
-
- // Position trace at beginning
- TmfContext tmpContext = fExperiment.seekEvent(0);
- TmfContext context = fExperiment.seekEvent(tmpContext.getLocation().clone());
- // assertEquals("Event rank", 0, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- // assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- // assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event passed the end
- tmpContext = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
- context = fExperiment.seekEvent(tmpContext.getLocation().clone());
- // assertEquals("Event rank", NB_EVENTS, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", null, event);
- // assertEquals("Event rank", NB_EVENTS, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", null, event);
- // assertEquals("Event rank", NB_EVENTS, context.getRank());
- }
-
- // ------------------------------------------------------------------------
- // seekEvent on timestamp
- // ------------------------------------------------------------------------
-
- public void testSeekEventOnTimestampOnCacheBoundary() throws Exception {
-
- // Position trace at event rank 0
- TmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0));
- assertEquals("Event rank", 0, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event rank 1000
- context = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0));
- assertEquals("Event rank", 1000, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
-
- // Position trace at event rank 4000
- context = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0));
- assertEquals("Event rank", 4000, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4000, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4001, context.getRank());
- }
-
- public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception {
-
- // Position trace at event rank 1
- TmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0));
- assertEquals("Event rank", 1, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
- assertEquals("Event rank", 2, context.getRank());
-
- // Position trace at event rank 9
- context = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0));
- assertEquals("Event rank", 9, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 9, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 10, context.getRank());
-
- // Position trace at event rank 999
- context = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0));
- assertEquals("Event rank", 999, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 999, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
-
- // Position trace at event rank 1001
- context = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0));
- assertEquals("Event rank", 1001, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
-
- // Position trace at event rank 4500
- context = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0));
- assertEquals("Event rank", 4500, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4500, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4501, context.getRank());
- }
-
- public void testSeekEventOnTimestampoutOfScope() throws Exception {
-
- // Position trace at beginning
- TmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0));
- assertEquals("Event rank", 0, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event passed the end
- context = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
- assertEquals("Event rank", NB_EVENTS, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", null, event);
- assertEquals("Event rank", NB_EVENTS, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", null, event);
- assertEquals("Event rank", NB_EVENTS, context.getRank());
- }
-
- // ------------------------------------------------------------------------
- // seekEvent on rank
- // ------------------------------------------------------------------------
-
- public void testSeekOnRankOnCacheBoundary() throws Exception {
-
- // On lower bound, returns the first event (ts = 1)
- TmfContext context = fExperiment.seekEvent(0);
- assertEquals("Event rank", 0, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event rank 1000
- context = fExperiment.seekEvent(1000);
- assertEquals("Event rank", 1000, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
-
- // Position trace at event rank 4000
- context = fExperiment.seekEvent(4000);
- assertEquals("Event rank", 4000, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4000, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", 4001, context.getRank());
- }
-
- public void testSeekOnRankNotOnCacheBoundary() throws Exception {
-
- // Position trace at event rank 9
- TmfContext context = fExperiment.seekEvent(9);
- assertEquals("Event rank", 9, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 9, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", 10, context.getRank());
-
- // Position trace at event rank 999
- context = fExperiment.seekEvent(999);
- assertEquals("Event rank", 999, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 999, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", 1000, context.getRank());
-
- // Position trace at event rank 1001
- context = fExperiment.seekEvent(1001);
- assertEquals("Event rank", 1001, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1001, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", 1002, context.getRank());
-
- // Position trace at event rank 4500
- context = fExperiment.seekEvent(4500);
- assertEquals("Event rank", 4500, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4500, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", 4501, context.getRank());
- }
-
- public void testSeekEventOnRankOfScope() throws Exception {
-
- // Position trace at beginning
- TmfContext context = fExperiment.seekEvent(-1);
- assertEquals("Event rank", 0, context.getRank());
- ITmfEvent event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 1, context.getRank());
-
- // Position trace at event passed the end
- context = fExperiment.seekEvent(NB_EVENTS);
- assertEquals("Event rank", NB_EVENTS, context.getRank());
- event = fExperiment.parseEvent(context);
- assertEquals("Event timestamp", null, event);
- assertEquals("Event rank", NB_EVENTS, context.getRank());
- event = fExperiment.readNextEvent(context);
- assertEquals("Event timestamp", null, event);
- assertEquals("Event rank", NB_EVENTS, context.getRank());
- }
-
- // ------------------------------------------------------------------------
- // processRequest
- // ------------------------------------------------------------------------
-
- public void testProcessRequestForNbEvents() throws Exception {
- final int blockSize = 100;
- final int nbEvents = 1000;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
-
- final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
- final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) {
- @Override
- public void handleData(final TmfEvent event) {
- super.handleData(event);
- requestedEvents.add(event);
- }
- };
- fExperiment.sendRequest(request);
- request.waitForCompletion();
-
- assertEquals("nbEvents", nbEvents, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < nbEvents; i++)
- assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue());
- }
-
- public void testProcessRequestForNbEvents2() throws Exception {
- final int blockSize = 2 * NB_EVENTS;
- final int nbEvents = 1000;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
-
- final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
- final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) {
- @Override
- public void handleData(final TmfEvent event) {
- super.handleData(event);
- requestedEvents.add(event);
- }
- };
- fExperiment.sendRequest(request);
- request.waitForCompletion();
-
- assertEquals("nbEvents", nbEvents, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < nbEvents; i++)
- assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue());
- }
-
- public void testProcessRequestForAllEvents() throws Exception {
- final int nbEvents = TmfEventRequest.ALL_DATA;
- final int blockSize = 1;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
- final long nbExpectedEvents = fExperiment.getNbEvents();
-
- final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
- final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) {
- @Override
- public void handleData(final TmfEvent event) {
- super.handleData(event);
- requestedEvents.add(event);
- }
- };
- fExperiment.sendRequest(request);
- request.waitForCompletion();
-
- assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertFalse("isCancelled", request.isCancelled());
-
- // Ensure that we have distinct events.
- // Don't go overboard: we are not validating the stub!
- for (int i = 0; i < nbExpectedEvents; i++)
- assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue());
- }
-
- // ------------------------------------------------------------------------
- // cancel
- // ------------------------------------------------------------------------
-
- public void testCancel() throws Exception {
- final int nbEvents = NB_EVENTS;
- final int blockSize = fDefaultBlockSize;
- final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
-
- final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
- final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) {
- int nbRead = 0;
- @Override
- public void handleData(final TmfEvent event) {
- super.handleData(event);
- requestedEvents.add(event);
- if (++nbRead == blockSize)
- cancel();
- }
- };
- fExperiment.sendRequest(request);
- request.waitForCompletion();
-
- assertEquals("nbEvents", blockSize, requestedEvents.size());
- assertTrue("isCompleted", request.isCompleted());
- assertTrue("isCancelled", request.isCancelled());
- }
-
- // ------------------------------------------------------------------------
- // getRank
- // ------------------------------------------------------------------------
-
- // public void testGetRank() throws Exception {
- // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp()));
- // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp( 1, (byte) -3)));
- // assertEquals("getRank", 10, fExperiment.getRank(new TmfTimestamp( 11, (byte) -3)));
- // assertEquals("getRank", 100, fExperiment.getRank(new TmfTimestamp( 101, (byte) -3)));
- // assertEquals("getRank", 1000, fExperiment.getRank(new TmfTimestamp(1001, (byte) -3)));
- // assertEquals("getRank", 2000, fExperiment.getRank(new TmfTimestamp(2001, (byte) -3)));
- // assertEquals("getRank", 2500, fExperiment.getRank(new TmfTimestamp(2501, (byte) -3)));
- // }
-
- // ------------------------------------------------------------------------
- // getTimestamp
- // ------------------------------------------------------------------------
-
- public void testGetTimestamp() throws Exception {
- assertTrue("getTimestamp", fExperiment.getTimestamp( 0).equals(new TmfTimestamp( 1, (byte) -3)));
- assertTrue("getTimestamp", fExperiment.getTimestamp( 10).equals(new TmfTimestamp( 11, (byte) -3)));
- assertTrue("getTimestamp", fExperiment.getTimestamp( 100).equals(new TmfTimestamp( 101, (byte) -3)));
- assertTrue("getTimestamp", fExperiment.getTimestamp(1000).equals(new TmfTimestamp(1001, (byte) -3)));
- assertTrue("getTimestamp", fExperiment.getTimestamp(2000).equals(new TmfTimestamp(2001, (byte) -3)));
- assertTrue("getTimestamp", fExperiment.getTimestamp(2500).equals(new TmfTimestamp(2501, (byte) -3)));
- }
-
-}
\ No newline at end of file
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
/**
- * <b><u>TmfLocationTest</u></b>
- * <p>
* Test suite for the TmfLocation class.
*/
@SuppressWarnings("nls")
/*******************************************************************************
- * Copyright (c) 2009, 2010, 20112 Ericsson
+ * Copyright (c) 2009, 2010, 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
import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
/**
- * <b><u>TmfTraceTest</u></b>
- * <p>
* Test suite for the TmfTrace class.
*/
@SuppressWarnings("nls")
assertEquals("getType", TmfEvent.class, trace.getType());
assertNull ("getResource", trace.getResource());
assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
- assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
assertEquals("getName", TEST_STREAM, trace.getName());
assertEquals("getType", TmfEvent.class, trace.getType());
assertNull ("getResource", trace.getResource());
assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
- assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
assertEquals("getName", TEST_STREAM, trace.getName());
assertEquals("getType", TmfEvent.class, trace.getType());
assertNull ("getResource", trace.getResource());
assertEquals("getPath", path, trace.getPath());
- assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
assertEquals("getName", path, trace.getName());
assertEquals("getType", TmfEvent.class, trace.getType());
assertNull ("getResource", trace.getResource());
assertEquals("getPath", path, trace.getPath());
- assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
assertEquals("getName", name, trace.getName());
assertFalse ("Open trace", trace == null);
assertNull ("getType", trace.getType());
assertNull ("getResource", trace.getResource());
- assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
assertEquals("getName", "", trace.getName());
// InitTrace and wait for indexing completion...
trace.initTrace(null, testfile.getPath(), TmfEvent.class);
+ trace.indexTrace();
int nbSecs = 0;
while (trace.getNbEvents() < NB_EVENTS && nbSecs < 10) {
Thread.sleep(1000);
assertFalse ("Open trace", trace == null);
assertEquals("getType", TmfEvent.class, trace.getType());
assertNull ("getResource", trace.getResource());
- assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
assertEquals("getName", TEST_STREAM, trace.getName());
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
}
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
}
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
// Position trace at event passed the end
- tmpContext = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
- context = fTrace.seekEvent(tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", null, event);
+ context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
+ assertNull("Event timestamp", context.getLocation());
assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
- assertEquals("Event timestamp", null, event);
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+ event = fTrace.getNext(context);
+ assertNull("Event", event);
}
// ------------------------------------------------------------------------
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 0, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 1, context.getRank());
assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
assertEquals("Event rank", 1000, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
assertEquals("Event rank", 1001, context.getRank());
assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
assertEquals("Event rank", 4000, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
assertEquals("Event rank", 4001, context.getRank());
}
assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
assertEquals("Event rank", 1, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 2, event.getTimestamp().getValue());
assertEquals("Event rank", 2, context.getRank());
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
assertEquals("Event rank", 9, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
assertEquals("Event rank", 10, context.getRank());
assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
assertEquals("Event rank", 999, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
assertEquals("Event rank", 1000, context.getRank());
assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
assertEquals("Event rank", 1001, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
assertEquals("Event rank", 1002, context.getRank());
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
assertEquals("Event rank", 4500, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
assertEquals("Event rank", 4501, context.getRank());
}
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 0, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 1, context.getRank());
// Position trace at event passed the end
context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
- assertEquals("Event rank", NB_EVENTS, context.getRank());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
event = fTrace.parseEvent(context);
assertEquals("Event timestamp", null, event);
- assertEquals("Event rank", NB_EVENTS, context.getRank());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", null, event);
- assertEquals("Event rank", NB_EVENTS, context.getRank());
+ assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
}
// ------------------------------------------------------------------------
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 0, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 1, context.getRank());
assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
assertEquals("Event rank", 1000, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
assertEquals("Event rank", 1001, context.getRank());
assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
assertEquals("Event rank", 4000, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
assertEquals("Event rank", 4001, context.getRank());
}
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
assertEquals("Event rank", 9, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
assertEquals("Event rank", 10, context.getRank());
assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
assertEquals("Event rank", 999, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
assertEquals("Event rank", 1000, context.getRank());
assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
assertEquals("Event rank", 1001, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
assertEquals("Event rank", 1002, context.getRank());
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
assertEquals("Event rank", 4500, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
assertEquals("Event rank", 4501, context.getRank());
}
- public void testSeekEventOnRankOfScope() throws Exception {
+ public void testSeekEventOnRankOutOfScope() throws Exception {
// Position trace at beginning
ITmfContext context = fTrace.seekEvent(-1);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 0, context.getRank());
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
assertEquals("Event rank", 1, context.getRank());
assertEquals("Event rank", NB_EVENTS, context.getRank());
event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", null, event);
+ assertNull("Event", event);
assertEquals("Event rank", NB_EVENTS, context.getRank());
- event = fTrace.readNextEvent(context);
- assertEquals("Event timestamp", null, event);
+ event = fTrace.getNext(context);
+ assertNull("Event", event);
assertEquals("Event rank", NB_EVENTS, context.getRank());
}
// Position the trace at event NB_READS
for (int i = 1; i < NB_READS; i++) {
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", i, event.getTimestamp().getValue());
}
// Read NB_EVENTS
ITmfEvent event;
for (int i = 0; i < NB_READS; i++) {
- event = fTrace.readNextEvent(context);
+ event = fTrace.getNext(context);
assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue());
assertEquals("Event rank", i + 1, context.getRank());
}
// no need to use synchronized since it's already cover by the calling method
long location = 0;
- if (context != null)
+ if (context != null && context.getLocation() != null) {
location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
-
- try {
- stream.seek(location);
-
- final long ts = stream.readLong();
- final String source = stream.readUTF();
- final String type = stream.readUTF();
- final Integer reference = stream.readInt();
- final int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
- final String[] fields = new String[typeIndex];
- for (int i = 0; i < typeIndex; i++)
- fields[i] = stream.readUTF();
-
- final StringBuffer content = new StringBuffer("[");
- if (typeIndex > 0)
- content.append(fields[0]);
- for (int i = 1; i < typeIndex; i++)
- content.append(", ").append(fields[i]);
- content.append("]");
-
- final TmfEventField root = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content.toString());
- final TmfEvent event = new TmfEvent(fEventStream,
- new TmfTimestamp(ts, -3, 0), // millisecs
- source, fTypes[typeIndex], root, reference.toString());
- return event;
- } catch (final EOFException e) {
- } catch (final IOException e) {
+ try {
+ stream.seek(location);
+
+ final long ts = stream.readLong();
+ final String source = stream.readUTF();
+ final String type = stream.readUTF();
+ final Integer reference = stream.readInt();
+ final int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
+ final String[] fields = new String[typeIndex];
+ for (int i = 0; i < typeIndex; i++)
+ fields[i] = stream.readUTF();
+
+ final StringBuffer content = new StringBuffer("[");
+ if (typeIndex > 0)
+ content.append(fields[0]);
+ for (int i = 1; i < typeIndex; i++)
+ content.append(", ").append(fields[i]);
+ content.append("]");
+
+ final TmfEventField root = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content.toString());
+ final TmfEvent event = new TmfEvent(fEventStream,
+ new TmfTimestamp(ts, -3, 0), // millisecs
+ source, fTypes[typeIndex], root, reference.toString());
+ return event;
+ } catch (final EOFException e) {
+ } catch (final IOException e) {
+ }
}
return null;
}
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceIndexer;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
*/
public TmfTraceStub() {
super();
- fParser = new TmfEventParserStub(this);
+ setParser(new TmfEventParserStub(this));
}
/**
* @throws FileNotFoundException
*/
public TmfTraceStub(final String path) throws TmfTraceException {
- this(path, DEFAULT_TRACE_CACHE_SIZE, false);
+ this(path, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false);
}
/**
} catch (FileNotFoundException e) {
throw new TmfTraceException(e.getMessage());
}
- fParser = new TmfEventParserStub(this);
+ setParser(new TmfEventParserStub(this));
}
/**
* @throws FileNotFoundException
*/
public TmfTraceStub(final String path, final boolean waitForCompletion) throws TmfTraceException {
- this(path, DEFAULT_TRACE_CACHE_SIZE, waitForCompletion);
+ this(path, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, waitForCompletion);
}
/**
} catch (FileNotFoundException e) {
throw new TmfTraceException(e.getMessage());
}
- fParser = new TmfEventParserStub(this);
+ setParser(new TmfEventParserStub(this));
+ if (waitForCompletion) {
+ indexTrace();
+ }
}
/**
} catch (FileNotFoundException e) {
throw new TmfTraceException(e.getMessage());
}
- fParser = new TmfEventParserStub(this);
+ setParser(new TmfEventParserStub(this));
}
/**
} catch (FileNotFoundException e) {
throw new TmfTraceException(e.getMessage());
}
- fParser = (parser != null) ? parser : new TmfEventParserStub(this);
+ setParser((parser != null) ? parser : new TmfEventParserStub(this));
}
/**
} catch (FileNotFoundException e) {
throw new TmfTraceException(e.getMessage());
}
- fParser = new TmfEventParserStub(this);
+ setParser(new TmfEventParserStub(this));
}
public void indexTrace() {
- fIndexer.buildIndex(true);
+ indexTrace(true);
}
@Override
} catch (FileNotFoundException e) {
throw new TmfTraceException(e.getMessage());
}
- fParser = new TmfEventParserStub(this);
+ setParser(new TmfEventParserStub(this));
super.initTrace(resource, path, type);
}
fLock.lock();
try {
// parseNextEvent will update the context
- if (fTrace != null) {
- final TmfEvent event = fParser.parseEvent(context.clone());
+ if (fTrace != null && getParser() != null && context != null) {
+ final TmfEvent event = getParser().parseEvent(context.clone());
return event;
}
-// }
-// catch (final IOException e) {
-// e.printStackTrace();
} finally {
fLock.unlock();
}
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
/**
* <b><u>ITmfDataRequest</u></b>
public void sendRequest(ITmfDataRequest<T> request);
public void fireRequest();
public void notifyPendingRequest(boolean isIncrement);
+
+ /**
+ * Return the next event based on the context supplied. The context
+ * will be updated for the subsequent read.
+ *
+ * @param context the trace read context (updated)
+ * @return the event referred to by context
+ */
+ public T getNext(ITmfContext context);
}
*/
public abstract ITmfContext armRequest(ITmfDataRequest<T> request);
- /**
- * Return the next event based on the context supplied. The context
- * will be updated for the subsequent read.
- *
- * @param context the trace read context (updated)
- * @return the event referred to by context
- */
- public abstract T getNext(ITmfContext context);
+// /**
+// * Return the next event based on the context supplied. The context
+// * will be updated for the subsequent read.
+// *
+// * @param context the trace read context (updated)
+// * @return the event referred to by context
+// */
+// public abstract T getNext(ITmfContext context);
/**
* Checks if the data meets the request completion criteria.
return seekEvent(request.getIndex());
}
- /**
- * The trace reader keeps its own iterator: the "context" parameter here
- * will be ignored.
- *
- * If you wish to specify a new context, instantiate a new CtfIterator and
- * seek() it to where you want, and use that to read events.
- *
- * FIXME merge with getNextEvent below once they both use the same parameter
- * type.
- * @param context ITmfContext
- * @return CtfTmfEvent
- */
- @Override
- public CtfTmfEvent getNext(final ITmfContext context) {
- return readNextEvent(context);
- }
+// /**
+// * The trace reader keeps its own iterator: the "context" parameter here
+// * will be ignored.
+// *
+// * If you wish to specify a new context, instantiate a new CtfIterator and
+// * seek() it to where you want, and use that to read events.
+// *
+// * FIXME merge with getNextEvent below once they both use the same parameter
+// * type.
+// * @param context ITmfContext
+// * @return CtfTmfEvent
+// */
+// @Override
+// public CtfTmfEvent getNext(final ITmfContext context) {
+// return readNextEvent(context);
+// }
// ------------------------------------------------------------------------
// ITmfTrace
* Method readNextEvent.
* @param context ITmfContext
* @return CtfTmfEvent
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(ITmfContext)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNext(ITmfContext)
*/
@Override
- public CtfTmfEvent readNextEvent(final ITmfContext context) {
+ public CtfTmfEvent getNext(final ITmfContext context) {
CtfTmfEvent event = null;
if (context instanceof CtfIterator) {
CtfIterator ctfIterator = (CtfIterator) context;
* used as e.g. a location marker (filename:lineno) to indicate where the event
* was generated.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* @see ITmfEventField
* @see TmfEvent
*/
-public interface ITmfEvent extends Cloneable {
+public interface ITmfEvent {
// ------------------------------------------------------------------------
// Constants
*/
public String getReference();
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
/**
* @return a clone of the event
*/
* The generic event payload in TMF. Each field can be either a terminal or
* further decomposed into subfields.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* @see ITmfEvent
* @see ITmfEventType
*/
-public interface ITmfEventField extends Cloneable {
+public interface ITmfEventField {
// ------------------------------------------------------------------------
// Constants
*/
public ITmfEventField getField(int index);
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
/**
* @return a clone of the event field
*/
* <p>
* Types are unique within their context space.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* @see ITmfEvent
* @see ITmfEventField
*/
-public interface ITmfEventType extends Cloneable {
+public interface ITmfEventType {
// ------------------------------------------------------------------------
// Constants
*/
public String getFieldName(int index);
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
/**
* @return a clone of the event type
*/
* timestamps in different scales). Default: 0.
* </ul>
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* @see ITmfEvent
* @see TmfTimeRange
*/
-public interface ITmfTimestamp extends Cloneable, Comparable<ITmfTimestamp> {
+public interface ITmfTimestamp extends Comparable<ITmfTimestamp> {
// ------------------------------------------------------------------------
// Getters
*/
public ITmfTimestamp getDelta(ITmfTimestamp ts);
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
/**
* @return a clone of the timestamp
*/
* copy of the event is needed, use the copy constructor. Otherwise (deep copy)
* use clone().
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* @see ITmfEventField
* @see ITmfTrace
*/
-public class TmfEvent implements ITmfEvent {
+public class TmfEvent implements ITmfEvent, Cloneable {
// ------------------------------------------------------------------------
// Attributes
* Non-value fields are structural (i.e. used to represent the event structure
* including optional fields) while the valued fields are actual event fields.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* @see ITmfEvent
* @see ITmfEventType
*/
-public class TmfEventField implements ITmfEventField {
+public class TmfEventField implements ITmfEventField, Cloneable {
// ------------------------------------------------------------------------
// Attributes
/**
* A basic implementation of ITmfEventType.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* @see ITmfEvent
* @see ITmfEventField
*/
-public class TmfEventType implements ITmfEventType {
+public class TmfEventType implements ITmfEventType, Cloneable {
// ------------------------------------------------------------------------
// Attributes
* A central repository for the available event types. Types are managed by
* context space.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
/**
* A simplified timestamp where scale and precision are set to 0.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*/
-public class TmfSimpleTimestamp extends TmfTimestamp {
+public class TmfSimpleTimestamp extends TmfTimestamp implements Cloneable {
// ------------------------------------------------------------------------
// Constructors
* @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#normalize(long, int)
*/
@Override
- public ITmfTimestamp normalize(final long offset, final int scale) throws ArithmeticException {
+ public ITmfTimestamp normalize(final long offset, final int scale) {
if (scale == 0) {
return new TmfSimpleTimestamp(getValue() + offset);
}
/**
* A utility class to define and manage time ranges.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* The null time range
*/
public static final TmfTimeRange NULL_RANGE =
- new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_BANG);
+ new TmfTimeRange(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_BANG);
// ------------------------------------------------------------------------
// Attributes
* @see java.lang.Object#clone()
*/
@Override
- public TmfTimeRange clone() {
+ public TmfTimeRange clone() throws CloneNotSupportedException {
TmfTimeRange clone = null;
try {
clone = (TmfTimeRange) super.clone();
package org.eclipse.linuxtools.tmf.core.event;
+
/**
* A generic timestamp implementation. The timestamp is represented by the
* tuple { value, scale, precision }.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*/
* @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#normalize(long, int)
*/
@Override
- public ITmfTimestamp normalize(final long offset, final int scale) throws ArithmeticException {
+ public ITmfTimestamp normalize(final long offset, final int scale) {
long value = fValue;
int precision = fPrecision;
/*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009, 2010, 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
*
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Updated as per TMF Trace Model 1.0
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.experiment;
-import java.util.Collections;
-import java.util.Vector;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
/**
- * <b><u>TmfExperiment</u></b>
- * <p>
* TmfExperiment presents a time-ordered, unified view of a set of TmfTraces
* that are part of a tracing experiment.
- * <p>
*/
-public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> implements ITmfTrace<T> {
+public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements ITmfEventParser<T> {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ // The index page size
+ private static final int DEFAULT_INDEX_PAGE_SIZE = 5000;
// ------------------------------------------------------------------------
// Attributes
// The set of traces that constitute the experiment
protected ITmfTrace<T>[] fTraces;
- // The total number of events
- protected long fNbEvents;
-
- // The experiment time range
- protected TmfTimeRange fTimeRange;
-
- // The experiment reference timestamp (default: ZERO)
- protected ITmfTimestamp fEpoch;
-
- // The experiment index
- protected Vector<TmfCheckpoint> fCheckpoints = new Vector<TmfCheckpoint>();
-
- // The current experiment context
- protected TmfExperimentContext fExperimentContext;
-
// Flag to initialize only once
- private boolean fInitialized = false;
+ protected boolean fInitialized = false;
// The experiment bookmarks file
- private IFile fBookmarksFile;
+ protected IFile fBookmarksFile;
- // The properties resource
- private IResource fResource;
+// // The properties resource
+// private IResource fResource;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
- @Override
- public TmfExperiment<T> clone() throws CloneNotSupportedException {
- throw new CloneNotSupportedException();
- }
-
@Override
public boolean validate(final IProject project, final String path) {
return true;
}
@Override
- public void initTrace(final IResource resource, final String path, final Class<T> eventType) {
- fResource = resource;
+ public void initTrace(final IResource resource, final String path, final Class<T> type) {
+// fResource = resource;
+ try {
+ super.initTrace(resource, path, type);
+ } catch (TmfTraceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
/**
* @param traces
* @param epoch
* @param indexPageSize
+ * @throws TmfTraceException
*/
public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final ITmfTimestamp epoch,
- final int indexPageSize) {
+ final int indexPageSize)
+ {
this(type, id, traces, TmfTimestamp.ZERO, indexPageSize, false);
}
- public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final ITmfTimestamp epoch,
- final int indexPageSize, final boolean preIndexExperiment) {
- super(id, type);
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public TmfExperiment(final Class<T> type, final String path, final ITmfTrace<T>[] traces, final ITmfTimestamp epoch,
+ final int indexPageSize, final boolean preIndexExperiment)
+ {
+ setCacheSize(indexPageSize);
+ setStreamingInterval(0);
+ setIndexer(new TmfCheckpointIndexer(this, indexPageSize));
+ setParser(this);
+ try {
+ super.initialize(null, path, type);
+ } catch (TmfTraceException e) {
+ e.printStackTrace();
+ }
fTraces = traces;
- fEpoch = epoch;
- fIndexPageSize = indexPageSize;
- fTimeRange = TmfTimeRange.NULL_RANGE;
+ setTimeRange(TmfTimeRange.NULL_RANGE);
if (preIndexExperiment) {
- indexExperiment(true, 0, TmfTimeRange.ETERNITY);
- updateTimeRange();
+ getIndexer().buildIndex(true);
}
}
- protected TmfExperiment(final String id, final Class<T> type) {
- super(id, type);
- }
-
/**
* @param type
* @param id
* @param traces
+ * @throws TmfTraceException
*/
public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces) {
this(type, id, traces, TmfTimestamp.ZERO, DEFAULT_INDEX_PAGE_SIZE);
* @param id
* @param traces
* @param indexPageSize
+ * @throws TmfTraceException
*/
public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final int indexPageSize) {
this(type, id, traces, TmfTimestamp.ZERO, indexPageSize);
trace.dispose();
fTraces = null;
}
- if (fCheckpoints != null)
- fCheckpoints.clear();
super.dispose();
}
- // ------------------------------------------------------------------------
- // ITmfTrace
- // ------------------------------------------------------------------------
-
- @Override
- public Class<T> getEventType() {
- return fType;
- }
-
- @Override
- public long getNbEvents() {
- return fNbEvents;
- }
-
- @Override
- public int getCacheSize() {
- return fIndexPageSize;
- }
-
- @Override
- public TmfTimeRange getTimeRange() {
- return fTimeRange;
- }
-
- @Override
- public ITmfTimestamp getStartTime() {
- return fTimeRange.getStartTime();
- }
-
- @Override
- public ITmfTimestamp getEndTime() {
- return fTimeRange.getEndTime();
- }
-
- public Vector<TmfCheckpoint> getCheckpoints() {
- return fCheckpoints;
- }
-
// ------------------------------------------------------------------------
// Accessors
// ------------------------------------------------------------------------
return fCurrentExperiment;
}
- public ITmfTimestamp getEpoch() {
- return fEpoch;
- }
-
public ITmfTrace<T>[] getTraces() {
return fTraces;
}
* @return the corresponding event timestamp
*/
public ITmfTimestamp getTimestamp(final int index) {
- final TmfExperimentContext context = seekEvent(index);
- final ITmfEvent event = readNextEvent(context);
+ final ITmfContext context = seekEvent(index);
+ final ITmfEvent event = getNext(context);
return (event != null) ? event.getTimestamp() : null;
}
- // ------------------------------------------------------------------------
- // Operators
- // ------------------------------------------------------------------------
-
- /**
- * Update the global time range
- */
- protected void updateTimeRange() {
- ITmfTimestamp startTime = fTimeRange != TmfTimeRange.NULL_RANGE ? fTimeRange.getStartTime() : TmfTimestamp.BIG_CRUNCH;
- ITmfTimestamp endTime = fTimeRange != TmfTimeRange.NULL_RANGE ? fTimeRange.getEndTime() : TmfTimestamp.BIG_BANG;
-
- for (final ITmfTrace<T> trace : fTraces) {
- final ITmfTimestamp traceStartTime = trace.getStartTime();
- if (traceStartTime.compareTo(startTime, true) < 0)
- startTime = traceStartTime;
- final ITmfTimestamp traceEndTime = trace.getEndTime();
- if (traceEndTime.compareTo(endTime, true) > 0)
- endTime = traceEndTime;
- }
- fTimeRange = new TmfTimeRange(startTime, endTime);
- }
-
// ------------------------------------------------------------------------
// TmfProvider
// ------------------------------------------------------------------------
@Override
public ITmfContext armRequest(final ITmfDataRequest<T> request) {
- // Tracer.trace("Ctx: Arming request - start");
ITmfTimestamp timestamp = (request instanceof ITmfEventRequest<?>) ? ((ITmfEventRequest<T>) request).getRange().getStartTime() : null;
- if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0)
- timestamp = null; // use request index
- TmfExperimentContext context = null;
- if (timestamp != null) {
- // seek by timestamp
+ if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0) {
+ timestamp = null;
+ }
+
+ ITmfContext context = null;
+ if (timestamp != null) { // Seek by timestamp
context = seekEvent(timestamp);
((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank());
- } else // Seek by rank
- if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex())
- // We are already at the right context -> no need to seek
- context = fExperimentContext;
- else
- context = seekEvent(request.getIndex());
- // Tracer.trace("Ctx: Arming request - done");
- return context;
- }
+ } else { // Seek by rank
+ context = seekEvent(request.getIndex());
+ }
- @Override
- @SuppressWarnings("unchecked")
- public T getNext(final ITmfContext context) {
- if (context instanceof TmfExperimentContext)
- return (T) readNextEvent(context);
- return null;
+ return context;
}
// ------------------------------------------------------------------------
// Instantiate the location
final TmfExperimentLocation expLocation = (location == null) ? new TmfExperimentLocation(new TmfLocationArray(
- new ITmfLocation<?>[fTraces.length]), new long[fTraces.length]) : (TmfExperimentLocation) location.clone();
+ new ITmfLocation<?>[fTraces.length])) : (TmfExperimentLocation) location.clone();
// Create and populate the context's traces contexts
- final TmfExperimentContext context = new TmfExperimentContext(fTraces, new ITmfContext[fTraces.length]);
- // Tracer.trace("Ctx: SeekLocation - start");
+ final TmfExperimentContext context = new TmfExperimentContext(new ITmfContext[fTraces.length]);
- long rank = 0;
for (int i = 0; i < fTraces.length; i++) {
// Get the relevant trace attributes
- final ITmfLocation<?> traceLocation = expLocation.getLocation().locations[i];
- final long traceRank = expLocation.getRanks()[i];
-
- // Set the corresponding sub-context
+ final ITmfLocation<?> traceLocation = expLocation.getLocation().getLocations()[i];
context.getContexts()[i] = fTraces[i].seekEvent(traceLocation);
- context.getContexts()[i].setRank(traceRank);
- rank += traceRank;
-
- // Set the trace location and read the corresponding event
- /*
- * The (TmfContext) cast should be safe since we created 'context'
- * ourselves higher up.
- */
- expLocation.getLocation().locations[i] = context.getContexts()[i].getLocation().clone();
- context.getEvents()[i] = fTraces[i].readNextEvent(context.getContexts()[i]);
+ expLocation.getLocation().getLocations()[i] = context.getContexts()[i].getLocation().clone();
+ context.getEvents()[i] = fTraces[i].getNext(context.getContexts()[i]);
}
- // Tracer.trace("Ctx: SeekLocation - done");
-
// Finalize context
context.setLocation(expLocation);
context.setLastTrace(TmfExperimentContext.NO_TRACE);
- context.setRank(rank);
-
- fExperimentContext = context;
-
+ context.setRank(ITmfContext.UNKNOWN_RANK);
return context;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp)
- */
@Override
- public synchronized TmfExperimentContext seekEvent(ITmfTimestamp timestamp) {
-
- // Tracer.trace("Ctx: seekEvent(TS) - start");
-
- if (timestamp == null)
- timestamp = TmfTimestamp.BIG_BANG;
-
- // First, find the right checkpoint
- int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null));
-
- // In the very likely case that the checkpoint was not found, bsearch
- // returns its negated would-be location (not an offset...). From that
- // index, we can then position the stream and get the event.
- if (index < 0)
- index = Math.max(0, -(index + 2));
-
- // Position the experiment at the checkpoint
- ITmfLocation<?> location;
- synchronized (fCheckpoints) {
- if (fCheckpoints.size() > 0) {
- if (index >= fCheckpoints.size())
- index = fCheckpoints.size() - 1;
- location = fCheckpoints.elementAt(index).getLocation();
- } else
- location = null;
- }
-
- final TmfExperimentContext context = seekEvent(location);
- context.setRank((long) index * fIndexPageSize);
-
- // And locate the event
- ITmfEvent event = parseEvent(context);
- while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) {
- readNextEvent(context);
- event = parseEvent(context);
- }
-
- if (event == null) {
- context.setLocation(null);
- context.setRank(ITmfContext.UNKNOWN_RANK);
- }
-
- return context;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long)
- */
- @Override
- public synchronized TmfExperimentContext seekEvent(final long rank) {
-
- // Tracer.trace("Ctx: seekEvent(rank) - start");
-
- // Position the stream at the previous checkpoint
- int index = (int) rank / fIndexPageSize;
- ITmfLocation<?> location;
- synchronized (fCheckpoints) {
- if (fCheckpoints.size() == 0)
- location = null;
- else {
- if (index >= fCheckpoints.size())
- index = fCheckpoints.size() - 1;
- location = fCheckpoints.elementAt(index).getLocation();
- }
- }
-
- final TmfExperimentContext context = seekEvent(location);
- context.setRank((long) index * fIndexPageSize);
-
- // And locate the event
- ITmfEvent event = parseEvent(context);
- long pos = context.getRank();
- while ((event != null) && (pos++ < rank)) {
- readNextEvent(context);
- event = parseEvent(context);
- }
-
- if (event == null) {
- context.setLocation(null);
- context.setRank(ITmfContext.UNKNOWN_RANK);
- }
-
- return context;
- }
-
- @Override
- public TmfContext seekEvent(final double ratio) {
- final TmfContext context = seekEvent((long) (ratio * getNbEvents()));
+ public ITmfContext seekEvent(final double ratio) {
+ final ITmfContext context = seekEvent((long) (ratio * getNbEvents()));
return context;
}
@Override
public ITmfLocation<?> getCurrentLocation() {
- if (fExperimentContext != null)
- return fExperimentContext.getLocation();
- return null;
+ ITmfLocation<?>[] locations = new ITmfLocation<?>[fTraces.length];
+ for (int i = 0; i < fTraces.length; i++) {
+ locations[i] = fTraces[i].getCurrentLocation();
+ }
+ return new TmfExperimentLocation(new TmfLocationArray(locations));
}
- // private void dumpContext(TmfExperimentContext context, boolean isBefore) {
- // TmfContext context0 = context.getContexts()[0];
- // TmfEvent event0 = context.getEvents()[0];
- // TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation();
- // long rank0 = context.getRank();
- // int trace = context.getLastTrace();
- //
- // StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A "));
- //
- // result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] ");
- // result.append("[Evt: " + event0.getTimestamp().toString() + "] ");
- // result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] ");
- // result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]");
- // Tracer.trace(result.toString());
- // }
-
- /**
- * Scan the next events from all traces and return the next one in
- * chronological order.
- *
- * @param context the trace context
- * @return the next event
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
*/
@Override
- public synchronized ITmfEvent readNextEvent(final ITmfContext context) {
-
- // Validate the context
- if (!(context instanceof TmfExperimentContext))
- return null; // Throw an exception?
-
- if (!context.equals(fExperimentContext))
- // Tracer.trace("Ctx: Restoring context");
- fExperimentContext = seekEvent(context.getLocation());
-
- final TmfExperimentContext expContext = (TmfExperimentContext) context;
-
- // dumpContext(expContext, true);
-
- // If an event was consumed previously, get the next one from that trace
- final int lastTrace = expContext.getLastTrace();
- if (lastTrace != TmfExperimentContext.NO_TRACE) {
- final ITmfContext traceContext = expContext.getContexts()[lastTrace];
- expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].readNextEvent(traceContext);
- expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
- }
-
- // Scan the candidate events and identify the "next" trace to read from
- final ITmfEvent eventArray[] = expContext.getEvents();
- if (eventArray == null)
- return null;
- int trace = TmfExperimentContext.NO_TRACE;
- ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
- if (eventArray.length == 1) {
- if (eventArray[0] != null) {
- timestamp = eventArray[0].getTimestamp();
- trace = 0;
- }
- } else
- for (int i = 0; i < eventArray.length; i++) {
- final ITmfEvent event = eventArray[i];
- if (event != null && event.getTimestamp() != null) {
- final ITmfTimestamp otherTS = event.getTimestamp();
- if (otherTS.compareTo(timestamp, true) < 0) {
- trace = i;
- timestamp = otherTS;
- }
- }
+ public synchronized T getNext(final ITmfContext context) {
+ final ITmfContext previousContext = (TmfExperimentContext) context.clone();
+ final T event = parseEvent(context);
+ if (event != null) {
+ updateAttributes(previousContext, event.getTimestamp());
+
+ TmfExperimentContext expContext = (TmfExperimentContext) context;
+ int trace = expContext.getLastTrace();
+ if (trace != TmfExperimentContext.NO_TRACE) {
+ TmfExperimentLocation location = (TmfExperimentLocation) expContext.getLocation();
+ location.getLocation().getLocations()[trace] = expContext.getContexts()[trace].getLocation();
}
- // Update the experiment context and set the "next" event
- ITmfEvent event = null;
- if (trace != TmfExperimentContext.NO_TRACE) {
- updateIndex(expContext, timestamp);
-
- final ITmfContext traceContext = expContext.getContexts()[trace];
- final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
- // expLocation.getLocation()[trace] = traceContext.getLocation().clone();
- expLocation.getLocation().locations[trace] = traceContext.getLocation().clone();
-
- // updateIndex(expContext, timestamp);
-
- expLocation.getRanks()[trace] = traceContext.getRank();
- expContext.setLastTrace(trace);
- expContext.increaseRank();
- event = expContext.getEvents()[trace];
- fExperimentContext = expContext;
+
+ context.increaseRank();
+ processEvent(event);
}
-
- // if (event != null) {
- // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
- // dumpContext(expContext, false);
- // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
- // }
-
return event;
}
- public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) {
- // Build the index as we go along
- final long rank = context.getRank();
- if (context.hasValidRank() && (rank % fIndexPageSize) == 0) {
- // Determine the table position
- final long position = rank / fIndexPageSize;
- // Add new entry at proper location (if empty)
- if (fCheckpoints.size() == position) {
- final ITmfLocation<?> location = context.getLocation().clone();
- fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location));
- // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", "
- // + location.toString());
- }
- }
- }
-
/* (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext)
*/
-// @Override
- public ITmfEvent parseEvent(final ITmfContext context) {
+ @SuppressWarnings("unchecked")
+ @Override
+ public T parseEvent(ITmfContext context) {
// Validate the context
if (!(context instanceof TmfExperimentContext))
return null; // Throw an exception?
- if (!context.equals(fExperimentContext))
- // Tracer.trace("Ctx: Restoring context");
- seekEvent(context.getLocation());
+ TmfExperimentContext expContext = (TmfExperimentContext) context;
- final TmfExperimentContext expContext = (TmfExperimentContext) context;
-
- // If an event was consumed previously, get the next one from that trace
+ // If an event was consumed previously, first get the next one from that trace
final int lastTrace = expContext.getLastTrace();
if (lastTrace != TmfExperimentContext.NO_TRACE) {
final ITmfContext traceContext = expContext.getContexts()[lastTrace];
- expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].readNextEvent(traceContext);
+ expContext.getEvents()[lastTrace] = fTraces[lastTrace].getNext(traceContext);
expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
- fExperimentContext = (TmfExperimentContext) context;
}
// Scan the candidate events and identify the "next" trace to read from
int trace = TmfExperimentContext.NO_TRACE;
ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
- for (int i = 0; i < expContext.getTraces().length; i++) {
+ for (int i = 0; i < fTraces.length; i++) {
final ITmfEvent event = expContext.getEvents()[i];
if (event != null && event.getTimestamp() != null) {
final ITmfTimestamp otherTS = event.getTimestamp();
}
}
- ITmfEvent event = null;
- if (trace != TmfExperimentContext.NO_TRACE)
- event = expContext.getEvents()[trace];
+ T event = null;
+ if (trace != TmfExperimentContext.NO_TRACE) {
+ event = (T) expContext.getEvents()[trace];
+ }
+ expContext.setLastTrace(trace);
return event;
}
fInitialized = true;
if (getStreamingInterval() == 0) {
- final TmfContext context = seekEvent(0);
+ final ITmfContext context = seekEvent(0);
final ITmfEvent event = getNext(context);
if (event == null)
return;
* event).
*/
- // The index page size
- private static final int DEFAULT_INDEX_PAGE_SIZE = 5000;
- protected int fIndexPageSize;
+// protected int fIndexPageSize;
protected boolean fIndexing = false;
- protected TmfTimeRange fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
+// protected TmfTimeRange fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
private Integer fEndSynchReference;
- // private static BufferedWriter fEventLog = null;
- // private static BufferedWriter openLogFile(String filename) {
- // BufferedWriter outfile = null;
- // try {
- // outfile = new BufferedWriter(new FileWriter(filename));
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
- // return outfile;
- // }
-
protected boolean isIndexingBusy() {
- synchronized (fCheckpoints) {
- return fIndexing;
- }
+ return fIndexing;
}
- @SuppressWarnings("unchecked")
- private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) {
-
- synchronized (fCheckpoints) {
- if (fIndexing)
- return;
- fIndexing = true;
- }
-
- final Job job = new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
-
- @Override
- protected IStatus run(final IProgressMonitor monitor) {
- while (!monitor.isCanceled())
- try {
- Thread.sleep(100);
- } catch (final InterruptedException e) {
- return Status.OK_STATUS;
- }
- monitor.done();
- return Status.OK_STATUS;
- }
- };
- job.schedule();
-
- // fEventLog = openLogFile("TraceEvent.log");
- // System.out.println(System.currentTimeMillis() + ": Experiment indexing started");
-
- final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, timeRange, index,
- TmfDataRequest.ALL_DATA,
- fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA
- // FOREGROUND
-
- // long indexingStart = System.nanoTime();
-
- ITmfTimestamp startTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getStartTime();
- ITmfTimestamp lastTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getEndTime();
- long initialNbEvents = fNbEvents;
-
- @Override
- public void handleStarted() {
- super.handleStarted();
- }
-
- @Override
- public void handleData(final ITmfEvent event) {
- super.handleData(event);
- if (event != null) {
- final ITmfTimestamp ts = event.getTimestamp();
- if (startTime == null)
- startTime = ts.clone();
- lastTime = ts.clone();
- }
- if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1)
- updateExperiment();
- }
-
- @Override
- public void handleSuccess() {
- // long indexingEnd = System.nanoTime();
-
- // if the end time is a real value then it is the streaming safe
- // time stamp
- // set the last time to the safe time stamp to prevent
- // unnecessary indexing requests
- if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH)
- lastTime = getRange().getEndTime();
- updateExperiment();
- // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed");
-
- // long average = (indexingEnd - indexingStart) / fNbEvents;
- // System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed="
- // + (indexingEnd * 1.0 - indexingStart) / 1000000000);
- // System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "."
- // + (average % 1000) + " us/evt)");
- super.handleSuccess();
- }
-
- @Override
- public void handleCompleted() {
- job.cancel();
- super.handleCompleted();
- synchronized (fCheckpoints) {
- fIndexing = false;
- if (fIndexingPendingRange != TmfTimeRange.NULL_RANGE) {
- indexExperiment(false, (int) fNbEvents, fIndexingPendingRange);
- fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
- }
- }
- }
-
- private void updateExperiment() {
- final int nbRead = getNbRead();
- if (startTime != null)
- fTimeRange = new TmfTimeRange(startTime, lastTime.clone());
- if (nbRead != 0) {
- // updateTimeRange();
- // updateNbEvents();
- fNbEvents = initialNbEvents + nbRead;
- notifyListeners();
- }
- }
- };
- sendRequest((ITmfDataRequest<T>) request);
- if (waitForCompletion)
- try {
- request.waitForCompletion();
- } catch (final InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- protected void notifyListeners() {
- broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null));
- // broadcast(new TmfExperimentRangeUpdatedSignal(this, this,
- // fTimeRange)); // , null));
- }
+// protected void notifyListeners() {
+// broadcast(new TmfExperimentUpdatedSignal(this, this));
+// }
// ------------------------------------------------------------------------
// Signal handlers
// ------------------------------------------------------------------------
+ @TmfSignalHandler
+ public void traceUpdated(final TmfTraceUpdatedSignal signal) {
+ if (signal.getTrace() == this) {
+ broadcast(new TmfExperimentUpdatedSignal(this, this));
+ }
+ }
+
@TmfSignalHandler
public void experimentSelected(final TmfExperimentSelectedSignal<T> signal) {
final TmfExperiment<?> experiment = signal.getExperiment();
@TmfSignalHandler
public void experimentRangeUpdated(final TmfExperimentRangeUpdatedSignal signal) {
- if (signal.getExperiment() == this)
- indexExperiment(false, (int) fNbEvents, signal.getRange());
- }
-
- @TmfSignalHandler
- public void traceUpdated(final TmfTraceUpdatedSignal signal) {
- for (final ITmfTrace<T> trace : fTraces)
- if (trace == signal.getTrace()) {
- synchronized (fCheckpoints) {
- if (fIndexing) {
- if (fIndexingPendingRange == TmfTimeRange.NULL_RANGE)
- fIndexingPendingRange = signal.getRange();
- else {
- ITmfTimestamp startTime = fIndexingPendingRange.getStartTime();
- ITmfTimestamp endTime = fIndexingPendingRange.getEndTime();
- if (signal.getRange().getStartTime().compareTo(startTime) < 0)
- startTime = signal.getRange().getStartTime();
- if (signal.getRange().getEndTime().compareTo(endTime) > 0)
- endTime = signal.getRange().getEndTime();
- fIndexingPendingRange = new TmfTimeRange(startTime, endTime);
- }
- return;
- }
- }
- indexExperiment(false, (int) fNbEvents, signal.getRange());
- return;
- }
+ if (signal.getExperiment() == this) {
+ getIndexer().buildIndex(false);
+ }
}
@Override
return fBookmarksFile;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
- */
- @Override
- public IResource getResource() {
- return fResource;
- }
+// /*
+// * (non-Javadoc)
+// *
+// * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
+// */
+// @Override
+// public IResource getResource() {
+// return fResource;
+// }
}
+
+
+///*******************************************************************************
+// * Copyright (c) 2009, 2010 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:
+// * Francois Chouinard - Initial API and implementation
+// *******************************************************************************/
+//
+//package org.eclipse.linuxtools.tmf.core.experiment;
+//
+//import java.util.Collections;
+//import java.util.Vector;
+//
+//import org.eclipse.core.resources.IFile;
+//import org.eclipse.core.resources.IProject;
+//import org.eclipse.core.resources.IResource;
+//import org.eclipse.core.runtime.IProgressMonitor;
+//import org.eclipse.core.runtime.IStatus;
+//import org.eclipse.core.runtime.Status;
+//import org.eclipse.core.runtime.jobs.Job;
+//import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
+//import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+//import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+//import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+//import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+//import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+//import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
+//import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+//import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
+//import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+//import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+//import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+//import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
+//import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+//
+///**
+// * <b><u>TmfExperiment</u></b>
+// * <p>
+// * TmfExperiment presents a time-ordered, unified view of a set of TmfTraces
+// * that are part of a tracing experiment.
+// * <p>
+// */
+//public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> implements ITmfTrace<T> {
+//
+// // ------------------------------------------------------------------------
+// // Attributes
+// // ------------------------------------------------------------------------
+//
+// // The currently selected experiment
+// protected static TmfExperiment<?> fCurrentExperiment = null;
+//
+// // The set of traces that constitute the experiment
+// protected ITmfTrace<T>[] fTraces;
+//
+// // The total number of events
+// protected long fNbEvents;
+//
+// // The experiment time range
+// protected TmfTimeRange fTimeRange;
+//
+// // The experiment reference timestamp (default: ZERO)
+// protected ITmfTimestamp fEpoch;
+//
+// // The experiment index
+// protected Vector<TmfCheckpoint> fCheckpoints = new Vector<TmfCheckpoint>();
+//
+// // The current experiment context
+// protected TmfExperimentContext fExperimentContext;
+//
+// // Flag to initialize only once
+// private boolean fInitialized = false;
+//
+// // The experiment bookmarks file
+// private IFile fBookmarksFile;
+//
+// // The properties resource
+// private IResource fResource;
+//
+// // ------------------------------------------------------------------------
+// // Constructors
+// // ------------------------------------------------------------------------
+//
+// @Override
+// public TmfExperiment<T> clone() throws CloneNotSupportedException {
+// throw new CloneNotSupportedException();
+// }
+//
+// @Override
+// public boolean validate(final IProject project, final String path) {
+// return true;
+// }
+//
+// @Override
+// public void initTrace(final IResource resource, final String path, final Class<T> eventType) {
+// fResource = resource;
+// }
+//
+// /**
+// * @param type
+// * @param id
+// * @param traces
+// * @param epoch
+// * @param indexPageSize
+// */
+// public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final ITmfTimestamp epoch,
+// final int indexPageSize) {
+// this(type, id, traces, TmfTimestamp.ZERO, indexPageSize, false);
+// }
+//
+// public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final ITmfTimestamp epoch,
+// final int indexPageSize, final boolean preIndexExperiment) {
+// super(id, type);
+//
+// fTraces = traces;
+// fEpoch = epoch;
+// fIndexPageSize = indexPageSize;
+// fTimeRange = TmfTimeRange.NULL_RANGE;
+//
+// if (preIndexExperiment) {
+// indexExperiment(true, 0, TmfTimeRange.ETERNITY);
+// updateTimeRange();
+// }
+// }
+//
+// protected TmfExperiment(final String id, final Class<T> type) {
+// super(id, type);
+// }
+//
+// /**
+// * @param type
+// * @param id
+// * @param traces
+// */
+// public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces) {
+// this(type, id, traces, TmfTimestamp.ZERO, DEFAULT_INDEX_PAGE_SIZE);
+// }
+//
+// /**
+// * @param type
+// * @param id
+// * @param traces
+// * @param indexPageSize
+// */
+// public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final int indexPageSize) {
+// this(type, id, traces, TmfTimestamp.ZERO, indexPageSize);
+// }
+//
+// /**
+// * Clears the experiment
+// */
+// @Override
+// @SuppressWarnings("rawtypes")
+// public synchronized void dispose() {
+//
+// final TmfExperimentDisposedSignal<T> signal = new TmfExperimentDisposedSignal<T>(this, this);
+// broadcast(signal);
+// if (fCurrentExperiment == this)
+// fCurrentExperiment = null;
+//
+// if (fTraces != null) {
+// for (final ITmfTrace trace : fTraces)
+// trace.dispose();
+// fTraces = null;
+// }
+// if (fCheckpoints != null)
+// fCheckpoints.clear();
+// super.dispose();
+// }
+//
+// // ------------------------------------------------------------------------
+// // ITmfTrace
+// // ------------------------------------------------------------------------
+//
+// @Override
+// public Class<T> getEventType() {
+// return fType;
+// }
+//
+// @Override
+// public long getNbEvents() {
+// return fNbEvents;
+// }
+//
+// @Override
+// public int getCacheSize() {
+// return fIndexPageSize;
+// }
+//
+// @Override
+// public TmfTimeRange getTimeRange() {
+// return fTimeRange;
+// }
+//
+// @Override
+// public ITmfTimestamp getStartTime() {
+// return fTimeRange.getStartTime();
+// }
+//
+// @Override
+// public ITmfTimestamp getEndTime() {
+// return fTimeRange.getEndTime();
+// }
+//
+// public Vector<TmfCheckpoint> getCheckpoints() {
+// return fCheckpoints;
+// }
+//
+// // ------------------------------------------------------------------------
+// // Accessors
+// // ------------------------------------------------------------------------
+//
+// public static void setCurrentExperiment(final TmfExperiment<?> experiment) {
+// if (fCurrentExperiment != null && fCurrentExperiment != experiment)
+// fCurrentExperiment.dispose();
+// fCurrentExperiment = experiment;
+// }
+//
+// public static TmfExperiment<?> getCurrentExperiment() {
+// return fCurrentExperiment;
+// }
+//
+// public ITmfTimestamp getEpoch() {
+// return fEpoch;
+// }
+//
+// public ITmfTrace<T>[] getTraces() {
+// return fTraces;
+// }
+//
+// /**
+// * Returns the timestamp of the event at the requested index. If none,
+// * returns null.
+// *
+// * @param index the event index (rank)
+// * @return the corresponding event timestamp
+// */
+// public ITmfTimestamp getTimestamp(final int index) {
+// final TmfExperimentContext context = seekEvent(index);
+// final ITmfEvent event = readNextEvent(context);
+// return (event != null) ? event.getTimestamp() : null;
+// }
+//
+// // ------------------------------------------------------------------------
+// // Operators
+// // ------------------------------------------------------------------------
+//
+// /**
+// * Update the global time range
+// */
+// protected void updateTimeRange() {
+// ITmfTimestamp startTime = fTimeRange != TmfTimeRange.NULL_RANGE ? fTimeRange.getStartTime() : TmfTimestamp.BIG_CRUNCH;
+// ITmfTimestamp endTime = fTimeRange != TmfTimeRange.NULL_RANGE ? fTimeRange.getEndTime() : TmfTimestamp.BIG_BANG;
+//
+// for (final ITmfTrace<T> trace : fTraces) {
+// final ITmfTimestamp traceStartTime = trace.getStartTime();
+// if (traceStartTime.compareTo(startTime, true) < 0)
+// startTime = traceStartTime;
+// final ITmfTimestamp traceEndTime = trace.getEndTime();
+// if (traceEndTime.compareTo(endTime, true) > 0)
+// endTime = traceEndTime;
+// }
+// fTimeRange = new TmfTimeRange(startTime, endTime);
+// }
+//
+// // ------------------------------------------------------------------------
+// // TmfProvider
+// // ------------------------------------------------------------------------
+//
+// @Override
+// public ITmfContext armRequest(final ITmfDataRequest<T> request) {
+// // Tracer.trace("Ctx: Arming request - start");
+// ITmfTimestamp timestamp = (request instanceof ITmfEventRequest<?>) ? ((ITmfEventRequest<T>) request).getRange().getStartTime() : null;
+// if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0)
+// timestamp = null; // use request index
+// TmfExperimentContext context = null;
+// if (timestamp != null) {
+// // seek by timestamp
+// context = seekEvent(timestamp);
+// ((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank());
+// } else // Seek by rank
+// if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex())
+// // We are already at the right context -> no need to seek
+// context = fExperimentContext;
+// else
+// context = seekEvent(request.getIndex());
+// // Tracer.trace("Ctx: Arming request - done");
+// return context;
+// }
+//
+// @Override
+// @SuppressWarnings("unchecked")
+// public T getNext(final ITmfContext context) {
+// if (context instanceof TmfExperimentContext)
+// return (T) readNextEvent(context);
+// return null;
+// }
+//
+// // ------------------------------------------------------------------------
+// // ITmfTrace trace positioning
+// // ------------------------------------------------------------------------
+//
+// // Returns a brand new context based on the location provided
+// // and initializes the event queues
+// @Override
+// public synchronized TmfExperimentContext seekEvent(final ITmfLocation<?> location) {
+// // Validate the location
+// if (location != null && !(location instanceof TmfExperimentLocation))
+// return null; // Throw an exception?
+//
+// if (fTraces == null)
+// return null;
+//
+// // Instantiate the location
+// final TmfExperimentLocation expLocation = (location == null) ? new TmfExperimentLocation(new TmfLocationArray(
+// new ITmfLocation<?>[fTraces.length]), new long[fTraces.length]) : (TmfExperimentLocation) location.clone();
+//
+// // Create and populate the context's traces contexts
+// final TmfExperimentContext context = new TmfExperimentContext(fTraces, new ITmfContext[fTraces.length]);
+// // Tracer.trace("Ctx: SeekLocation - start");
+//
+// long rank = 0;
+// for (int i = 0; i < fTraces.length; i++) {
+// // Get the relevant trace attributes
+// final ITmfLocation<?> traceLocation = expLocation.getLocation().locations[i];
+// final long traceRank = expLocation.getRanks()[i];
+//
+// // Set the corresponding sub-context
+// context.getContexts()[i] = fTraces[i].seekEvent(traceLocation);
+// context.getContexts()[i].setRank(traceRank);
+// rank += traceRank;
+//
+// // Set the trace location and read the corresponding event
+// /*
+// * The (TmfContext) cast should be safe since we created 'context'
+// * ourselves higher up.
+// */
+// expLocation.getLocation().locations[i] = context.getContexts()[i].getLocation().clone();
+// context.getEvents()[i] = fTraces[i].readNextEvent(context.getContexts()[i]);
+// }
+//
+// // Tracer.trace("Ctx: SeekLocation - done");
+//
+// // Finalize context
+// context.setLocation(expLocation);
+// context.setLastTrace(TmfExperimentContext.NO_TRACE);
+// context.setRank(rank);
+//
+// fExperimentContext = context;
+//
+// return context;
+// }
+//
+// /* (non-Javadoc)
+// * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp)
+// */
+// @Override
+// public synchronized TmfExperimentContext seekEvent(ITmfTimestamp timestamp) {
+//
+// // Tracer.trace("Ctx: seekEvent(TS) - start");
+//
+// if (timestamp == null)
+// timestamp = TmfTimestamp.BIG_BANG;
+//
+// // First, find the right checkpoint
+// int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null));
+//
+// // In the very likely case that the checkpoint was not found, bsearch
+// // returns its negated would-be location (not an offset...). From that
+// // index, we can then position the stream and get the event.
+// if (index < 0)
+// index = Math.max(0, -(index + 2));
+//
+// // Position the experiment at the checkpoint
+// ITmfLocation<?> location;
+// synchronized (fCheckpoints) {
+// if (fCheckpoints.size() > 0) {
+// if (index >= fCheckpoints.size())
+// index = fCheckpoints.size() - 1;
+// location = fCheckpoints.elementAt(index).getLocation();
+// } else
+// location = null;
+// }
+//
+// final TmfExperimentContext context = seekEvent(location);
+// context.setRank((long) index * fIndexPageSize);
+//
+// // And locate the event
+// ITmfEvent event = parseEvent(context);
+// while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) {
+// readNextEvent(context);
+// event = parseEvent(context);
+// }
+//
+// if (event == null) {
+// context.setLocation(null);
+// context.setRank(ITmfContext.UNKNOWN_RANK);
+// }
+//
+// return context;
+// }
+//
+// /* (non-Javadoc)
+// * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long)
+// */
+// @Override
+// public synchronized TmfExperimentContext seekEvent(final long rank) {
+//
+// // Tracer.trace("Ctx: seekEvent(rank) - start");
+//
+// // Position the stream at the previous checkpoint
+// int index = (int) rank / fIndexPageSize;
+// ITmfLocation<?> location;
+// synchronized (fCheckpoints) {
+// if (fCheckpoints.size() == 0)
+// location = null;
+// else {
+// if (index >= fCheckpoints.size())
+// index = fCheckpoints.size() - 1;
+// location = fCheckpoints.elementAt(index).getLocation();
+// }
+// }
+//
+// final TmfExperimentContext context = seekEvent(location);
+// context.setRank((long) index * fIndexPageSize);
+//
+// // And locate the event
+// ITmfEvent event = parseEvent(context);
+// long pos = context.getRank();
+// while ((event != null) && (pos++ < rank)) {
+// readNextEvent(context);
+// event = parseEvent(context);
+// }
+//
+// if (event == null) {
+// context.setLocation(null);
+// context.setRank(ITmfContext.UNKNOWN_RANK);
+// }
+//
+// return context;
+// }
+//
+// @Override
+// public TmfContext seekEvent(final double ratio) {
+// final TmfContext context = seekEvent((long) (ratio * getNbEvents()));
+// return context;
+// }
+//
+// @Override
+// public double getLocationRatio(final ITmfLocation<?> location) {
+// if (location instanceof TmfExperimentLocation)
+// return (double) seekEvent(location).getRank() / getNbEvents();
+// return 0;
+// }
+//
+// @Override
+// public ITmfLocation<?> getCurrentLocation() {
+// if (fExperimentContext != null)
+// return fExperimentContext.getLocation();
+// return null;
+// }
+//
+// // private void dumpContext(TmfExperimentContext context, boolean isBefore) {
+// // TmfContext context0 = context.getContexts()[0];
+// // TmfEvent event0 = context.getEvents()[0];
+// // TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation();
+// // long rank0 = context.getRank();
+// // int trace = context.getLastTrace();
+// //
+// // StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A "));
+// //
+// // result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] ");
+// // result.append("[Evt: " + event0.getTimestamp().toString() + "] ");
+// // result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] ");
+// // result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]");
+// // Tracer.trace(result.toString());
+// // }
+//
+// /**
+// * Scan the next events from all traces and return the next one in
+// * chronological order.
+// *
+// * @param context the trace context
+// * @return the next event
+// */
+// @Override
+// public synchronized ITmfEvent readNextEvent(final ITmfContext context) {
+//
+// // Validate the context
+// if (!(context instanceof TmfExperimentContext))
+// return null; // Throw an exception?
+//
+// if (!context.equals(fExperimentContext))
+// // Tracer.trace("Ctx: Restoring context");
+// fExperimentContext = seekEvent(context.getLocation());
+//
+// final TmfExperimentContext expContext = (TmfExperimentContext) context;
+//
+// // dumpContext(expContext, true);
+//
+// // If an event was consumed previously, get the next one from that trace
+// final int lastTrace = expContext.getLastTrace();
+// if (lastTrace != TmfExperimentContext.NO_TRACE) {
+// final ITmfContext traceContext = expContext.getContexts()[lastTrace];
+// expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].readNextEvent(traceContext);
+// expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
+// }
+//
+// // Scan the candidate events and identify the "next" trace to read from
+// final ITmfEvent eventArray[] = expContext.getEvents();
+// if (eventArray == null)
+// return null;
+// int trace = TmfExperimentContext.NO_TRACE;
+// ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
+// if (eventArray.length == 1) {
+// if (eventArray[0] != null) {
+// timestamp = eventArray[0].getTimestamp();
+// trace = 0;
+// }
+// } else
+// for (int i = 0; i < eventArray.length; i++) {
+// final ITmfEvent event = eventArray[i];
+// if (event != null && event.getTimestamp() != null) {
+// final ITmfTimestamp otherTS = event.getTimestamp();
+// if (otherTS.compareTo(timestamp, true) < 0) {
+// trace = i;
+// timestamp = otherTS;
+// }
+// }
+// }
+// // Update the experiment context and set the "next" event
+// ITmfEvent event = null;
+// if (trace != TmfExperimentContext.NO_TRACE) {
+// updateIndex(expContext, timestamp);
+//
+// final ITmfContext traceContext = expContext.getContexts()[trace];
+// final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
+// // expLocation.getLocation()[trace] = traceContext.getLocation().clone();
+// expLocation.getLocation().locations[trace] = traceContext.getLocation().clone();
+//
+// // updateIndex(expContext, timestamp);
+//
+// expLocation.getRanks()[trace] = traceContext.getRank();
+// expContext.setLastTrace(trace);
+// expContext.increaseRank();
+// event = expContext.getEvents()[trace];
+// fExperimentContext = expContext;
+// }
+//
+// // if (event != null) {
+// // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
+// // dumpContext(expContext, false);
+// // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
+// // }
+//
+// return event;
+// }
+//
+// public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) {
+// // Build the index as we go along
+// final long rank = context.getRank();
+// if (context.hasValidRank() && (rank % fIndexPageSize) == 0) {
+// // Determine the table position
+// final long position = rank / fIndexPageSize;
+// // Add new entry at proper location (if empty)
+// if (fCheckpoints.size() == position) {
+// final ITmfLocation<?> location = context.getLocation().clone();
+// fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location));
+// // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", "
+// // + location.toString());
+// }
+// }
+// }
+//
+// /* (non-Javadoc)
+// * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext)
+// */
+//// @Override
+// public ITmfEvent parseEvent(final ITmfContext context) {
+//
+// // Validate the context
+// if (!(context instanceof TmfExperimentContext))
+// return null; // Throw an exception?
+//
+// if (!context.equals(fExperimentContext))
+// // Tracer.trace("Ctx: Restoring context");
+// seekEvent(context.getLocation());
+//
+// final TmfExperimentContext expContext = (TmfExperimentContext) context;
+//
+// // If an event was consumed previously, get the next one from that trace
+// final int lastTrace = expContext.getLastTrace();
+// if (lastTrace != TmfExperimentContext.NO_TRACE) {
+// final ITmfContext traceContext = expContext.getContexts()[lastTrace];
+// expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].readNextEvent(traceContext);
+// expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
+// fExperimentContext = (TmfExperimentContext) context;
+// }
+//
+// // Scan the candidate events and identify the "next" trace to read from
+// int trace = TmfExperimentContext.NO_TRACE;
+// ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
+// for (int i = 0; i < expContext.getTraces().length; i++) {
+// final ITmfEvent event = expContext.getEvents()[i];
+// if (event != null && event.getTimestamp() != null) {
+// final ITmfTimestamp otherTS = event.getTimestamp();
+// if (otherTS.compareTo(timestamp, true) < 0) {
+// trace = i;
+// timestamp = otherTS;
+// }
+// }
+// }
+//
+// ITmfEvent event = null;
+// if (trace != TmfExperimentContext.NO_TRACE)
+// event = expContext.getEvents()[trace];
+//
+// return event;
+// }
+//
+// /* (non-Javadoc)
+// * @see java.lang.Object#toString()
+// */
+// @Override
+// @SuppressWarnings("nls")
+// public String toString() {
+// return "[TmfExperiment (" + getName() + ")]";
+// }
+//
+// // ------------------------------------------------------------------------
+// // Indexing
+// // ------------------------------------------------------------------------
+//
+// private synchronized void initializeStreamingMonitor() {
+// if (fInitialized)
+// return;
+// fInitialized = true;
+//
+// if (getStreamingInterval() == 0) {
+// final TmfContext context = seekEvent(0);
+// final ITmfEvent event = getNext(context);
+// if (event == null)
+// return;
+// final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp().clone(), TmfTimestamp.BIG_CRUNCH);
+// final TmfExperimentRangeUpdatedSignal signal = new TmfExperimentRangeUpdatedSignal(this, this, timeRange);
+//
+// // Broadcast in separate thread to prevent deadlock
+// new Thread() {
+// @Override
+// public void run() {
+// broadcast(signal);
+// }
+// }.start();
+// return;
+// }
+//
+// final Thread thread = new Thread("Streaming Monitor for experiment " + getName()) { ////$NON-NLS-1$
+// private ITmfTimestamp safeTimestamp = null;
+// private TmfTimeRange timeRange = null;
+//
+// @Override
+// public void run() {
+// while (!fExecutor.isShutdown()) {
+// if (!isIndexingBusy()) {
+// ITmfTimestamp startTimestamp = TmfTimestamp.BIG_CRUNCH;
+// ITmfTimestamp endTimestamp = TmfTimestamp.BIG_BANG;
+// for (final ITmfTrace<T> trace : fTraces) {
+// if (trace.getStartTime().compareTo(startTimestamp) < 0)
+// startTimestamp = trace.getStartTime();
+// if (trace.getStreamingInterval() != 0 && trace.getEndTime().compareTo(endTimestamp) > 0)
+// endTimestamp = trace.getEndTime();
+// }
+// if (safeTimestamp != null && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0)
+// timeRange = new TmfTimeRange(startTimestamp, safeTimestamp);
+// else
+// timeRange = null;
+// safeTimestamp = endTimestamp;
+// if (timeRange != null) {
+// final TmfExperimentRangeUpdatedSignal signal =
+// new TmfExperimentRangeUpdatedSignal(TmfExperiment.this, TmfExperiment.this, timeRange);
+// broadcast(signal);
+// }
+// }
+// try {
+// Thread.sleep(getStreamingInterval());
+// } catch (final InterruptedException e) {
+// e.printStackTrace();
+// }
+// }
+// }
+// };
+// thread.start();
+// }
+//
+// /*
+// * (non-Javadoc)
+// *
+// * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getStreamingInterval()
+// */
+// @Override
+// public long getStreamingInterval() {
+// long interval = 0;
+// for (final ITmfTrace<T> trace : fTraces)
+// interval = Math.max(interval, trace.getStreamingInterval());
+// return interval;
+// }
+//
+// /*
+// * The experiment holds the globally ordered events of its set of traces. It
+// * is expected to provide access to each individual event by index i.e. it
+// * must be possible to request the Nth event of the experiment.
+// *
+// * The purpose of the index is to keep the information needed to rapidly
+// * restore the traces contexts at regular intervals (every INDEX_PAGE_SIZE
+// * event).
+// */
+//
+// // The index page size
+// private static final int DEFAULT_INDEX_PAGE_SIZE = 5000;
+// protected int fIndexPageSize;
+// protected boolean fIndexing = false;
+// protected TmfTimeRange fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
+//
+// private Integer fEndSynchReference;
+//
+// // private static BufferedWriter fEventLog = null;
+// // private static BufferedWriter openLogFile(String filename) {
+// // BufferedWriter outfile = null;
+// // try {
+// // outfile = new BufferedWriter(new FileWriter(filename));
+// // } catch (IOException e) {
+// // e.printStackTrace();
+// // }
+// // return outfile;
+// // }
+//
+// protected boolean isIndexingBusy() {
+// synchronized (fCheckpoints) {
+// return fIndexing;
+// }
+// }
+//
+// @SuppressWarnings("unchecked")
+// private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) {
+//
+// synchronized (fCheckpoints) {
+// if (fIndexing)
+// return;
+// fIndexing = true;
+// }
+//
+// final Job job = new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
+//
+// @Override
+// protected IStatus run(final IProgressMonitor monitor) {
+// while (!monitor.isCanceled())
+// try {
+// Thread.sleep(100);
+// } catch (final InterruptedException e) {
+// return Status.OK_STATUS;
+// }
+// monitor.done();
+// return Status.OK_STATUS;
+// }
+// };
+// job.schedule();
+//
+// // fEventLog = openLogFile("TraceEvent.log");
+// // System.out.println(System.currentTimeMillis() + ": Experiment indexing started");
+//
+// final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, timeRange, index,
+// TmfDataRequest.ALL_DATA,
+// fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA
+// // FOREGROUND
+//
+// // long indexingStart = System.nanoTime();
+//
+// ITmfTimestamp startTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getStartTime();
+// ITmfTimestamp lastTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getEndTime();
+// long initialNbEvents = fNbEvents;
+//
+// @Override
+// public void handleStarted() {
+// super.handleStarted();
+// }
+//
+// @Override
+// public void handleData(final ITmfEvent event) {
+// super.handleData(event);
+// if (event != null) {
+// final ITmfTimestamp ts = event.getTimestamp();
+// if (startTime == null)
+// startTime = ts.clone();
+// lastTime = ts.clone();
+// }
+// if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1)
+// updateExperiment();
+// }
+//
+// @Override
+// public void handleSuccess() {
+// // long indexingEnd = System.nanoTime();
+//
+// // if the end time is a real value then it is the streaming safe
+// // time stamp
+// // set the last time to the safe time stamp to prevent
+// // unnecessary indexing requests
+// if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH)
+// lastTime = getRange().getEndTime();
+// updateExperiment();
+// // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed");
+//
+// // long average = (indexingEnd - indexingStart) / fNbEvents;
+// // System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed="
+// // + (indexingEnd * 1.0 - indexingStart) / 1000000000);
+// // System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "."
+// // + (average % 1000) + " us/evt)");
+// super.handleSuccess();
+// }
+//
+// @Override
+// public void handleCompleted() {
+// job.cancel();
+// super.handleCompleted();
+// synchronized (fCheckpoints) {
+// fIndexing = false;
+// if (fIndexingPendingRange != TmfTimeRange.NULL_RANGE) {
+// indexExperiment(false, (int) fNbEvents, fIndexingPendingRange);
+// fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
+// }
+// }
+// }
+//
+// private void updateExperiment() {
+// final int nbRead = getNbRead();
+// if (startTime != null)
+// fTimeRange = new TmfTimeRange(startTime, lastTime.clone());
+// if (nbRead != 0) {
+// // updateTimeRange();
+// // updateNbEvents();
+// fNbEvents = initialNbEvents + nbRead;
+// notifyListeners();
+// }
+// }
+// };
+//
+// sendRequest((ITmfDataRequest<T>) request);
+// if (waitForCompletion)
+// try {
+// request.waitForCompletion();
+// } catch (final InterruptedException e) {
+// e.printStackTrace();
+// }
+// }
+//
+// protected void notifyListeners() {
+// broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null));
+// // broadcast(new TmfExperimentRangeUpdatedSignal(this, this,
+// // fTimeRange)); // , null));
+// }
+//
+// // ------------------------------------------------------------------------
+// // Signal handlers
+// // ------------------------------------------------------------------------
+//
+// @TmfSignalHandler
+// public void experimentSelected(final TmfExperimentSelectedSignal<T> signal) {
+// final TmfExperiment<?> experiment = signal.getExperiment();
+// if (experiment == this) {
+// setCurrentExperiment(experiment);
+// fEndSynchReference = Integer.valueOf(signal.getReference());
+// }
+// }
+//
+// @TmfSignalHandler
+// public void endSync(final TmfEndSynchSignal signal) {
+// if (fEndSynchReference != null && fEndSynchReference.intValue() == signal.getReference()) {
+// fEndSynchReference = null;
+// initializeStreamingMonitor();
+// }
+// }
+//
+// @TmfSignalHandler
+// public void experimentUpdated(final TmfExperimentUpdatedSignal signal) {
+// }
+//
+// @TmfSignalHandler
+// public void experimentRangeUpdated(final TmfExperimentRangeUpdatedSignal signal) {
+// if (signal.getExperiment() == this)
+// indexExperiment(false, (int) fNbEvents, signal.getRange());
+// }
+//
+// @TmfSignalHandler
+// public void traceUpdated(final TmfTraceUpdatedSignal signal) {
+// for (final ITmfTrace<T> trace : fTraces)
+// if (trace == signal.getTrace()) {
+// synchronized (fCheckpoints) {
+// if (fIndexing) {
+// if (fIndexingPendingRange == TmfTimeRange.NULL_RANGE)
+// fIndexingPendingRange = signal.getRange();
+// else {
+// ITmfTimestamp startTime = fIndexingPendingRange.getStartTime();
+// ITmfTimestamp endTime = fIndexingPendingRange.getEndTime();
+// if (signal.getRange().getStartTime().compareTo(startTime) < 0)
+// startTime = signal.getRange().getStartTime();
+// if (signal.getRange().getEndTime().compareTo(endTime) > 0)
+// endTime = signal.getRange().getEndTime();
+// fIndexingPendingRange = new TmfTimeRange(startTime, endTime);
+// }
+// return;
+// }
+// }
+// indexExperiment(false, (int) fNbEvents, signal.getRange());
+// return;
+// }
+// }
+//
+// @Override
+// public String getPath() {
+// // TODO Auto-generated method stub
+// return null;
+// }
+//
+// /**
+// * Set the file to be used for bookmarks on this experiment
+// *
+// * @param file the bookmarks file
+// */
+// public void setBookmarksFile(final IFile file) {
+// fBookmarksFile = file;
+// }
+//
+// /**
+// * Get the file used for bookmarks on this experiment
+// *
+// * @return the bookmarks file or null if none is set
+// */
+// public IFile getBookmarksFile() {
+// return fBookmarksFile;
+// }
+//
+// /*
+// * (non-Javadoc)
+// *
+// * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
+// */
+// @Override
+// public IResource getResource() {
+// return fResource;
+// }
+//}
/*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009, 2010, 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
*
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Put in shape for 1.0
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.experiment;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
/**
- * <b><u>TmfExperimentContext</u></b>
+ * The experiment context in TMF.
* <p>
* The experiment keeps track of the next event from each of its traces so it
* can pick the next one in chronological order.
* <p>
* This implies that the "next" event from each trace has already been
* read and that we at least know its timestamp. This doesn't imply that a
- * full parse of the event content was performed (read: LTTng works like
- * this).
+ * full parse of the event content was performed (read: the legacy LTTng works
+ * like this...).
* <p>
* The last trace refers to the trace from which the last event was "consumed"
* at the experiment level.
// Constants
// ------------------------------------------------------------------------
- public static final int NO_TRACE = -1;
+ /**
+ * No last trace read indicator
+ */
+ static final int NO_TRACE = -1;
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private ITmfTrace<?>[] fTraces = new ITmfTrace[0];
+// private ITmfTrace<?>[] fTraces = new ITmfTrace[0];
private final ITmfContext[] fContexts;
private ITmfEvent[] fEvents;
private int lastTraceRead;
// Constructors
// ------------------------------------------------------------------------
- public TmfExperimentContext(final ITmfTrace<?>[] traces, final ITmfContext[] contexts) {
+ public TmfExperimentContext(final ITmfContext[] contexts) {
super();
- fTraces = traces;
+// fTraces = traces;
fContexts = contexts;
- fEvents = new ITmfEvent[fTraces.length];
- final ITmfLocation<?>[] locations = new ITmfLocation[fTraces.length];
- final long[] ranks = new long[fTraces.length];
+ fEvents = new ITmfEvent[fContexts.length];
+ final ITmfLocation<?>[] locations = new ITmfLocation[fContexts.length];
+ final long[] ranks = new long[fContexts.length];
long rank = 0;
- for (int i = 0; i < fTraces.length; i++)
+ for (int i = 0; i < fContexts.length; i++)
if (contexts[i] != null) {
locations[i] = contexts[i].getLocation();
ranks[i] = contexts[i].getRank();
rank += contexts[i].getRank();
}
- setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks));
+ setLocation(new TmfExperimentLocation(new TmfLocationArray(locations)));
setRank(rank);
lastTraceRead = NO_TRACE;
}
public TmfExperimentContext(final TmfExperimentContext other) {
- this(other.fTraces, other.cloneContexts());
+ this(other.cloneContexts());
fEvents = other.fEvents;
if (other.getLocation() != null)
setLocation(other.getLocation().clone());
setLastTrace(other.lastTraceRead);
}
- public TmfExperimentContext(final ITmfTrace<?>[] traces) {
- this(traces, new TmfContext[traces.length]);
- }
+// public TmfExperimentContext(final ITmfTrace<?>[] traces) {
+// this(traces, new TmfContext[traces.length]);
+// }
private ITmfContext[] cloneContexts() {
final ITmfContext[] contexts = new ITmfContext[fContexts.length];
// Accessors
// ------------------------------------------------------------------------
- public ITmfTrace<?>[] getTraces() {
- return fTraces;
- }
+// public ITmfTrace<?>[] getTraces() {
+// return fTraces;
+// }
public ITmfContext[] getContexts() {
return fContexts;
@Override
public int hashCode() {
int result = 17;
- for (int i = 0; i < fTraces.length; i++) {
- result = 37 * result + fTraces[i].hashCode();
+ for (int i = 0; i < fContexts.length; i++) {
+// result = 37 * result + fTraces[i].hashCode();
result = 37 * result + fContexts[i].hashCode();
}
return result;
final TmfExperimentContext o = (TmfExperimentContext) other;
boolean isEqual = true;
int i = 0;
- while (isEqual && (i < fTraces.length)) {
- isEqual &= fTraces[i].equals(o.fTraces[i]);
+ while (isEqual && (i < fContexts.length)) {
+// isEqual &= fTraces[i].equals(o.fTraces[i]);
isEqual &= fContexts[i].equals(o.fContexts[i]);
i++;
}
/*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009, 2010, 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Updated as per TMF Trace Model 1.0
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.experiment;
-import java.util.Arrays;
-
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
/**
- * <b><u>TmfExperimentLocation</u></b>
+ * The experiment location in TMF.
+ * <p>
+ * An experiment location is actually the set of locations of the traces it
+ * contains. By setting the individual traces to their corresponding locations,
+ * the experiment can be positioned to read the next chronological event.
* <p>
- * The experiment location is the set of its traces' locations.
+ * It is the responsibility of the user the individual trace locations are valid
+ * and that they are matched to the correct trace.
+ *
+ * @version 1.0
+ * @author Francois Chouinard
+ *
+ * @see TmfLocationArray
*/
-public class TmfExperimentLocation extends TmfLocation<TmfLocationArray> {
+public class TmfExperimentLocation extends TmfLocation<TmfLocationArray> implements Cloneable {
- private long[] fRanks;
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
- public TmfExperimentLocation(TmfLocationArray locations, long[] ranks) {
- super(locations);
- fRanks = ranks;
- }
+ /**
+ * The standard constructor
+ *
+ * @param locations the set of trace locations
+ */
+ public TmfExperimentLocation(TmfLocationArray locations) {
+ super(locations);
+ }
- @Override
- public TmfExperimentLocation clone() {
- super.clone(); // To keep FindBugs happy
- TmfLocationArray array = (TmfLocationArray) getLocation();
- TmfLocationArray clones = array.clone();
- return new TmfExperimentLocation(clones, fRanks.clone());
- }
+ /**
+ * The copy constructor
+ *
+ * @param location the other experiment location
+ */
+ public TmfExperimentLocation(TmfExperimentLocation location) {
+ this(location.getLocation());
+ }
- @Override
- @SuppressWarnings("nls")
- public String toString() {
- StringBuilder result = new StringBuilder("[TmfExperimentLocation");
- TmfLocationArray array = (TmfLocationArray) getLocation();
- for (int i = 0; i < array.locations.length; i++) {
- result.append("[" + array.locations[i].toString() + "," + fRanks[i] + "]");
- }
- result.append("]");
- return result.toString();
- }
+ // ------------------------------------------------------------------------
+ // Cloneable
+ // ------------------------------------------------------------------------
- public long[] getRanks() {
- return fRanks;
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.TmfLocation#clone()
+ */
+ @Override
+ public TmfExperimentLocation clone() {
+// super.clone(); // To keep FindBugs happy
+ TmfLocationArray array = (TmfLocationArray) getLocation();
+ TmfLocationArray clones = array.clone();
+ return new TmfExperimentLocation(clones);
}
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.TmfLocation#toString()
+ */
+ @Override
+ @SuppressWarnings("nls")
+ public String toString() {
+ StringBuilder result = new StringBuilder("[TmfExperimentLocation");
+ ITmfLocation<? extends Comparable<?>>[] locations = ((TmfLocationArray) getLocation()).getLocations();
+ for (ITmfLocation<?> location : locations) {
+ result.append("[" + location.toString() + "]");
+ }
+ result.append("]");
+ return result.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.TmfLocation#hashCode()
+ */
@Override
public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(fRanks);
- return result;
+ return super.hashCode();
}
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.TmfLocation#equals(java.lang.Object)
+ */
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
+ }
+ if (!super.equals(obj)) {
return false;
- TmfExperimentLocation other = (TmfExperimentLocation) obj;
- if (!Arrays.equals(fRanks, other.fRanks))
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
return true;
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 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:
+ * Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.experiment;
+
+import java.util.Collections;
+import java.util.Vector;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+
+/**
+ * <b><u>TmfLegacyExperiment</u></b>
+ * <p>
+ * TmfExperiment presents a time-ordered, unified view of a set of TmfTraces
+ * that are part of a tracing experiment.
+ * <p>
+ */
+public class TmfLegacyExperiment<T extends ITmfEvent> extends TmfExperiment<T> {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+// // The currently selected experiment
+// protected static TmfExperiment<?> fCurrentExperiment = null;
+//
+// // The set of traces that constitute the experiment
+// protected ITmfTrace<T>[] fTraces;
+
+// // The total number of events
+// protected long fNbEvents;
+
+// // The experiment time range
+// protected TmfTimeRange fTimeRange;
+
+ // The experiment reference timestamp (default: ZERO)
+ protected ITmfTimestamp fEpoch;
+
+ // The experiment index
+ protected Vector<TmfCheckpoint> fCheckpoints;
+
+ // The current experiment context
+ protected TmfExperimentContext fExperimentContext;
+
+// // Flag to initialize only once
+// private boolean fInitialized = false;
+
+// // The experiment bookmarks file
+// private IFile fBookmarksFile;
+
+ // The properties resource
+ private IResource fResource;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ @Override
+ public TmfLegacyExperiment<T> clone() throws CloneNotSupportedException {
+ throw new CloneNotSupportedException();
+ }
+
+ @Override
+ public boolean validate(final IProject project, final String path) {
+ return true;
+ }
+
+ /**
+ * @param type
+ * @param id
+ * @param traces
+ * @param epoch
+ * @param indexPageSize
+ */
+ public TmfLegacyExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final ITmfTimestamp epoch,
+ final int indexPageSize)
+ {
+ this(type, id, traces, TmfTimestamp.ZERO, indexPageSize, false);
+ }
+
+ public TmfLegacyExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final ITmfTimestamp epoch,
+ final int indexPageSize, final boolean preIndexExperiment)
+ {
+ super(type, id, traces, epoch, indexPageSize, false);
+// fNbEvents = 0;
+ setTimeRange(TmfTimeRange.NULL_RANGE);
+ fEpoch = epoch;
+ fCheckpoints = new Vector<TmfCheckpoint>();
+ if (preIndexExperiment) {
+ indexExperiment(true, 0, TmfTimeRange.ETERNITY);
+ }
+ }
+
+// protected TmfLegacyExperiment(final String id, final Class<T> type) {
+// super(id, type);
+// }
+
+ /**
+ * @param type
+ * @param id
+ * @param traces
+ */
+ public TmfLegacyExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces) {
+ this(type, id, traces, TmfTimestamp.ZERO, DEFAULT_INDEX_PAGE_SIZE);
+ }
+
+ /**
+ * @param type
+ * @param id
+ * @param traces
+ * @param indexPageSize
+ */
+ public TmfLegacyExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final int indexPageSize) {
+ this(type, id, traces, TmfTimestamp.ZERO, indexPageSize);
+ }
+
+ /**
+ * Clears the experiment
+ */
+ @Override
+ @SuppressWarnings( "rawtypes" )
+ public synchronized void dispose() {
+
+ final TmfExperimentDisposedSignal<T> signal = new TmfExperimentDisposedSignal<T>(this, this);
+ broadcast(signal);
+ if (fCurrentExperiment == this)
+ fCurrentExperiment = null;
+
+ if (fTraces != null) {
+ for (final ITmfTrace trace : fTraces)
+ trace.dispose();
+ fTraces = null;
+ }
+ if (fCheckpoints != null)
+ fCheckpoints.clear();
+ super.dispose();
+ }
+
+ // ------------------------------------------------------------------------
+ // ITmfTrace
+ // ------------------------------------------------------------------------
+
+// @Override
+// public Class<T> getEventType() {
+// return fType;
+// }
+//
+// @Override
+// public long getNbEvents() {
+// return fNbEvents;
+// }
+//
+// @Override
+// public int getCacheSize() {
+// return fIndexPageSize;
+// }
+//
+// @Override
+// public TmfTimeRange getTimeRange() {
+// return fTimeRange;
+// }
+//
+// @Override
+// public ITmfTimestamp getStartTime() {
+// return fTimeRange.getStartTime();
+// }
+//
+// @Override
+// public ITmfTimestamp getEndTime() {
+// return fTimeRange.getEndTime();
+// }
+
+// public Vector<TmfCheckpoint> getCheckpoints() {
+// return fCheckpoints;
+// }
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+
+// public static void setCurrentExperiment(final TmfExperiment<?> experiment) {
+// if (fCurrentExperiment != null && fCurrentExperiment != experiment)
+// fCurrentExperiment.dispose();
+// fCurrentExperiment = experiment;
+// }
+//
+// public static TmfExperiment<?> getCurrentExperiment() {
+// return fCurrentExperiment;
+// }
+
+ public ITmfTimestamp getEpoch() {
+ return fEpoch;
+ }
+
+ @Override
+ public ITmfTrace<T>[] getTraces() {
+ return fTraces;
+ }
+
+ /**
+ * Returns the timestamp of the event at the requested index. If none,
+ * returns null.
+ *
+ * @param index the event index (rank)
+ * @return the corresponding event timestamp
+ */
+ @Override
+ public ITmfTimestamp getTimestamp(final int index) {
+ final TmfExperimentContext context = seekEvent(index);
+ final ITmfEvent event = getNext(context);
+ return (event != null) ? event.getTimestamp() : null;
+ }
+
+ // ------------------------------------------------------------------------
+ // Operators
+ // ------------------------------------------------------------------------
+
+ /**
+ * Update the global time range
+ */
+ protected void updateTimeRange() {
+ ITmfTimestamp startTime = getStartTime();
+ ITmfTimestamp endTime = getEndTime();
+
+ for (final ITmfTrace<T> trace : fTraces) {
+ final ITmfTimestamp traceStartTime = trace.getStartTime();
+ if (traceStartTime.compareTo(startTime, true) < 0)
+ startTime = traceStartTime;
+ final ITmfTimestamp traceEndTime = trace.getEndTime();
+ if (traceEndTime.compareTo(endTime, true) > 0)
+ endTime = traceEndTime;
+ }
+ setTimeRange(new TmfTimeRange(startTime, endTime));
+ }
+
+ // ------------------------------------------------------------------------
+ // TmfProvider
+ // ------------------------------------------------------------------------
+
+ @Override
+ public ITmfContext armRequest(final ITmfDataRequest<T> request) {
+ // Tracer.trace("Ctx: Arming request - start");
+ ITmfTimestamp timestamp = (request instanceof ITmfEventRequest<?>) ? ((ITmfEventRequest<T>) request).getRange().getStartTime() : null;
+ if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0)
+ timestamp = null; // use request index
+ TmfExperimentContext context = null;
+ if (timestamp != null) {
+ // seek by timestamp
+ context = seekEvent(timestamp);
+ ((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank());
+ } else // Seek by rank
+ if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex())
+ // We are already at the right context -> no need to seek
+ context = fExperimentContext;
+ else
+ context = seekEvent(request.getIndex());
+ // Tracer.trace("Ctx: Arming request - done");
+ return context;
+ }
+
+// @Override
+// @SuppressWarnings("unchecked")
+// public T getNext(final ITmfContext context) {
+// if (context instanceof TmfExperimentContext)
+// return (T) readNextEvent(context);
+// return null;
+// }
+
+ // ------------------------------------------------------------------------
+ // ITmfTrace trace positioning
+ // ------------------------------------------------------------------------
+
+ // Returns a brand new context based on the location provided
+ // and initializes the event queues
+ @Override
+ public synchronized TmfExperimentContext seekEvent(final ITmfLocation<?> location) {
+ // Validate the location
+ if (location != null && !(location instanceof TmfExperimentLocation))
+ return null; // Throw an exception?
+
+ if (fTraces == null)
+ return null;
+
+ // Instantiate the location
+ final TmfExperimentLocation expLocation = (location == null) ? new TmfExperimentLocation(new TmfLocationArray(
+ new ITmfLocation<?>[fTraces.length])) : (TmfExperimentLocation) location.clone();
+
+ // Create and populate the context's traces contexts
+ final TmfExperimentContext context = new TmfExperimentContext(new ITmfContext[fTraces.length]);
+ // Tracer.trace("Ctx: SeekLocation - start");
+
+// long rank = 0;
+ for (int i = 0; i < fTraces.length; i++) {
+ // Get the relevant trace attributes
+ final ITmfLocation<?> traceLocation = expLocation.getLocation().getLocations()[i];
+// final long traceRank = expLocation.getRanks()[i];
+
+ // Set the corresponding sub-context
+ context.getContexts()[i] = fTraces[i].seekEvent(traceLocation);
+// context.getContexts()[i].setRank(traceRank);
+// rank += traceRank;
+
+ // Set the trace location and read the corresponding event
+ /*
+ * The (TmfContext) cast should be safe since we created 'context'
+ * ourselves higher up.
+ */
+ expLocation.getLocation().getLocations()[i] = context.getContexts()[i].getLocation().clone();
+ context.getEvents()[i] = fTraces[i].getNext(context.getContexts()[i]);
+ }
+
+ // Tracer.trace("Ctx: SeekLocation - done");
+
+ // Finalize context
+ context.setLocation(expLocation);
+ context.setLastTrace(TmfExperimentContext.NO_TRACE);
+// context.setRank(rank);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+
+ fExperimentContext = context;
+
+ return context;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp)
+ */
+ @Override
+ public synchronized TmfExperimentContext seekEvent(ITmfTimestamp timestamp) {
+
+ // Tracer.trace("Ctx: seekEvent(TS) - start");
+
+ if (timestamp == null)
+ timestamp = TmfTimestamp.BIG_BANG;
+
+ // First, find the right checkpoint
+ int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null));
+
+ // In the very likely case that the checkpoint was not found, bsearch
+ // returns its negated would-be location (not an offset...). From that
+ // index, we can then position the stream and get the event.
+ if (index < 0)
+ index = Math.max(0, -(index + 2));
+
+ // Position the experiment at the checkpoint
+ ITmfLocation<?> location;
+ synchronized (fCheckpoints) {
+ if (fCheckpoints.size() > 0) {
+ if (index >= fCheckpoints.size())
+ index = fCheckpoints.size() - 1;
+ location = fCheckpoints.elementAt(index).getLocation();
+ } else
+ location = null;
+ }
+
+ final TmfExperimentContext context = seekEvent(location);
+ context.setRank((long) index * getCacheSize());
+
+ // And locate the event
+ ITmfEvent event = parseEvent(context);
+ while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) {
+ getNext(context);
+ event = parseEvent(context);
+ }
+
+ if (event == null) {
+ context.setLocation(null);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+ }
+
+ return context;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long)
+ */
+ @Override
+ public synchronized TmfExperimentContext seekEvent(final long rank) {
+
+ // Tracer.trace("Ctx: seekEvent(rank) - start");
+
+ // Position the stream at the previous checkpoint
+ int fIndexPageSize = getCacheSize();
+ int index = (int) rank / fIndexPageSize;
+ ITmfLocation<?> location;
+ synchronized (fCheckpoints) {
+ if (fCheckpoints.size() == 0)
+ location = null;
+ else {
+ if (index >= fCheckpoints.size())
+ index = fCheckpoints.size() - 1;
+ location = fCheckpoints.elementAt(index).getLocation();
+ }
+ }
+
+ final TmfExperimentContext context = seekEvent(location);
+ context.setRank((long) index * fIndexPageSize);
+
+ // And locate the event
+ ITmfEvent event = parseEvent(context);
+ long pos = context.getRank();
+ while ((event != null) && (pos++ < rank)) {
+ getNext(context);
+ event = parseEvent(context);
+ }
+
+ if (event == null) {
+ context.setLocation(null);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+ }
+
+ return context;
+ }
+
+ @Override
+ public TmfContext seekEvent(final double ratio) {
+ final TmfContext context = seekEvent((long) (ratio * getNbEvents()));
+ return context;
+ }
+
+ @Override
+ public double getLocationRatio(final ITmfLocation<?> location) {
+ if (location instanceof TmfExperimentLocation)
+ return (double) seekEvent(location).getRank() / getNbEvents();
+ return 0;
+ }
+
+ @Override
+ public ITmfLocation<?> getCurrentLocation() {
+ if (fExperimentContext != null)
+ return fExperimentContext.getLocation();
+ return null;
+ }
+
+ // private void dumpContext(TmfExperimentContext context, boolean isBefore) {
+ // TmfContext context0 = context.getContexts()[0];
+ // TmfEvent event0 = context.getEvents()[0];
+ // TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation();
+ // long rank0 = context.getRank();
+ // int trace = context.getLastTrace();
+ //
+ // StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A "));
+ //
+ // result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] ");
+ // result.append("[Evt: " + event0.getTimestamp().toString() + "] ");
+ // result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] ");
+ // result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]");
+ // Tracer.trace(result.toString());
+ // }
+
+ /**
+ * Scan the next events from all traces and return the next one in
+ * chronological order.
+ *
+ * @param context the trace context
+ * @return the next event
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized T getNext(final ITmfContext context) {
+
+ // Validate the context
+ if (!(context instanceof TmfExperimentContext))
+ return null; // Throw an exception?
+
+ if (!context.equals(fExperimentContext))
+ // Tracer.trace("Ctx: Restoring context");
+ fExperimentContext = seekEvent(context.getLocation());
+
+ final TmfExperimentContext expContext = (TmfExperimentContext) context;
+
+ // dumpContext(expContext, true);
+
+ // If an event was consumed previously, get the next one from that trace
+ final int lastTrace = expContext.getLastTrace();
+ if (lastTrace != TmfExperimentContext.NO_TRACE) {
+ final ITmfContext traceContext = expContext.getContexts()[lastTrace];
+ expContext.getEvents()[lastTrace] = fTraces[lastTrace].getNext(traceContext);
+ expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
+ }
+
+ // Scan the candidate events and identify the "next" trace to read from
+ final ITmfEvent eventArray[] = expContext.getEvents();
+ if (eventArray == null)
+ return null;
+ int trace = TmfExperimentContext.NO_TRACE;
+ ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
+ if (eventArray.length == 1) {
+ if (eventArray[0] != null) {
+ timestamp = eventArray[0].getTimestamp();
+ trace = 0;
+ }
+ } else
+ for (int i = 0; i < eventArray.length; i++) {
+ final ITmfEvent event = eventArray[i];
+ if (event != null && event.getTimestamp() != null) {
+ final ITmfTimestamp otherTS = event.getTimestamp();
+ if (otherTS.compareTo(timestamp, true) < 0) {
+ trace = i;
+ timestamp = otherTS;
+ }
+ }
+ }
+ // Update the experiment context and set the "next" event
+ T event = null;
+ if (trace != TmfExperimentContext.NO_TRACE) {
+ updateIndex(expContext, timestamp);
+
+ final ITmfContext traceContext = expContext.getContexts()[trace];
+ final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
+ // expLocation.getLocation()[trace] = traceContext.getLocation().clone();
+ expLocation.getLocation().getLocations()[trace] = traceContext.getLocation().clone();
+
+ // updateIndex(expContext, timestamp);
+
+// expLocation.getRanks()[trace] = traceContext.getRank();
+ expContext.setLastTrace(trace);
+ expContext.increaseRank();
+ event = (T) expContext.getEvents()[trace];
+ fExperimentContext = expContext;
+ }
+
+ // if (event != null) {
+ // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
+ // dumpContext(expContext, false);
+ // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
+ // }
+
+ return event;
+ }
+
+ public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) {
+ // Build the index as we go along
+ final long rank = context.getRank();
+ if (context.hasValidRank() && (rank % getCacheSize()) == 0) {
+ // Determine the table position
+ final long position = rank / getCacheSize();
+ // Add new entry at proper location (if empty)
+ if (fCheckpoints.size() == position) {
+ final ITmfLocation<?> location = context.getLocation().clone();
+ fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location));
+ // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", "
+ // + location.toString());
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public T parseEvent(final ITmfContext context) {
+
+ // Validate the context
+ if (!(context instanceof TmfExperimentContext))
+ return null; // Throw an exception?
+
+ if (!context.equals(fExperimentContext))
+ // Tracer.trace("Ctx: Restoring context");
+ seekEvent(context.getLocation());
+
+ final TmfExperimentContext expContext = (TmfExperimentContext) context;
+
+ // If an event was consumed previously, get the next one from that trace
+ final int lastTrace = expContext.getLastTrace();
+ if (lastTrace != TmfExperimentContext.NO_TRACE) {
+ final ITmfContext traceContext = expContext.getContexts()[lastTrace];
+ expContext.getEvents()[lastTrace] = fTraces[lastTrace].getNext(traceContext);
+ expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
+ fExperimentContext = (TmfExperimentContext) context;
+ }
+
+ // Scan the candidate events and identify the "next" trace to read from
+ int trace = TmfExperimentContext.NO_TRACE;
+ ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
+ for (int i = 0; i < fTraces.length; i++) {
+ final ITmfEvent event = expContext.getEvents()[i];
+ if (event != null && event.getTimestamp() != null) {
+ final ITmfTimestamp otherTS = event.getTimestamp();
+ if (otherTS.compareTo(timestamp, true) < 0) {
+ trace = i;
+ timestamp = otherTS;
+ }
+ }
+ }
+
+ T event = null;
+ if (trace != TmfExperimentContext.NO_TRACE)
+ event = (T) expContext.getEvents()[trace];
+
+ return event;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ @SuppressWarnings("nls")
+ public String toString() {
+ return "[TmfExperiment (" + getName() + ")]";
+ }
+
+ // ------------------------------------------------------------------------
+ // Indexing
+ // ------------------------------------------------------------------------
+
+// private synchronized void initializeStreamingMonitor() {
+// if (fInitialized)
+// return;
+// fInitialized = true;
+//
+// if (getStreamingInterval() == 0) {
+// final TmfContext context = seekEvent(0);
+// final ITmfEvent event = getNext(context);
+// if (event == null)
+// return;
+// final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp().clone(), TmfTimestamp.BIG_CRUNCH);
+// final TmfExperimentRangeUpdatedSignal signal = new TmfExperimentRangeUpdatedSignal(this, this, timeRange);
+//
+// // Broadcast in separate thread to prevent deadlock
+// new Thread() {
+// @Override
+// public void run() {
+// broadcast(signal);
+// }
+// }.start();
+// return;
+// }
+//
+// final Thread thread = new Thread("Streaming Monitor for experiment " + getName()) { ////$NON-NLS-1$
+// private ITmfTimestamp safeTimestamp = null;
+// private TmfTimeRange timeRange = null;
+//
+// @Override
+// public void run() {
+// while (!fExecutor.isShutdown()) {
+// if (!isIndexingBusy()) {
+// ITmfTimestamp startTimestamp = TmfTimestamp.BIG_CRUNCH;
+// ITmfTimestamp endTimestamp = TmfTimestamp.BIG_BANG;
+// for (final ITmfTrace<T> trace : fTraces) {
+// if (trace.getStartTime().compareTo(startTimestamp) < 0)
+// startTimestamp = trace.getStartTime();
+// if (trace.getStreamingInterval() != 0 && trace.getEndTime().compareTo(endTimestamp) > 0)
+// endTimestamp = trace.getEndTime();
+// }
+// if (safeTimestamp != null && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0)
+// timeRange = new TmfTimeRange(startTimestamp, safeTimestamp);
+// else
+// timeRange = null;
+// safeTimestamp = endTimestamp;
+// if (timeRange != null) {
+// final TmfExperimentRangeUpdatedSignal signal =
+// new TmfExperimentRangeUpdatedSignal(TmfLegacyExperiment.this, TmfLegacyExperiment.this, timeRange);
+// broadcast(signal);
+// }
+// }
+// try {
+// Thread.sleep(getStreamingInterval());
+// } catch (final InterruptedException e) {
+// e.printStackTrace();
+// }
+// }
+// }
+// };
+// thread.start();
+// }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getStreamingInterval()
+ */
+ @Override
+ public long getStreamingInterval() {
+ long interval = 0;
+ for (final ITmfTrace<T> trace : fTraces)
+ interval = Math.max(interval, trace.getStreamingInterval());
+ return interval;
+ }
+
+ /*
+ * The experiment holds the globally ordered events of its set of traces. It
+ * is expected to provide access to each individual event by index i.e. it
+ * must be possible to request the Nth event of the experiment.
+ *
+ * The purpose of the index is to keep the information needed to rapidly
+ * restore the traces contexts at regular intervals (every INDEX_PAGE_SIZE
+ * event).
+ */
+
+ // The index page size
+ private static final int DEFAULT_INDEX_PAGE_SIZE = 5000;
+// protected int fIndexPageSize;
+ protected boolean fIndexing = false;
+ protected TmfTimeRange fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
+
+// private Integer fEndSynchReference;
+
+ // private static BufferedWriter fEventLog = null;
+ // private static BufferedWriter openLogFile(String filename) {
+ // BufferedWriter outfile = null;
+ // try {
+ // outfile = new BufferedWriter(new FileWriter(filename));
+ // } catch (IOException e) {
+ // e.printStackTrace();
+ // }
+ // return outfile;
+ // }
+
+// protected boolean isIndexingBusy() {
+// synchronized (fCheckpoints) {
+// return fIndexing;
+// }
+// }
+
+ @SuppressWarnings("unchecked")
+ private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) {
+
+ synchronized (fCheckpoints) {
+ if (fIndexing)
+ return;
+ fIndexing = true;
+ }
+
+ final Job job = new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
+
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+ while (!monitor.isCanceled())
+ try {
+ Thread.sleep(100);
+ } catch (final InterruptedException e) {
+ return Status.OK_STATUS;
+ }
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+ };
+ job.schedule();
+
+ // fEventLog = openLogFile("TraceEvent.log");
+ // System.out.println(System.currentTimeMillis() + ": Experiment indexing started");
+
+ final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, timeRange, index,
+ TmfDataRequest.ALL_DATA,
+ getCacheSize(), ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA
+ // FOREGROUND
+
+ // long indexingStart = System.nanoTime();
+
+ ITmfTimestamp startTime = (getTimeRange().equals(TmfTimeRange.NULL_RANGE)) ? null : getStartTime();
+ ITmfTimestamp lastTime = (getTimeRange().equals(TmfTimeRange.NULL_RANGE)) ? null : getEndTime();
+ long initialNbEvents = getNbEvents();
+
+ @Override
+ public void handleStarted() {
+ super.handleStarted();
+ }
+
+ @Override
+ public void handleData(final ITmfEvent event) {
+ super.handleData(event);
+ if (event != null) {
+ final ITmfTimestamp ts = event.getTimestamp();
+ if (startTime == null)
+ startTime = ts.clone();
+ lastTime = ts.clone();
+ }
+ if ((getNbRead() % getCacheSize()) == 1 && getNbRead() != 1)
+ updateExperiment();
+ }
+
+ @Override
+ public void handleSuccess() {
+ // long indexingEnd = System.nanoTime();
+
+ // if the end time is a real value then it is the streaming safe
+ // time stamp
+ // set the last time to the safe time stamp to prevent
+ // unnecessary indexing requests
+ if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH)
+ lastTime = getRange().getEndTime();
+ updateExperiment();
+ // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed");
+
+ // long average = (indexingEnd - indexingStart) / fNbEvents;
+ // System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed="
+ // + (indexingEnd * 1.0 - indexingStart) / 1000000000);
+ // System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "."
+ // + (average % 1000) + " us/evt)");
+ super.handleSuccess();
+ }
+
+ @Override
+ public void handleCompleted() {
+ job.cancel();
+ super.handleCompleted();
+ synchronized (fCheckpoints) {
+ fIndexing = false;
+ if (!(fIndexingPendingRange.equals(TmfTimeRange.NULL_RANGE))) {
+ indexExperiment(false, (int) getNbEvents(), fIndexingPendingRange);
+ fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
+ }
+ }
+ }
+
+ private void updateExperiment() {
+ final int nbRead = getNbRead();
+ if (startTime != null) {
+ setTimeRange(new TmfTimeRange(startTime, lastTime.clone()));
+ }
+ if (nbRead != 0) {
+ // updateTimeRange();
+ // updateNbEvents();
+ setNbEvents(initialNbEvents + nbRead);
+ notifyListeners();
+ }
+ }
+ };
+
+ sendRequest((ITmfDataRequest<T>) request);
+ if (waitForCompletion)
+ try {
+ request.waitForCompletion();
+ } catch (final InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected void notifyListeners() {
+ broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null));
+ // broadcast(new TmfExperimentRangeUpdatedSignal(this, this,
+ // fTimeRange)); // , null));
+ }
+
+ // ------------------------------------------------------------------------
+ // Signal handlers
+ // ------------------------------------------------------------------------
+
+// @TmfSignalHandler
+// public void experimentSelected(final TmfExperimentSelectedSignal<T> signal) {
+// final TmfExperiment<?> experiment = signal.getExperiment();
+// if (experiment == this) {
+// setCurrentExperiment(experiment);
+// fEndSynchReference = Integer.valueOf(signal.getReference());
+// }
+// }
+//
+// @TmfSignalHandler
+// public void endSync(final TmfEndSynchSignal signal) {
+// if (fEndSynchReference != null && fEndSynchReference.intValue() == signal.getReference()) {
+// fEndSynchReference = null;
+// initializeStreamingMonitor();
+// }
+// }
+//
+// @TmfSignalHandler
+// public void experimentUpdated(final TmfExperimentUpdatedSignal signal) {
+// }
+//
+ @Override
+ @TmfSignalHandler
+ public void experimentRangeUpdated(final TmfExperimentRangeUpdatedSignal signal) {
+ if (signal.getExperiment() == this)
+ indexExperiment(false, (int) getNbEvents(), signal.getRange());
+ }
+
+ @Override
+ @TmfSignalHandler
+ public void traceUpdated(final TmfTraceUpdatedSignal signal) {
+ for (final ITmfTrace<T> trace : fTraces)
+ if (trace == signal.getTrace()) {
+ synchronized (fCheckpoints) {
+ if (fIndexing) {
+ if (fIndexingPendingRange.equals(TmfTimeRange.NULL_RANGE))
+ fIndexingPendingRange = signal.getRange();
+ else {
+ ITmfTimestamp startTime = fIndexingPendingRange.getStartTime();
+ ITmfTimestamp endTime = fIndexingPendingRange.getEndTime();
+ if (signal.getRange().getStartTime().compareTo(startTime) < 0)
+ startTime = signal.getRange().getStartTime();
+ if (signal.getRange().getEndTime().compareTo(endTime) > 0)
+ endTime = signal.getRange().getEndTime();
+ fIndexingPendingRange = new TmfTimeRange(startTime, endTime);
+ }
+ return;
+ }
+ }
+ indexExperiment(false, (int) getNbEvents(), signal.getRange());
+ return;
+ }
+ }
+
+ @Override
+ public String getPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+// /**
+// * Set the file to be used for bookmarks on this experiment
+// *
+// * @param file the bookmarks file
+// */
+// public void setBookmarksFile(final IFile file) {
+// fBookmarksFile = file;
+// }
+//
+// /**
+// * Get the file used for bookmarks on this experiment
+// *
+// * @return the bookmarks file or null if none is set
+// */
+// public IFile getBookmarksFile() {
+// return fBookmarksFile;
+// }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
+ */
+ @Override
+ public IResource getResource() {
+ return fResource;
+ }
+}
/*******************************************************************************
- * Copyright (c) 2011 Ericsson
+ * Copyright (c) 2011, 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Patrick Tasse - Initial API and implementation
+ * Patrick Tasse - Initial API and implementation
+ * Francois Chouinard - Put in shape for 1.0
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.experiment;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+/**
+ * A convenience class to store trace location arrays. The main purpose is to
+ * provide a Comparable implementation for TmfExperimentLocation.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable {
- public ITmfLocation<? extends Comparable<?>>[] locations;
-
- public TmfLocationArray(ITmfLocation<? extends Comparable<?>>[] locations) {
- this.locations = locations;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Override
- public int compareTo(TmfLocationArray o) {
- for (int i = 0; i < locations.length; i++) {
- ITmfLocation<? extends Comparable> l1 = (ITmfLocation<? extends Comparable>) locations[i].getLocation();
- ITmfLocation<? extends Comparable> l2 = (ITmfLocation<? extends Comparable>) o.locations[i].getLocation();
- int result = l1.getLocation().compareTo(l2.getLocation());
- if (result != 0) {
- return result;
- }
- }
- return 0;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#clone()
- */
- @Override
- protected TmfLocationArray clone() {
- ITmfLocation<? extends Comparable<?>>[] clones = (ITmfLocation<? extends Comparable<?>>[]) new ITmfLocation<?>[locations.length];
- for (int i = 0; i < locations.length; i++) {
- clones[i] = locations[i].clone();
- }
- return new TmfLocationArray(clones);
- }
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private ITmfLocation<? extends Comparable<?>>[] fLocations;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * The standard constructor
+ *
+ * @param locations the locations
+ */
+ public TmfLocationArray(ITmfLocation<? extends Comparable<?>>[] locations) {
+ fLocations = locations;
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters
+ // ------------------------------------------------------------------------
+
+ /**
+ * The standard constructor
+ *
+ * @param locations the locations
+ */
+ public ITmfLocation<? extends Comparable<?>>[] getLocations() {
+ return fLocations;
+ }
+
+ // ------------------------------------------------------------------------
+ // Cloneable
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public TmfLocationArray clone() {
+ ITmfLocation<? extends Comparable<?>>[] clones = (ITmfLocation<? extends Comparable<?>>[]) new ITmfLocation<?>[fLocations.length];
+ for (int i = 0; i < fLocations.length; i++) {
+ clones[i] = fLocations[i].clone();
+ }
+ return new TmfLocationArray(clones);
+ }
+
+ // ------------------------------------------------------------------------
+ // Comparable
+ // ------------------------------------------------------------------------
+ @Override
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public int compareTo(TmfLocationArray o) {
+ for (int i = 0; i < fLocations.length; i++) {
+ ITmfLocation<? extends Comparable> l1 = (ITmfLocation<? extends Comparable>) fLocations[i].getLocation();
+ ITmfLocation<? extends Comparable> l2 = (ITmfLocation<? extends Comparable>) o.fLocations[i].getLocation();
+ int result = l1.getLocation().compareTo(l2.getLocation());
+ if (result != 0) {
+ return result;
+ }
+ }
+ return 0;
+ }
+
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Arrays.hashCode(locations);
+ result = prime * result + Arrays.hashCode(fLocations);
return result;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
TmfLocationArray other = (TmfLocationArray) obj;
- if (!Arrays.equals(locations, other.locations))
+ if (!Arrays.equals(fLocations, other.fLocations)) {
return false;
+ }
return true;
}
-}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ @SuppressWarnings("nls")
+ public String toString() {
+ return "TmfLocationArray [locations=" + Arrays.toString(fLocations) + "]";
+ }
+}
* The basic trace checkpoint structure in TMF. The purpose of the checkpoint is
* to associate a trace location to an event timestamp.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
- * @see TmfCheckpoint
* @see ITmfTimestamp
* @see ITmfLocation
*/
-public interface ITmfCheckpoint extends Cloneable, Comparable<ITmfCheckpoint> {
+public interface ITmfCheckpoint extends Comparable<ITmfCheckpoint> {
// ------------------------------------------------------------------------
// Getters
*/
public ITmfLocation<? extends Comparable<?>> getLocation();
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
/**
* @return a clone of the checkpoint
*/
/**
* The basic trace context structure in TMF. The purpose of the context is to
- * associate a trace location to an event of a specific rank (order).
+ * associate a trace location to an event at a specific rank (order).
* <p>
* The context should be sufficient to allow the trace to position itself so
- * that performing a trace read operation will yield the corresponding event.
+ * that performing a trace read operation will yield the corresponding 'nth'
+ * event.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* @see ITmfLocation
*/
-public interface ITmfContext extends Cloneable {
+public interface ITmfContext {
// ------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------
/**
- * @return the rank of the event referred to by the context
+ * @return the rank of the event at the context location
*/
public long getRank();
/**
- * @return the location of the event referred to by the context
+ * @return the location of the event at the context rank
*/
public ITmfLocation<? extends Comparable<?>> getLocation();
*/
public void dispose();
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
/**
* @return a clone of the context
*/
/**
* The generic trace parser in TMF.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* <p>
* This location is trace-specific and must be comparable.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
- *
- * @see TmfLocation
*/
-public interface ITmfLocation<L extends Comparable<?>> extends Cloneable {
+public interface ITmfLocation<L extends Comparable<?>> {
// ------------------------------------------------------------------------
// Getters
public L getLocation();
// ------------------------------------------------------------------------
- // Cloneable
+ // Operations
// ------------------------------------------------------------------------
/**
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
/**
* The event stream structure in TMF. In its basic form, a trace has:
* <b>Example 1</b>: Process a whole trace
* <pre>
* ITmfContext context = trace.seekEvent(0);
- * ITmfEvent event = trace.readEvent(context);
+ * ITmfEvent event = trace.getNext(context);
* while (event != null) {
* processEvent(event);
- * event = trace.readNextEvent(context);
+ * event = trace.getNext(context);
* }
* </pre>
* <b>Example 2</b>: Process 50 events starting from the 1000th event
* <pre>
* int nbEventsRead = 0;
* ITmfContext context = trace.seekEvent(1000);
- * ITmfEvent event = trace.readNextEvent(context);
+ * ITmfEvent event = trace.getNext(context);
* while (event != null && nbEventsRead < 50) {
* nbEventsRead++;
* processEvent(event);
- * event = trace.readNextEvent(context);
+ * event = trace.getNext(context);
* }
* </pre>
* <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
* ITmfTimestamp startTime = ...;
* ITmfTimestamp endTime = ...;
* ITmfContext context = trace.seekEvent(startTime);
- * ITmfEvent event = trace.readNextEvent(context);
+ * ITmfEvent event = trace.getNext(context);
* while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
* processEvent(event);
- * event = trace.readNextEvent(context);
+ * event = trace.getNext(context);
* }
* </pre>
* A trace is also an event provider so it can process event requests
* }
* </pre>
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
- *
+ *
+ * @see ITmfContext
* @see ITmfEvent
- * @see ITmfDataProvider
- * @see ITmfEventRequest
- * @see TmfTrace
+ * @see ITmfTraceIndexer
+ * @see ITmfEventParser
*/
public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ /**
+ * The default trace cache size
+ */
+ public static final int DEFAULT_TRACE_CACHE_SIZE = 1000;
+
// ------------------------------------------------------------------------
// Initializers
// ------------------------------------------------------------------------
*/
public ITmfContext seekEvent(double ratio);
- // ------------------------------------------------------------------------
- // Read operations (returning an actual event)
- // ------------------------------------------------------------------------
-
- /**
- * Return the event pointed by the supplied context (or null if no event
- * left) and updates the context to point the next event.
- *
- * @param context the read context (will be updated)
- * @return the event pointed to by the context
- */
- public ITmfEvent readNextEvent(ITmfContext context);
-
}
/**
* The generic trace indexer in TMF.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
* to a generic location.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
- * @see ITmfCheckpoint
* @see ITmfLocation
* @see ITmfTimestamp
*/
-public class TmfCheckpoint implements ITmfCheckpoint {
+public class TmfCheckpoint implements ITmfCheckpoint, Cloneable {
// ------------------------------------------------------------------------
// Attributes
* @param other the other checkpoint
*/
public TmfCheckpoint(final TmfCheckpoint other) {
- if (other == null)
+ if (other == null) {
throw new IllegalArgumentException();
+ }
fTimestamp = other.fTimestamp;
fLocation = other.fLocation;
}
*/
@Override
public boolean equals(final Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (!(obj instanceof TmfCheckpoint))
+ }
+ if (!(obj instanceof TmfCheckpoint)) {
return false;
+ }
final TmfCheckpoint other = (TmfCheckpoint) obj;
if (fLocation == null) {
- if (other.fLocation != null)
+ if (other.fLocation != null) {
return false;
- } else if (!fLocation.equals(other.fLocation))
+ }
+ } else if (!fLocation.equals(other.fLocation)) {
return false;
+ }
if (fTimestamp == null) {
- if (other.fTimestamp != null)
+ if (other.fTimestamp != null) {
return false;
- } else if (!fTimestamp.equals(other.fTimestamp))
+ }
+ } else if (!fTimestamp.equals(other.fTimestamp)) {
return false;
+ }
return true;
}
package org.eclipse.linuxtools.tmf.core.trace;
+import java.util.ArrayList;
import java.util.Collections;
-import java.util.Vector;
+import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
* Locating a specific checkpoint is trivial for both rank (rank % interval) and
* timestamp (bsearch in the array).
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
- * @see ITmfTraceIndexer
* @see ITmfTrace
* @see ITmfEvent
*/
// Attributes
// ------------------------------------------------------------------------
- /**
- * The event trace to index
- */
+ // The event trace to index
private final ITmfTrace<ITmfEvent> fTrace;
- /**
- * The interval between checkpoints
- */
- protected final int fCheckpointInterval;
+ // The interval between checkpoints
+ private final int fCheckpointInterval;
/**
* The trace index. It is composed of checkpoints taken at intervals of
* fCheckpointInterval events.
*/
- protected final Vector<TmfCheckpoint> fTraceIndex;
+ private final List<TmfCheckpoint> fTraceIndex;
// ------------------------------------------------------------------------
// Construction
public TmfCheckpointIndexer(final ITmfTrace<ITmfEvent> trace, final int interval) {
fTrace = trace;
fCheckpointInterval = interval;
- fTraceIndex = new Vector<TmfCheckpoint>();
+ fTraceIndex = new ArrayList<TmfCheckpoint>();
}
// ------------------------------------------------------------------------
fTraceIndex.clear();
// Build a background request for all the trace data. The index is
- // updated as we go by getNextEvent().
+ // updated as we go by readNextEvent().
final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, TmfTimeRange.ETERNITY,
TmfDataRequest.ALL_DATA, fCheckpointInterval, ITmfDataRequest.ExecutionType.BACKGROUND)
{
- ITmfTimestamp startTime = null;
- ITmfTimestamp lastTime = null;
+ private ITmfTimestamp startTime = null;
+ private ITmfTimestamp lastTime = null;
@Override
public void handleData(final ITmfEvent event) {
public synchronized ITmfContext seekIndex(final ITmfTimestamp timestamp) {
// A null timestamp indicates to seek the first event
- if (timestamp == null)
+ if (timestamp == null) {
return fTrace.seekEvent(0);
+ }
// Find the checkpoint at or before the requested timestamp.
// In the very likely event that the timestamp is not at a checkpoint
public ITmfContext seekIndex(final long rank) {
// A rank < 0 indicates to seek the first event
- if (rank < 0)
+ if (rank < 0) {
return fTrace.seekEvent(0);
+ }
// Find the checkpoint at or before the requested rank.
final int index = (int) rank / fCheckpointInterval;
/**
* Position the trace at the given checkpoint
*
- * @param index
- * the checkpoint index
+ * @param checkpoint the checkpoint index
* @return the corresponding context
*/
- private ITmfContext seekCheckpoint(int index) {
- ITmfLocation<?> location;
+ private ITmfContext seekCheckpoint(final int checkpoint) {
+ ITmfLocation<?> location = null;
+ int index = checkpoint;
synchronized (fTraceIndex) {
if (!fTraceIndex.isEmpty()) {
if (index >= fTraceIndex.size()) {
index = fTraceIndex.size() - 1;
}
- location = fTraceIndex.elementAt(index).getLocation();
- } else {
- location = null;
+ location = fTraceIndex.get(index).getLocation();
}
}
final ITmfContext context = fTrace.seekEvent(location);
return context;
}
+ // ------------------------------------------------------------------------
+ // Getters
+ // ------------------------------------------------------------------------
+
+ /**
+ * @return the trace index
+ */
+ protected List<TmfCheckpoint> getTraceIndex() {
+ return fTraceIndex;
+ }
}
* It ties a trace location to an event rank. The context should be enough to
* restore the trace state so the corresponding event can be read.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
* @param context the other context
*/
public TmfContext(final TmfContext context) {
- if (context == null)
+ if (context == null) {
throw new IllegalArgumentException();
+ }
fLocation = context.fLocation;
fRank = context.fRank;
}
*/
@Override
public void increaseRank() {
- if (hasValidRank())
+ if (hasValidRank()) {
fRank++;
+ }
}
/* (non-Javadoc)
*/
@Override
public boolean equals(final Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
final TmfContext other = (TmfContext) obj;
if (fLocation == null) {
- if (other.fLocation != null)
+ if (other.fLocation != null) {
return false;
- } else if (!fLocation.equals(other.fLocation))
+ }
+ } else if (!fLocation.equals(other.fLocation)) {
return false;
- if (fRank != other.fRank)
+ }
+ if (fRank != other.fRank) {
return false;
+ }
return true;
}
* A convenience implementation on of ITmfLocation. The generic class (L) must
* be comparable.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*/
-public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L> {
+public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cloneable {
// ------------------------------------------------------------------------
// Attributes
*/
@SuppressWarnings("unused")
private TmfLocation() {
- fLocation = null;
}
/**
final Method method = clazz.getMethod("clone", new Class[0]); //$NON-NLS-1$
final Object copy = method.invoke(this.fLocation, new Object[0]);
clone.fLocation = (L) copy;
- } else
+ } else {
clone.fLocation = null;
+ }
} catch (final CloneNotSupportedException e) {
} catch (final NoSuchMethodException e) {
} catch (final Exception e) {
@Override
@SuppressWarnings("unchecked")
public boolean equals(final Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
final TmfLocation<L> other = (TmfLocation<L>) obj;
if (fLocation == null) {
- if (other.fLocation != null)
+ if (other.fLocation != null) {
return false;
- } else if (!fLocation.equals(other.fLocation))
+ }
+ } else if (!fLocation.equals(other.fLocation)) {
return false;
+ }
return true;
}
package org.eclipse.linuxtools.tmf.core.trace;
import java.io.File;
-import java.io.FileNotFoundException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Path;
* TmfCheckpointIndexer (default). In this case, the trace cache size will be
* used as checkpoint interval.
*
- * @since 1.0
* @version 1.0
* @author Francois Chouinard
*
*/
public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T> implements ITmfTrace<T> {
- // ------------------------------------------------------------------------
- // Constants
- // ------------------------------------------------------------------------
-
- /**
- * The default trace cache size
- */
- public static final int DEFAULT_TRACE_CACHE_SIZE = 10000;
-
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
// The trace path
private String fPath;
- /**
- * The trace cache page size
- */
- protected int fCacheSize = DEFAULT_TRACE_CACHE_SIZE;
+ // The trace cache page size
+ private int fCacheSize = ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
- /**
- * The number of events collected (so far)
- */
- protected long fNbEvents = 0;
+ // The number of events collected (so far)
+ private long fNbEvents = 0;
// The time span of the event stream
private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH;
private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
- /**
- * The trace streaming interval (0 = no streaming)
- */
- protected long fStreamingInterval = 0;
+ // The trace streaming interval (0 = no streaming)
+ private long fStreamingInterval = 0;
- /**
- * The trace indexer
- */
- protected ITmfTraceIndexer<ITmfTrace<ITmfEvent>> fIndexer;
+ // The trace indexer
+ private ITmfTraceIndexer<ITmfTrace<ITmfEvent>> fIndexer;
- /**
- * The trace parser
- */
- protected ITmfEventParser<T> fParser;
+ // The trace parser
+ private ITmfEventParser<T> fParser;
// ------------------------------------------------------------------------
// Construction
*/
protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize,
final long interval, final ITmfTraceIndexer<?> indexer) throws TmfTraceException {
- this(resource, type, path, cacheSize, interval, null, null);
+ this(resource, type, path, cacheSize, interval, indexer, null);
}
/**
protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize,
final long interval, final ITmfTraceIndexer<?> indexer, final ITmfEventParser<T> parser) throws TmfTraceException {
super();
- fCacheSize = (cacheSize > 0) ? cacheSize : DEFAULT_TRACE_CACHE_SIZE;
+ fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
fStreamingInterval = interval;
fIndexer = (indexer != null) ? indexer : new TmfCheckpointIndexer(this, fCacheSize);
fParser = parser;
@SuppressWarnings({ "unchecked", "rawtypes" })
public TmfTrace(final TmfTrace<T> trace) throws TmfTraceException {
super();
- if (trace == null)
+ if (trace == null) {
throw new IllegalArgumentException();
+ }
fCacheSize = trace.getCacheSize();
fStreamingInterval = trace.getStreamingInterval();
fIndexer = new TmfCheckpointIndexer(this);
@Override
public void initTrace(final IResource resource, final String path, final Class<T> type) throws TmfTraceException {
initialize(resource, path, type);
- fIndexer.buildIndex(false);
}
/**
* @param path the trace path
* @param type the trace event type
*
- * @throws FileNotFoundException
+ * @throws TmfTraceException
*/
@SuppressWarnings("unchecked")
protected void initialize(final IResource resource, final String path, final Class<T> type) throws TmfTraceException {
- if (path == null)
+ if (path == null) {
throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$
+ }
fPath = path;
fResource = resource;
String traceName = (resource != null) ? resource.getName() : null;
return file.exists();
}
+ /**
+ * Index the trace
+ *
+ * @param waitForCompletion index synchronously (true) or not (false)
+ */
+ protected void indexTrace(boolean waitForCompletion) {
+ getIndexer().buildIndex(waitForCompletion);
+ }
+
// ------------------------------------------------------------------------
// ITmfTrace - Basic getters
// ------------------------------------------------------------------------
return fStreamingInterval;
}
+ /**
+ * @return the trace indexer
+ */
+ protected ITmfTraceIndexer<ITmfTrace<ITmfEvent>> getIndexer() {
+ return fIndexer;
+ }
+
+ /**
+ * @return the trace parser
+ */
+ protected ITmfEventParser<T> getParser() {
+ return fParser;
+ }
+
// ------------------------------------------------------------------------
// ITmfTrace - Trace characteristics getters
// ------------------------------------------------------------------------
}
// ------------------------------------------------------------------------
- // Convenience setters
+ // Convenience setters/getters
// ------------------------------------------------------------------------
+ /**
+ * Set the trace cache size. Must be done at initialization time.
+ *
+ * @param cacheSize The trace cache size
+ */
+ protected void setCacheSize(final int cacheSize) {
+ fCacheSize = cacheSize;
+ }
+
+ /**
+ * Set the trace known number of events. This can be quite dynamic
+ * during indexing or for live traces.
+ *
+ * @param nbEvents The number of events
+ */
+ protected synchronized void setNbEvents(final long nbEvents) {
+ fNbEvents = (nbEvents > 0) ? nbEvents : 0;
+ }
+
/**
* Update the trace events time range
*
}
/**
- * Update the trace streaming interval
+ * Set the polling interval for live traces (default = 0 = no streaming).
*
* @param interval the new trace streaming interval
*/
fStreamingInterval = (interval > 0) ? interval : 0;
}
+ /**
+ * Set the trace indexer. Must be done at initialization time.
+ *
+ * @param indexer the trace indexer
+ */
+ protected void setIndexer(final ITmfTraceIndexer<ITmfTrace<ITmfEvent>> indexer) {
+ fIndexer = indexer;
+ }
+
+ /**
+ * Set the trace parser. Must be done at initialization time.
+ *
+ * @param parser the new trace parser
+ */
+ protected void setParser(final ITmfEventParser<T> parser) {
+ fParser = parser;
+ }
+
// ------------------------------------------------------------------------
// ITmfTrace - SeekEvent operations (returning a trace context)
// ------------------------------------------------------------------------
// And locate the requested event context
long pos = context.getRank();
if (pos < rank) {
- ITmfEvent event = readNextEvent(context);
+ ITmfEvent event = getNext(context);
while (event != null && ++pos < rank) {
- event = readNextEvent(context);
+ event = getNext(context);
}
}
return context;
// And locate the requested event context
final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype...
- ITmfEvent event = readNextEvent(nextEventContext);
+ ITmfEvent event = getNext(nextEventContext);
while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
context.setLocation(nextEventContext.getLocation().clone());
context.increaseRank();
- event = readNextEvent(nextEventContext);
+ event = getNext(nextEventContext);
+ }
+ if (event == null) {
+ context.setLocation(null);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
}
return context;
}
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
*/
@Override
- public synchronized ITmfEvent readNextEvent(final ITmfContext context) {
+ public synchronized T getNext(final ITmfContext context) {
// parseEvent() does not update the context
- final ITmfEvent event = fParser.parseEvent(context);
+ final T event = fParser.parseEvent(context);
if (event != null) {
updateAttributes(context, event.getTimestamp());
context.setLocation(getCurrentLocation());
@Override
public ITmfContext armRequest(final ITmfDataRequest<T> request) {
if (request instanceof ITmfEventRequest<?>
- && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest<T>) request).getRange().getStartTime())
- && request.getIndex() == 0) {
+ && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest<T>) request).getRange().getStartTime())
+ && request.getIndex() == 0)
+ {
final ITmfContext context = seekEvent(((ITmfEventRequest<T>) request).getRange().getStartTime());
((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank());
return context;
return seekEvent(request.getIndex());
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#getNext(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
- */
- @Override
- @SuppressWarnings("unchecked")
- public T getNext(final ITmfContext context) {
- if (context instanceof TmfContext)
- return (T) readNextEvent(context);
- return null;
- }
+// /* (non-Javadoc)
+// * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#getNext(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
+// */
+// @Override
+// @SuppressWarnings("unchecked")
+// public T getNext(final ITmfContext context) {
+// if (context instanceof TmfContext) {
+// return (T) readNextEvent(context);
+// }
+// return null;
+// }
// ------------------------------------------------------------------------
</uml2SDLoader>
</extension>
+ <extension
+ point="org.eclipse.linuxtools.tmf.ui.tracetype">
+ <category
+ id="org.eclipse.linuxtools.tmf.tests.category.tracetype"
+ name="Test trace">
+ </category>
+ <type
+ category="org.eclipse.linuxtools.tmf.tests.category.tracetype"
+ event_type="org.eclipse.linuxtools.tmf.core.event.TmfEvent"
+ id="org.eclipse.linuxtools.tmf.tests.tracetype"
+ name="TMF Tests"
+ trace_type="org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub">
+ <eventsTableType
+ class="org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable">
+ </eventsTableType>
+ </type>
+ </extension>
+
</plugin>
Bundle-Activator: org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.eclipse.ui;bundle-version="3.7.0",
- org.eclipse.ui.ide;bundle-version="3.7.0",
- org.eclipse.core.resources;bundle-version="3.7.100",
+Require-Bundle: org.eclipse.core.expressions,
org.eclipse.core.filesystem;bundle-version="1.3.100",
+ org.eclipse.core.resources;bundle-version="3.7.100",
org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.linuxtools.tmf.core;bundle-version="0.5.0",
+ org.eclipse.ui;bundle-version="3.7.0",
+ org.eclipse.ui.ide;bundle-version="3.7.0",
org.eclipse.ui.navigator;bundle-version="3.5.100",
- org.eclipse.ui.navigator.resources;bundle-version="3.4.300",
- org.eclipse.core.expressions
+ org.eclipse.ui.navigator.resources;bundle-version="3.4.300"
Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.linuxtools.tmf.ui.tests",
+ org.eclipse.linuxtools.internal.tmf.ui.commands;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.dialogs;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.editors.handlers;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.preferences;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.project.handlers;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.signal;x-internal:=true,
org.eclipse.linuxtools.tmf.ui.editors,
org.eclipse.linuxtools.tmf.ui.project.model,
org.eclipse.linuxtools.tmf.ui.project.wizards,
import org.eclipse.core.resources.IProject;\r
import org.eclipse.core.resources.IResource;\r
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;\r
import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;\r
}\r
\r
@Override\r
- public synchronized TmfEvent readNextEvent(final ITmfContext context) {\r
+ public synchronized CustomTxtEvent getNext(final ITmfContext context) {\r
final ITmfContext savedContext = context.clone();\r
- final TmfEvent event = parseEvent(context);\r
+ final CustomTxtEvent event = parseEvent(context);\r
if (event != null) {\r
updateAttributes(savedContext, event.getTimestamp());\r
context.increaseRank();\r
import org.eclipse.core.resources.IResource;\r
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;\r
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;\r
import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;\r
}\r
\r
@Override\r
- public synchronized TmfEvent readNextEvent(final ITmfContext context) {\r
+ public synchronized CustomXmlEvent getNext(final ITmfContext context) {\r
final ITmfContext savedContext = context.clone();\r
- final TmfEvent event = parseEvent(context);\r
+ final CustomXmlEvent event = parseEvent(context);\r
if (event != null) {\r
updateAttributes(savedContext, event.getTimestamp());\r
context.increaseRank();\r
return;
fDataModel.setCurrentEvent(fCurrentEventTime);
fScaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, HISTOGRAM_BAR_WIDTH);
- if (fScaledData != null) {
- fCanvas.redraw();
- // Display histogram and update X-,Y-axis labels
- fTimeRangeStartText.setText(HistogramUtils.nanosecondsToString(fDataModel.getFirstBucketTime()));
- fTimeRangeEndText.setText(HistogramUtils.nanosecondsToString(fDataModel.getEndTime()));
- fMaxNbEventsText.setText(Long.toString(fScaledData.fMaxValue));
- // The Y-axis area might need to be re-sized
- fMaxNbEventsText.getParent().layout();
+ synchronized(fScaledData) {
+ if (fScaledData != null) {
+ fCanvas.redraw();
+ // Display histogram and update X-,Y-axis labels
+ fTimeRangeStartText.setText(HistogramUtils.nanosecondsToString(fDataModel.getFirstBucketTime()));
+ fTimeRangeEndText.setText(HistogramUtils.nanosecondsToString(fDataModel.getEndTime()));
+ fMaxNbEventsText.setText(Long.toString(fScaledData.fMaxValue));
+ // The Y-axis area might need to be re-sized
+ fMaxNbEventsText.getParent().layout();
+ }
}
}
}
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
/**
* <b><u>HistogramRequest</u></b>
// ------------------------------------------------------------------------
public HistogramRequest(HistogramDataModel histogram, TmfTimeRange range, int rank, int nbEvents, ITmfDataRequest.ExecutionType execType) {
- super(ITmfEvent.class, range, rank, nbEvents, TmfTrace.DEFAULT_TRACE_CACHE_SIZE, execType);
+ super(ITmfEvent.class, range, rank, nbEvents, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, execType);
fHistogram = histogram;
}
}\r
while (true) {\r
long rank = context.getRank();\r
- ITmfEvent event = trace.readNextEvent(context);\r
+ ITmfEvent event = trace.getNext(context);\r
if (event == null) {\r
done = true;\r
break;\r
if (interrupted)\r
return;\r
long rank = fContext.getRank();\r
- ITmfEvent event = trace.readNextEvent(fContext);\r
+ ITmfEvent event = trace.getNext(fContext);\r
if (event == null) {\r
break;\r
}\r
long rank = 0;\r
while (!context.getLocation().equals(endLocation)) {\r
location = context.getLocation().clone();\r
- ITmfEvent event = fTrace.readNextEvent(context);\r
+ ITmfEvent event = fTrace.getNext(context);\r
if (event == null) {\r
break;\r
}\r
} else {\r
//fBottomContext = fTrace.seekEvent(fLines.get(fLines.size() - 1).rank + 1);\r
fBottomContext = fTrace.seekEvent(fLines.get(fLines.size() - 1).location);\r
- fTrace.readNextEvent(fBottomContext);\r
+ fTrace.getNext(fBottomContext);\r
}\r
if (fBottomContext == null) {\r
break;\r
}\r
long rank = fBottomContext.getRank();\r
ITmfLocation<?> location = fBottomContext.getLocation() != null ? fBottomContext.getLocation().clone() : null;\r
- ITmfEvent event = fTrace.readNextEvent(fBottomContext);\r
+ ITmfEvent event = fTrace.getNext(fBottomContext);\r
if (event == null) {\r
break;\r
}\r