use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.
the class TmfEventProviderTest method testGetPlainEvents.
// ------------------------------------------------------------------------
// getSyntheticEvent
// ------------------------------------------------------------------------
/**
* Test getPlainEvents
*/
@Test
public void testGetPlainEvents() {
final int NB_EVENTS = 1000;
final Vector<ITmfEvent> requestedEvents = new Vector<>();
// Get the TmfSyntheticEventStub provider
ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
ITmfEventProvider provider = eventProviders[0];
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(ITmfEvent event) {
super.handleData(event);
requestedEvents.add(event);
}
};
provider.sendRequest(request);
try {
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());
}
} catch (InterruptedException e) {
fail();
}
}
use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.
the class TmfEventProviderTest method getSyntheticData.
private static void getSyntheticData(final TmfTimeRange range, final int nbEvents) throws InterruptedException {
final Vector<ITmfEvent> requestedEvents = new Vector<>();
// Get the event provider
ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(TmfSyntheticEventStub.class);
ITmfEventProvider provider = eventProviders[0];
final TmfEventRequest request = new TmfEventRequest(TmfSyntheticEventStub.class, range, 0, nbEvents, ExecutionType.FOREGROUND) {
@Override
public void handleData(ITmfEvent event) {
super.handleData(event);
requestedEvents.add(event);
}
};
provider.sendRequest(request);
request.waitForCompletion();
if (nbEvents != -1) {
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 / 2); i++) {
assertEquals("Distinct events", i + 1, requestedEvents.get(2 * i + 0).getTimestamp().getValue());
assertEquals("Distinct events", i + 1, requestedEvents.get(2 * i + 1).getTimestamp().getValue());
}
}
use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.
the class TmfSyntheticEventProviderStub method armRequest.
@Override
public ITmfContext armRequest(final ITmfEventRequest request) {
// Get the TmfSyntheticEventStub provider
final ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
final ITmfEventProvider provider = eventProviders[0];
final TmfTimeRange range = request.getRange();
final TmfEventRequest subRequest = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {
@Override
public void handleData(final ITmfEvent event) {
super.handleData(event);
handleIncomingData(event);
}
};
provider.sendRequest(subRequest);
// Return a dummy context
return new TmfContext();
}
use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.
the class ITmfTrace method getUUID.
/**
* Get the trace {@link UUID}, a unique identifier that should always be the
* same if the trace and the children do not change.
*
* The default implementation relies on the trace name, the length of the file
* and the last modified date.
*
* @return A {@link UUID} that when it changes is a good indication that the
* trace files have changed. An unchanged {@link UUID} may or may not
* indicate that the trace has changed.
* @since 3.1
*/
@Nullable
default UUID getUUID() {
/*
* Best effort get UUID, if an implementation has more info, it should override
* this.
*/
StringBuilder sb = new StringBuilder();
File file = new File(getPath());
if (file.isDirectory()) {
for (File childFile : file.listFiles()) {
sb.append(childFile.getName());
sb.append(childFile.length());
sb.append(childFile.lastModified());
}
} else if (file.exists()) {
sb.append(file.getName());
sb.append(file.length());
sb.append(file.lastModified());
}
for (ITmfEventProvider child : getChildren()) {
if (child instanceof ITmfTrace) {
sb.append(String.valueOf(((ITmfTrace) child).getUUID()));
}
}
return UUID.nameUUIDFromBytes(Objects.requireNonNull(sb.toString().getBytes(Charset.defaultCharset())));
}
use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.
the class TmfTraceUtils method getAnalysisModulesOfClass.
/**
* Return the analysis modules that are of a given class. The modules will be
* cast to the requested class. If the trace has children, the childrens modules
* are also returned.
*
* @param trace
* The trace for which you want the modules, the children trace
* modules are added as well.
* @param moduleClass
* Returned modules must extend this class
* @return List of modules of class moduleClass
*/
public static <T> Iterable<@NonNull T> getAnalysisModulesOfClass(ITmfTrace trace, Class<T> moduleClass) {
Iterable<IAnalysisModule> analysisModules = trace.getAnalysisModules();
List<@NonNull T> modules = new ArrayList<>();
for (IAnalysisModule module : analysisModules) {
if (moduleClass.isAssignableFrom(module.getClass())) {
modules.add(checkNotNull(moduleClass.cast(module)));
}
}
for (ITmfEventProvider child : trace.getChildren()) {
if (child instanceof ITmfTrace) {
ITmfTrace childTrace = (ITmfTrace) child;
Iterables.addAll(modules, getAnalysisModulesOfClass(childTrace, moduleClass));
}
}
return modules;
}
Aggregations