Search in sources :

Example 1 with TmfEventField

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

the class CtfTmfEventTypeTest method testToString.

/**
 * Run the String toString() method test.
 */
@Test
public void testToString() {
    ITmfEventField emptyField = new TmfEventField("", null, new ITmfEventField[] {});
    CtfTmfEventType fixture = new CtfTmfEventType("", emptyField);
    String result = fixture.toString();
    assertEquals("", result);
}
Also used : ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) CtfTmfEventType(org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) TmfEventField(org.eclipse.tracecompass.tmf.core.event.TmfEventField) Test(org.junit.Test)

Example 2 with TmfEventField

use of org.eclipse.tracecompass.tmf.core.event.TmfEventField 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)

Example 3 with TmfEventField

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

the class CustomEvent method processData.

// ------------------------------------------------------------------------
// Other operations
// ------------------------------------------------------------------------
private void processData() {
    // Remove the values as they are processed, so we can process the extra values at the end
    String timestampString = fData.remove(Tag.TIMESTAMP);
    String timestampInputFormat = fData.remove(Key.TIMESTAMP_INPUT_FORMAT);
    ITmfTimestamp timestamp = null;
    if (timestampInputFormat != null && timestampString != null) {
        TmfTimestampFormat timestampFormat = new TmfTimestampFormat(timestampInputFormat);
        try {
            long time = timestampFormat.parseValue(timestampString);
            timestamp = TmfTimestamp.fromNanos(getTrace().getTimestampTransform().transform(time));
            setTimestamp(timestamp);
        } catch (ParseException e) {
            setTimestamp(TmfTimestamp.ZERO);
        }
    } else {
        setTimestamp(TmfTimestamp.ZERO);
    }
    // Update the custom event type of this event if set
    String eventName = fData.remove(Tag.EVENT_TYPE);
    ITmfEventType type = getType();
    if (eventName != null && type instanceof CustomEventType) {
        ((CustomEventType) type).setName(eventName);
    }
    Map<String, TmfEventField> fieldMap = new LinkedHashMap<>();
    for (OutputColumn outputColumn : fDefinition.outputs) {
        if (outputColumn.tag.equals(Tag.TIMESTAMP)) {
            if (timestamp != null && fDefinition.timeStampOutputFormat != null && !fDefinition.timeStampOutputFormat.isEmpty()) {
                TmfTimestampFormat timestampFormat = new TmfTimestampFormat(fDefinition.timeStampOutputFormat);
                fieldMap.put(outputColumn.name, new TmfEventField(outputColumn.name, timestampFormat.format(timestamp.getValue()), null));
            }
        } else if (outputColumn.tag.equals(Tag.OTHER) || outputColumn.tag.equals(Tag.MESSAGE)) {
            Object key = (outputColumn.tag.equals(Tag.OTHER) ? outputColumn.name : outputColumn.tag);
            fieldMap.put(outputColumn.name, new TmfEventField(outputColumn.name, nullToEmptyString(fData.remove(key)), null));
        }
    }
    // This event contains extra values, we process them now
    for (Entry<Object, String> entry : fData.entrySet()) {
        String fieldName = nullToEmptyString(entry.getKey().toString());
        // Ignore extra fields if a field of same name is already set
        if (!fieldMap.containsKey(fieldName)) {
            fieldMap.put(fieldName, new CustomExtraField(fieldName, nullToEmptyString(entry.getValue()), null));
        }
    }
    setContent(new CustomEventContent(customEventContent.getName(), customEventContent.getValue(), fieldMap.values().toArray(new ITmfEventField[fieldMap.size()])));
    fData = null;
}
Also used : CustomExtraField(org.eclipse.tracecompass.internal.tmf.core.parsers.custom.CustomExtraField) NonNullUtils.nullToEmptyString(org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString) ITmfEventType(org.eclipse.tracecompass.tmf.core.event.ITmfEventType) LinkedHashMap(java.util.LinkedHashMap) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) TmfEventField(org.eclipse.tracecompass.tmf.core.event.TmfEventField) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) TmfTimestampFormat(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat) OutputColumn(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn) ParseException(java.text.ParseException)

Example 4 with TmfEventField

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

the class CustomEventType method getRootField.

static ITmfEventField getRootField(CustomTraceDefinition definition) {
    ITmfEventField[] fields = new ITmfEventField[definition.outputs.size()];
    for (int i = 0; i < fields.length; i++) {
        fields[i] = new TmfEventField(definition.outputs.get(i).name, null, null);
    }
    ITmfEventField rootField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fields);
    return rootField;
}
Also used : ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) TmfEventField(org.eclipse.tracecompass.tmf.core.event.TmfEventField)

Example 5 with TmfEventField

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

the class BtfEventType method generateContent.

/**
 * Gets the event field values
 *
 * @param event
 *            the "event" payload
 * @param sourceInstance
 *            source instance
 * @param targetInstance
 *            target instance
 * @param notes
 *            optional notes (use null if no notes)
 * @return a field.
 * @since 2.2
 */
public ITmfEventField generateContent(String event, long sourceInstance, long targetInstance, @Nullable String notes) {
    // $NON-NLS-1$
    String notesString = notes == null ? "" : notes;
    TmfEventField retField;
    TmfEventField sourceInstanceField = new TmfEventField(BtfColumnNames.SOURCE_INSTANCE.toString(), sourceInstance, null);
    TmfEventField targetInstanceField = new TmfEventField(BtfColumnNames.TARGET_INSTANCE.toString(), targetInstance, null);
    TmfEventField eventField = new TmfEventField(BtfColumnNames.EVENT.toString(), event, BTFPayload.getFieldDescription(event));
    TmfEventField notesField = new TmfEventField(BtfColumnNames.NOTES.toString(), notesString, null);
    retField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, new TmfEventField[] { eventField, sourceInstanceField, targetInstanceField, notesField });
    return retField;
}
Also used : ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) TmfEventField(org.eclipse.tracecompass.tmf.core.event.TmfEventField)

Aggregations

TmfEventField (org.eclipse.tracecompass.tmf.core.event.TmfEventField)26 ITmfEventField (org.eclipse.tracecompass.tmf.core.event.ITmfEventField)24 Test (org.junit.Test)13 TmfEvent (org.eclipse.tracecompass.tmf.core.event.TmfEvent)5 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)4 ArrayList (java.util.ArrayList)3 ITmfEventType (org.eclipse.tracecompass.tmf.core.event.ITmfEventType)3 TmfEventType (org.eclipse.tracecompass.tmf.core.event.TmfEventType)3 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)3 CtfTmfEventType (org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType)3 EOFException (java.io.EOFException)2 IOException (java.io.IOException)2 RandomAccessFile (java.io.RandomAccessFile)2 Map (java.util.Map)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Packet (org.eclipse.tracecompass.internal.pcap.core.packet.Packet)2 PcapEventField (org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEventField)2 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1