use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.
the class XmlStubTraceTest method testAspects.
/**
* Test the presence and resolve of the aspects for this trace
*/
@Test
public void testAspects() {
fTestTrace = TmfXmlTraceStubNs.setupTrace(TmfCoreTestPlugin.getAbsoluteFilePath(VALID_FILE));
ITmfEventAspect<?> cpuAspect = null;
ITmfEventAspect<?> testAspect = null;
int aspectCount = 0;
for (ITmfEventAspect<?> aspect : fTestTrace.getEventAspects()) {
aspectCount++;
if (aspect instanceof TmfCpuAspect) {
cpuAspect = aspect;
} else if (aspect.getName().equals("test")) {
testAspect = aspect;
}
}
/* Check the presence of the cpu and test aspects */
assertEquals("Number of aspects", 5, aspectCount);
assertNotNull(cpuAspect);
assertNotNull(testAspect);
ITmfContext ctx;
ctx = fTestTrace.seekEvent(0L);
assertNotNull(ctx);
ITmfEvent event = fTestTrace.getNext(ctx);
assertNotNull(event);
assertEquals("Cpu aspect of event 1", 1, cpuAspect.resolve(event));
assertEquals("Test aspect of event 1", "abc", testAspect.resolve(event));
event = fTestTrace.getNext(ctx);
assertNotNull(event);
assertEquals("Cpu aspect of event 2", 1, cpuAspect.resolve(event));
assertEquals("Test aspect of event 2", "abc", testAspect.resolve(event));
event = fTestTrace.getNext(ctx);
assertNotNull(event);
assertEquals("Cpu aspect of event 3", 2, cpuAspect.resolve(event));
assertEquals("Test aspect of event 3", "def", testAspect.resolve(event));
event = fTestTrace.getNext(ctx);
assertNotNull(event);
assertEquals("Cpu aspect of event 4", 1, cpuAspect.resolve(event));
assertEquals("Test aspect of event 4", "def", testAspect.resolve(event));
ctx.dispose();
}
use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.
the class TmfXmlTraceStub method getNext.
@Override
@Nullable
public synchronized ITmfEvent getNext(@Nullable ITmfContext context) {
if (context == null) {
return null;
}
final ITmfContext savedContext = new TmfContext(context.getLocation(), context.getRank());
CustomXmlEvent event = fTrace.getNext(context);
if (event == null) {
return null;
}
/* Translate the content of the event */
/* The "fields" field contains a | separated list of field names */
/* The "values" field contains a | separated list of field values */
/* the "type" field contains a | separated list of field types */
ITmfEventField content = event.getContent();
if (content == null) {
return null;
}
String fieldString = getStringValue(content, FIELD_NAMES_FIELD);
String valueString = getStringValue(content, VALUES_FIELD);
String typeString = getStringValue(content, TYPES_FIELD);
String[] fields = fieldString.split(VALUES_SEPARATOR);
String[] values = valueString.split(VALUES_SEPARATOR);
String[] types = typeString.split(VALUES_SEPARATOR);
ITmfEventField[] fieldsArray = new TmfEventField[fields.length];
for (int i = 0; i < fields.length; i++) {
String value = EMPTY;
if (values.length > i) {
value = values[i];
}
String type = null;
if (types.length > i) {
type = types[i];
}
Object val = value;
if (type != null) {
switch(type) {
case TYPE_INTEGER:
{
try {
val = Integer.valueOf(value);
} catch (NumberFormatException e) {
// $NON-NLS-1$
Activator.logError(String.format("Get next XML event: cannot cast value %s to integer", value), e);
val = 0;
}
break;
}
case TYPE_LONG:
{
try {
val = Long.valueOf(value);
} catch (NumberFormatException e) {
// $NON-NLS-1$
Activator.logError(String.format("Get next XML event: cannot cast value %s to long", value), e);
val = 0L;
}
break;
}
case TYPE_LONG_ARRAY:
{
try {
String[] split = value.split(",");
long[] arr = new long[split.length];
for (int j = 0; j < split.length; j++) {
arr[j] = Long.valueOf(split[j]);
}
val = arr;
} catch (NumberFormatException e) {
// $NON-NLS-1$
Activator.logError(String.format("Get next XML event: cannot cast one of the comma-separated values of %s to long", value), e);
val = new long[0];
}
break;
}
case TYPE_INT_ARRAY:
{
try {
String[] split = value.split(",");
int[] arr = new int[split.length];
for (int j = 0; j < split.length; j++) {
arr[j] = Integer.valueOf(split[j]);
}
val = arr;
} catch (NumberFormatException e) {
// $NON-NLS-1$
Activator.logError(String.format("Get next XML event: cannot cast one of the comma-separated values of %s to int", value), e);
val = new int[0];
}
break;
}
default:
break;
}
}
fieldsArray[i] = new TmfEventField(checkNotNull(fields[i]), val, null);
}
/*
* Generate the aspects for this trace if it is the 'set_aspects'
* definition
*/
if (fTrace.getDefinition() != fDefinition) {
generateAspects(fieldsArray);
return null;
}
/* Create a new event with new fields and name */
ITmfEventType customEventType = event.getType();
String eventName = getStringValue(content, EVENT_NAME_FIELD);
TmfEventType eventType = new TmfEventType(eventName, customEventType.getRootField());
ITmfEventField eventFields = new CustomEventContent(content.getName(), content.getValue(), fieldsArray);
/*
* TODO: Timestamps for these traces are in nanos, but since the
* CustomXmlTrace does not support this format, the timestamp of the
* original is in second and we need to convert it. We should do that at
* the source when it is supported
*/
TmfEvent newEvent = new TmfEvent(this, ITmfContext.UNKNOWN_RANK, event.getTimestamp(), eventType, eventFields);
updateAttributes(savedContext, event);
return newEvent;
}
use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.
the class TmfEventTableDataProvider method fetchIndex.
/**
* Find the index in the table of an event using the rank in the trace or
* the timestamp value. It will take any filter into consideration.
*
* @param fetchParameters
* Map of parameters that contain the filter applied to the
* table, if any. Everything else is ignored.
* @param traceRank
* Rank of the event in the trace
* @param timeBegin
* Timestamp of the event
* @param monitor
* Progress monitor
* @return Index in the table
*/
public TmfModelResponse<List<Long>> fetchIndex(Map<String, Object> fetchParameters, long traceRank, long timeBegin, @Nullable IProgressMonitor monitor) {
@Nullable ITmfFilter filter = extractFilter(fetchParameters);
long rank;
if (traceRank == -1) {
ITmfContext context = getTrace().seekEvent(TmfTimestamp.fromNanos(timeBegin));
rank = context.getRank();
} else {
rank = traceRank;
}
if (filter == null) {
return new TmfModelResponse<>(Collections.singletonList(rank), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
applyFilter(filter);
Entry<Long, Long> nearestEntry = fRankToIndexMap.floorEntry(rank);
long startingIndex = nearestEntry != null ? nearestEntry.getValue() : 0L;
long startingRank = nearestEntry != null ? nearestEntry.getKey() : 0L;
List<Long> foundIndex = new ArrayList<>();
TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, startingRank, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND) {
private long currentIndex = startingIndex;
private long fRank = startingRank;
@Override
public void handleData(ITmfEvent event) {
super.handleData(event);
if (monitor != null && monitor.isCanceled()) {
cancel();
return;
}
if (fRank >= rank) {
foundIndex.add(currentIndex);
done();
return;
}
if (filter.matches(event)) {
currentIndex++;
}
fRank++;
}
};
getTrace().sendRequest(request);
try {
request.waitForCompletion();
} catch (InterruptedException e) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, NonNullUtils.nullToEmptyString(e.getMessage()));
}
return new TmfModelResponse<>(foundIndex, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.
the class AbstractTmfStateProvider method processEvent.
@Override
public void processEvent(ITmfEvent event) {
/* Make sure the target state system has been assigned */
if (!fStateSystemAssigned) {
// $NON-NLS-1$
throw new IllegalStateException("Cannot process event without a target state system. ID: " + getClass().getSimpleName());
}
fPropagateExceptions.run();
/* Insert the event we're received into the events queue */
ITmfEvent curEvent = event;
fEventsQueue.put(curEvent);
}
use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.
the class ITmfTrace method readStart.
/**
* Read the start time of the trace quickly, without requiring it to be
* indexed.
*
* @return the trace's start time. Null if the trace is empty or failed.
* @since 3.0
*/
default ITmfTimestamp readStart() {
ITmfContext context = seekEvent(0L);
ITmfEvent event = getNext(context);
context.dispose();
return (event != null) ? event.getTimestamp() : null;
}
Aggregations