Search in sources :

Example 11 with TmfEvent

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();
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Example 12 with TmfEvent

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;
}
Also used : ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) IOException(java.io.IOException) TmfTraceStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) RandomAccessFile(java.io.RandomAccessFile) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) TmfEventField(org.eclipse.tracecompass.tmf.core.event.TmfEventField) TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfEventType(org.eclipse.tracecompass.tmf.core.event.TmfEventType) EOFException(java.io.EOFException)

Example 13 with TmfEvent

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;
}
Also used : RandomAccessFile(java.io.RandomAccessFile) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) TmfEventField(org.eclipse.tracecompass.tmf.core.event.TmfEventField) TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) EOFException(java.io.EOFException) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) IOException(java.io.IOException)

Example 14 with TmfEvent

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;
}
Also used : TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) JsonElement(com.google.gson.JsonElement) TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfEventType(org.eclipse.tracecompass.tmf.core.event.TmfEventType) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ITmfLocation(org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation)

Example 15 with TmfEvent

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));
}
Also used : TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Aggregations

TmfEvent (org.eclipse.tracecompass.tmf.core.event.TmfEvent)21 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)19 Test (org.junit.Test)16 ITmfEventField (org.eclipse.tracecompass.tmf.core.event.ITmfEventField)5 TmfEventField (org.eclipse.tracecompass.tmf.core.event.TmfEventField)5 TmfEventType (org.eclipse.tracecompass.tmf.core.event.TmfEventType)5 IOException (java.io.IOException)3 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)3 EOFException (java.io.EOFException)2 RandomAccessFile (java.io.RandomAccessFile)2 ITmfEventType (org.eclipse.tracecompass.tmf.core.event.ITmfEventType)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)1 CustomEventContent (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomEventContent)1 CustomXmlEvent (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent)1 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)1 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)1