use of org.eclipse.tracecompass.tmf.core.event.TmfEvent in project tracecompass by tracecompass.
the class TmfEventTest method testNonEqualTraces.
@Test
public void testNonEqualTraces() {
final ITmfTrace trace1 = fTrace;
final ITmfTrace trace2 = STUB_TRACE.getTrace();
final ITmfEvent event1 = new TmfEvent(trace1, 0, fTimestamp1, fType, fContent1);
ITmfEvent event2 = new TmfEvent(trace1, 0, fTimestamp1, fType, fContent1);
assertTrue("equals", event1.equals(event2));
assertTrue("equals", event2.equals(event1));
event2 = new TmfEvent(trace2, 0, fTimestamp1, fType, fContent1);
assertFalse("equals", event1.equals(event2));
assertFalse("equals", event2.equals(event1));
trace2.dispose();
}
use of org.eclipse.tracecompass.tmf.core.event.TmfEvent in project tracecompass by tracecompass.
the class TmfUml2SDTestTrace method parseEvent.
@Override
public ITmfEvent parseEvent(ITmfContext context) {
if (!(fEventStream instanceof TmfTraceStub)) {
return null;
}
// Highly inefficient...
RandomAccessFile stream = ((TmfTraceStub) fEventStream).getStream();
// String name = eventStream.getName();
// name = name.substring(name.lastIndexOf('/') + 1);
long location = 0;
if (context != null) {
location = (Long) context.getLocation().getLocationInfo();
}
try {
stream.seek(location);
long ts = stream.readLong();
stream.readUTF();
/* Previously source, now unused */
String type = stream.readUTF();
stream.readUTF();
/* Previously reference, now unused */
String sender = stream.readUTF();
String receiver = stream.readUTF();
String signal = stream.readUTF();
String[] labels = { "sender", "receiver", "signal" };
TmfEventType tmfEventType = new TmfEventType(type, TmfEventField.makeRoot(labels));
String content = "[";
content += sender;
content += "," + receiver;
content += "," + signal;
content += "]";
// Pre-parse the content
TmfEventField[] fields = new TmfEventField[3];
fields[0] = new TmfEventField("sender", sender, null);
fields[1] = new TmfEventField("receiver", receiver, null);
fields[2] = new TmfEventField("signal", signal, null);
ITmfEventField tmfContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content, fields);
ITmfEvent tmfEvent = new TmfEvent(fEventStream, ITmfContext.UNKNOWN_RANK, TmfTimestamp.create(ts, -9), tmfEventType, tmfContent);
return tmfEvent;
} catch (final EOFException e) {
} catch (final IOException e) {
}
return null;
}
use of org.eclipse.tracecompass.tmf.core.event.TmfEvent in project tracecompass by tracecompass.
the class TmfEventParserStub method parseEvent.
@Override
public ITmfEvent parseEvent(final ITmfContext context) {
if (!(fEventStream instanceof TmfTraceStub)) {
return null;
}
// Highly inefficient...
final RandomAccessFile stream = ((TmfTraceStub) fEventStream).getStream();
if (stream == null) {
return null;
}
// String name = eventStream.getName();
// name = name.substring(name.lastIndexOf('/') + 1);
// no need to use synchronized since it's already cover by the calling method
long location = 0;
if (context != null && context.getLocation() != null) {
location = (Long) context.getLocation().getLocationInfo();
try {
stream.seek(location);
final long ts = stream.readLong();
stream.readUTF();
/* Previously source, now unused */
final String type = stream.readUTF();
stream.readInt();
/* Previously reference, now unused */
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(), null);
final ITmfEvent event = new TmfEvent(fEventStream, ITmfContext.UNKNOWN_RANK, fEventStream.createTimestamp(ts * 1000000L), fTypes[typeIndex], root);
return event;
} catch (final EOFException e) {
} catch (final IOException e) {
}
}
return null;
}
use of org.eclipse.tracecompass.tmf.core.event.TmfEvent in project tracecompass by tracecompass.
the class JsonStubTrace method parseEvent.
@Override
public ITmfEvent parseEvent(ITmfContext context) {
ITmfLocation location = context.getLocation();
if (location instanceof TmfLongLocation) {
TmfLongLocation tmfLongLocation = (TmfLongLocation) location;
Long locationInfo = tmfLongLocation.getLocationInfo();
if (location.equals(NULL_LOCATION)) {
locationInfo = 0L;
}
try {
if (!locationInfo.equals(fFileInput.getFilePointer())) {
fFileInput.seek(locationInfo);
}
String nextJson = readNextEventString(() -> fFileInput.read());
while (nextJson != null) {
JsonObject object = GSON.fromJson(nextJson, JsonObject.class);
// Ignore events with no timestamp, they are there just to make sure the traces
// parses in those cases
JsonElement tsElement = object.get(TIMESTAMP_KEY);
if (tsElement != null) {
long timestamp = tsElement.getAsLong();
return new TmfEvent(this, context.getRank(), TmfTimestamp.fromNanos(timestamp), new TmfEventType("JsonStubEvent", null), // $NON-NLS-1$
null);
}
nextJson = readNextEventString(() -> fFileInput.read());
}
} catch (IOException e) {
// Nothing to do
}
}
return null;
}
use of org.eclipse.tracecompass.tmf.core.event.TmfEvent in project tracecompass by tracecompass.
the class TmfEventTest method testEqualsSymmetry.
@Test
public void testEqualsSymmetry() {
final ITmfEvent event1 = new TmfEvent(fEvent1);
final ITmfEvent event2 = new TmfEvent(fEvent2);
assertTrue("equals", event1.equals(fEvent1));
assertTrue("equals", fEvent1.equals(event1));
assertTrue("equals", event2.equals(fEvent2));
assertTrue("equals", fEvent2.equals(event2));
}
Aggregations