use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfExperimentTest method testProcessRequestForNbEvents.
// ------------------------------------------------------------------------
// processRequest
// ------------------------------------------------------------------------
@Test
public void testProcessRequestForNbEvents() throws InterruptedException {
final int nbEvents = 1000;
final Vector<ITmfEvent> requestedEvents = new Vector<>();
final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, 0, nbEvents, ExecutionType.FOREGROUND) {
@Override
public void handleData(final ITmfEvent 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());
// 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());
}
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfCheckpointIndexer method buildIndex.
// ------------------------------------------------------------------------
// ITmfTraceIndexer - buildIndex
// ------------------------------------------------------------------------
@Override
public void buildIndex(final long offset, final TmfTimeRange range, final boolean waitForCompletion) {
long indexingOffset = offset;
TmfTimeRange indexingTimeRange = range;
// Don't do anything if we are already indexing
synchronized (fTraceIndex) {
if (fIsIndexing) {
return;
}
fIsIndexing = true;
}
// Restore previously built index values
if (!fTraceIndex.isCreatedFromScratch() && !fBuiltOnce && fTraceIndex.getNbEvents() > 0) {
indexingOffset = fTraceIndex.getNbEvents();
indexingTimeRange = new TmfTimeRange(fTraceIndex.getTimeRange().getStartTime(), TmfTimestamp.BIG_CRUNCH);
// $NON-NLS-1$ //$NON-NLS-2$
TmfCoreTracer.traceIndexer("restoring index. nbEvents: " + fTraceIndex.getNbEvents() + " time range: " + fTraceIndex.getTimeRange());
// Set some trace attributes that depends on indexing
TmfTraceUpdatedSignal signal = new TmfTraceUpdatedSignal(this, fTrace, new TmfTimeRange(fTraceIndex.getTimeRange().getStartTime(), fTraceIndex.getTimeRange().getEndTime()), indexingOffset);
fTrace.broadcast(signal);
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
TmfCoreTracer.traceIndexer("buildIndex. offset: " + indexingOffset + " (requested " + offset + ")" + " time range: " + range);
// The monitoring job
// $NON-NLS-1$ //$NON-NLS-2$
TmfIndexingJob job = new TmfIndexingJob("Indexing " + fTrace.getName() + "...");
job.setSystem(fBuiltOnce);
fBuiltOnce = true;
job.schedule();
// Build a background request for all the trace data. The index is
// updated as we go by readNextEvent().
fIndexingRequest = new TmfEventRequest(ITmfEvent.class, indexingTimeRange, indexingOffset, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.BACKGROUND) {
@Override
public void handleData(final ITmfEvent event) {
super.handleData(event);
// Update the trace status at regular intervals
if ((getNbRead() % fCheckpointInterval) == 0) {
updateTraceStatus();
}
}
@Override
public void handleSuccess() {
updateTraceStatus();
}
@Override
public void handleCompleted() {
job.cancel();
fTraceIndex.setTimeRange(fTrace.getTimeRange());
fTraceIndex.setNbEvents(fTrace.getNbEvents());
super.handleCompleted();
fIsIndexing = false;
// $NON-NLS-1$ //$NON-NLS-2$
TmfCoreTracer.traceIndexer("Build index request completed. nbEvents: " + fTraceIndex.getNbEvents() + " time range: " + fTraceIndex.getTimeRange());
}
@Override
public void fail(Exception e) {
super.fail(e);
job.setException(e);
}
private void updateTraceStatus() {
if (fTrace.getNbEvents() > 0) {
signalNewTimeRange(fTrace.getStartTime(), fTrace.getEndTime());
}
}
};
// Submit the request and wait for completion if required
fTrace.sendRequest(fIndexingRequest);
if (waitForCompletion) {
try {
fIndexingRequest.waitForCompletion();
} catch (final InterruptedException e) {
}
}
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfTraceTest method testProcessDataRequestForSomeEvents.
@Test
public void testProcessDataRequestForSomeEvents() throws InterruptedException {
final int startIndex = 100;
final int nbEvents = 1000;
final Vector<ITmfEvent> requestedEvents = new Vector<>();
final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, startIndex, nbEvents, TmfEventRequest.ExecutionType.FOREGROUND) {
@Override
public void handleData(final ITmfEvent event) {
super.handleData(event);
requestedEvents.add(event);
}
};
final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class);
providers[0].sendRequest(request);
request.waitForCompletion();
assertEquals("nbEvents", nbEvents, requestedEvents.size());
assertTrue("isCompleted", request.isCompleted());
assertFalse("isCancelled", request.isCancelled());
// Don't go overboard: we are not validating the stub!
for (int i = 0; i < nbEvents; i++) {
assertEquals("Distinct events", startIndex + 1 + i, requestedEvents.get(i).getTimestamp().getValue());
}
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfTraceTest method testProcessEventRequestForAllEvents.
// ------------------------------------------------------------------------
// processRequest
// ------------------------------------------------------------------------
@Test
public void testProcessEventRequestForAllEvents() throws InterruptedException {
final Vector<ITmfEvent> requestedEvents = new Vector<>();
final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {
@Override
public void handleData(final ITmfEvent event) {
super.handleData(event);
requestedEvents.add(event);
}
};
final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class);
providers[0].sendRequest(request);
request.waitForCompletion();
assertEquals("nbEvents", NB_EVENTS, requestedEvents.size());
assertTrue("isCompleted", request.isCompleted());
assertFalse("isCancelled", request.isCancelled());
// Don't go overboard: we are not validating the stub!
for (int i = 0; i < NB_EVENTS; i++) {
assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue());
}
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfTraceTest method testProcessEventRequestForSomeEvents.
@Test
public void testProcessEventRequestForSomeEvents() throws InterruptedException {
final long startTime = 100;
final int nbEvents = 1000;
final Vector<ITmfEvent> requestedEvents = new Vector<>();
final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.create(startTime, SCALE), TmfTimestamp.BIG_CRUNCH);
final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, 0, nbEvents, ExecutionType.FOREGROUND) {
@Override
public void handleData(final ITmfEvent event) {
super.handleData(event);
requestedEvents.add(event);
}
};
final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class);
providers[0].sendRequest(request);
request.waitForCompletion();
assertEquals("nbEvents", nbEvents, requestedEvents.size());
assertTrue("isCompleted", request.isCompleted());
assertFalse("isCancelled", request.isCancelled());
// Don't go overboard: we are not validating the stub!
for (int i = 0; i < nbEvents; i++) {
assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue());
}
}
Aggregations