Search in sources :

Example 1 with TmfEvent

use of org.eclipse.tracecompass.tmf.core.event.TmfEvent in project tracecompass by tracecompass.

the class CtfTmfCpuAspectTest method test.

/**
 * Test the cpu aspect
 */
@Test
public void test() {
    CtfCpuAspect fixture = new CtfCpuAspect();
    CtfTmfTrace trace = fTrace;
    assertNotNull(trace);
    CtfTmfEventFactory fabrica = CtfTmfEventFactory.instance();
    /*
         * Evaluate field, no stream
         */
    CtfTmfEvent e = fabrica.createEvent(trace, fEvents.get(0), "");
    assertEquals(Integer.valueOf(2), fixture.resolve(e));
    /*
         * Evaluate stream and field
         */
    e = fabrica.createEvent(trace, fEvents.get(1), "");
    assertEquals(Integer.valueOf(3), fixture.resolve(e));
    /*
         * Evaluate context
         */
    e = fabrica.createEvent(trace, fEvents.get(2), "");
    assertNull(fixture.resolve(e));
    /*
         * Evaluate an empty event
         */
    e = fabrica.createEvent(trace, fEvents.get(3), "");
    assertNull(fixture.resolve(e));
    /*
         * Evaluate stream and no field, default LTTng behaviour
         */
    e = fabrica.createEvent(trace, fEvents.get(4), "");
    assertEquals(Integer.valueOf(6), fixture.resolve(e));
    /*
         * Evaluate non-ctf event
         */
    assertNull(fixture.resolve(new TmfEvent(trace, 0, TmfTimestamp.BIG_BANG, null, null)));
}
Also used : CtfTmfEvent(org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent) TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) CtfTmfEvent(org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent) CtfCpuAspect(org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfCpuAspect) CtfTmfEventFactory(org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventFactory) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) Test(org.junit.Test)

Example 2 with TmfEvent

use of org.eclipse.tracecompass.tmf.core.event.TmfEvent in project tracecompass by tracecompass.

the class TmfEventTest method testHashCode.

// ------------------------------------------------------------------------
// hashCode
// ------------------------------------------------------------------------
@Test
public void testHashCode() {
    ITmfEvent event1 = new TmfEvent(fTrace, ITmfContext.UNKNOWN_RANK, null, null, null);
    ITmfEvent event2 = new TmfEvent(fTrace, ITmfContext.UNKNOWN_RANK, null, null, null);
    assertTrue("hashCode", event1.hashCode() == event2.hashCode());
    final ITmfTrace trace = fTrace;
    event1 = new TmfEvent(trace, 0, fTimestamp1, fType, fContent1);
    event2 = new TmfEvent(trace, 1, fTimestamp2, fType, fContent2);
    final ITmfEvent event1b = new TmfEvent(event1);
    final ITmfEvent event2b = new TmfEvent(event2);
    assertTrue("hashCode", event1.hashCode() == event1b.hashCode());
    assertTrue("hashCode", event2.hashCode() == event2b.hashCode());
    assertTrue("hashCode", event1.hashCode() != event2.hashCode());
    assertTrue("hashCode", event2.hashCode() != event1.hashCode());
    trace.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 3 with TmfEvent

use of org.eclipse.tracecompass.tmf.core.event.TmfEvent in project tracecompass by tracecompass.

the class MultiAspectTest method testResolve.

/**
 * Test the resolve of aspects.
 */
@Test
public void testResolve() {
    ITmfEventAspect<?> fMultiAspect0 = MultiAspect.create(ImmutableList.of(fAspectNull), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect1 = MultiAspect.create(ImmutableList.of(fAspect0), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect2 = MultiAspect.create(ImmutableList.of(fAspect1), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect3 = MultiAspect.create(ImmutableList.of(fAspectNull, fAspect0), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect4 = MultiAspect.create(ImmutableList.of(fAspectNull, fAspect1), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect5 = MultiAspect.create(ImmutableList.of(fAspect0, fAspect1), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect6 = MultiAspect.create(ImmutableList.of(fAspectNull, fAspect0, fAspect1), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect7 = MultiAspect.create(ImmutableList.of(fAspectNull, fAspect1, fAspect0), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect8 = MultiAspect.create(ImmutableList.of(fAspect0, fAspectNull), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect9 = MultiAspect.create(ImmutableList.of(fAspect1, fAspectNull), TmfCpuAspect.class);
    ITmfEventAspect<?> fMultiAspect10 = MultiAspect.create(ImmutableList.of(fAspect1, fAspect0), TmfCpuAspect.class);
    TmfEvent event = DUMMY_EVENT;
    assertNotNull(fMultiAspect0);
    assertNotNull(fMultiAspect1);
    assertNotNull(fMultiAspect2);
    assertNotNull(fMultiAspect3);
    assertNotNull(fMultiAspect4);
    assertNotNull(fMultiAspect5);
    assertNotNull(fMultiAspect6);
    assertNotNull(fMultiAspect7);
    assertNotNull(fMultiAspect8);
    assertNotNull(fMultiAspect9);
    assertNotNull(fMultiAspect10);
    assertEquals(null, fMultiAspect0.resolve(event));
    assertEquals(Integer.valueOf(0), fMultiAspect1.resolve(event));
    assertEquals(Integer.valueOf(1), fMultiAspect2.resolve(event));
    assertEquals(Integer.valueOf(0), fMultiAspect3.resolve(event));
    assertEquals(Integer.valueOf(1), fMultiAspect4.resolve(event));
    assertEquals(Integer.valueOf(0), fMultiAspect5.resolve(event));
    assertEquals(Integer.valueOf(0), fMultiAspect6.resolve(event));
    assertEquals(Integer.valueOf(1), fMultiAspect7.resolve(event));
    assertEquals(Integer.valueOf(0), fMultiAspect8.resolve(event));
    assertEquals(Integer.valueOf(1), fMultiAspect9.resolve(event));
    assertEquals(Integer.valueOf(1), fMultiAspect10.resolve(event));
}
Also used : TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Example 4 with TmfEvent

use of org.eclipse.tracecompass.tmf.core.event.TmfEvent in project tracecompass by tracecompass.

the class TmfAspectTest method testResolve.

/**
 * Test the resolve of aspects.
 */
@Test
public void testResolve() {
    TmfEvent event = new TmfEvent(null, -1, TmfTimestamp.BIG_BANG, null, null);
    assertEquals(Integer.valueOf(0), fAspect0.resolve(event));
    assertEquals(Integer.valueOf(1), fAspect1.resolve(event));
}
Also used : TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Example 5 with TmfEvent

use of org.eclipse.tracecompass.tmf.core.event.TmfEvent 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;
}
Also used : CustomXmlEvent(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent) TmfContext(org.eclipse.tracecompass.tmf.core.trace.TmfContext) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEventType(org.eclipse.tracecompass.tmf.core.event.ITmfEventType) CustomEventContent(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomEventContent) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) TmfEventField(org.eclipse.tracecompass.tmf.core.event.TmfEventField) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) TmfEventType(org.eclipse.tracecompass.tmf.core.event.TmfEventType) ITmfEventType(org.eclipse.tracecompass.tmf.core.event.ITmfEventType) Nullable(org.eclipse.jdt.annotation.Nullable)

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