Search in sources :

Example 1 with CustomXmlEvent

use of org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent 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 2 with CustomXmlEvent

use of org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent in project tracecompass by tracecompass.

the class TmfTraceElement method instantiateEvent.

/**
 * Instantiate a <code>ITmfEvent</code> object based on the trace type and
 * the corresponding extension.
 *
 * @return the <code>ITmfEvent</code> or <code>null</code> for an error
 */
public ITmfEvent instantiateEvent() {
    try {
        String traceTypeId = getTraceType();
        if (traceTypeId != null) {
            if (CustomTxtTrace.isCustomTraceTypeId(traceTypeId)) {
                for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
                    String id = CustomTxtTrace.buildTraceTypeId(def.categoryName, def.definitionName);
                    if (traceTypeId.equals(id)) {
                        return new CustomTxtEvent(def);
                    }
                }
            }
            if (CustomXmlTrace.isCustomTraceTypeId(traceTypeId)) {
                for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
                    String id = CustomXmlTrace.buildTraceTypeId(def.categoryName, def.definitionName);
                    if (traceTypeId.equals(id)) {
                        return new CustomXmlEvent(def);
                    }
                }
            }
            IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(traceTypeId);
            if (ce == null) {
                return null;
            }
            ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
            return event;
        }
    } catch (CoreException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e);
    }
    return null;
}
Also used : CustomTxtEvent(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent) CustomXmlEvent(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent) CustomXmlTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition) CoreException(org.eclipse.core.runtime.CoreException) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) CustomTxtTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Aggregations

ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)2 CustomXmlEvent (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent)2 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 ITmfEventField (org.eclipse.tracecompass.tmf.core.event.ITmfEventField)1 ITmfEventType (org.eclipse.tracecompass.tmf.core.event.ITmfEventType)1 TmfEvent (org.eclipse.tracecompass.tmf.core.event.TmfEvent)1 TmfEventField (org.eclipse.tracecompass.tmf.core.event.TmfEventField)1 TmfEventType (org.eclipse.tracecompass.tmf.core.event.TmfEventType)1 CustomEventContent (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomEventContent)1 CustomTxtEvent (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent)1 CustomTxtTraceDefinition (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition)1 CustomXmlTraceDefinition (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition)1 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)1 TmfContext (org.eclipse.tracecompass.tmf.core.trace.TmfContext)1