tmf: Bug 497347: Custom event aspects incorrect in mixed experiments
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 5 Jul 2016 19:09:37 +0000 (15:09 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 20 Jul 2016 21:22:03 +0000 (17:22 -0400)
Change the custom event aspects to use TmfContentFieldAspect with the
field name. In a mixed experiment, fields from different custom trace
types with the same name will be combined in a single aspect.

Use the base aspect for the Event type if specified as a custom parser
output.

Remove the internal column data array in custom event, as its
information is stored in the event content.

Do not store the custom event type name as a content field, as it is
already stored in the custom event type.

Change-Id: Ic8b39672f0b6f27439774262791d249e6ecf24b1
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/76640
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/parsers/custom/CustomEventAspects.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomEvent.java

index b9f38e3a3b607809a5965d0ed49486858ec3e46d..5987f25ccabd60589a08aea8e8815a5579e17e7d 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2015 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
 
 package org.eclipse.tracecompass.internal.tmf.core.parsers.custom;
 
-import java.util.List;
-
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
-import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomEvent;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 
 import com.google.common.collect.ImmutableList;
 
@@ -38,47 +36,6 @@ import com.google.common.collect.ImmutableList;
  */
 public class CustomEventAspects {
 
-    /**
-     * Aspects for custom events, which use an integer ID to represent each
-     * field.
-     */
-    private static final class CustomEventFieldAspect implements ITmfEventAspect<String> {
-
-        private final @NonNull String fName;
-        private final int fIndex;
-
-        /**
-         * Constructor
-         *
-         * @param name
-         *            The name of this aspect
-         * @param idx
-         *            The index of this field in the event's content to display
-         */
-        public CustomEventFieldAspect(@NonNull String name, int idx) {
-            fName = name;
-            fIndex = idx;
-        }
-
-        @Override
-        public String getName() {
-            return fName;
-        }
-
-        @Override
-        public String getHelpText() {
-            return EMPTY_STRING;
-        }
-
-        @Override
-        public String resolve(ITmfEvent event) {
-            if (event instanceof CustomEvent) {
-                return NonNullUtils.nullToEmptyString(((CustomEvent) event).getEventString(fIndex));
-            }
-            return EMPTY_STRING;
-        }
-    }
-
     /**
      * Build a set of event aspects for a given trace definition
      *
@@ -89,10 +46,14 @@ public class CustomEventAspects {
      */
     public static @NonNull Iterable<ITmfEventAspect<?>> generateAspects(CustomTraceDefinition definition) {
         ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
-        List<OutputColumn> outputs = definition.outputs;
-        for (int i = 0; i < outputs.size(); i++) {
-            String name = outputs.get(i).name;
-            builder.add(new CustomEventFieldAspect(name, i));
+        for (OutputColumn output : definition.outputs) {
+            if (output.tag.equals(Tag.TIMESTAMP) && definition.timeStampOutputFormat == null) {
+                builder.add(TmfBaseAspects.getTimestampAspect());
+            } else if (output.tag.equals(Tag.EVENT_TYPE)) {
+                builder.add(TmfBaseAspects.getEventTypeAspect());
+            } else {
+                builder.add(new TmfContentFieldAspect(output.name, output.name));
+            }
         }
         return builder.build();
     }
index ef57420953934855c06785a72f47e9fefce65185..cc6b43302a865b38229815484a748edefed5a8c2 100644 (file)
 
 package org.eclipse.tracecompass.tmf.core.parsers.custom;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
+
 import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
@@ -31,6 +37,8 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 
+import com.google.common.collect.Iterables;
+
 /**
  * Base event for custom text parsers.
  *
@@ -72,8 +80,6 @@ public class CustomEvent extends TmfEvent {
      */
     protected Map<Object, String> fData;
 
-    private TmfEventField[] fColumnData;
-
     /**
      * Basic constructor.
      *
@@ -225,16 +231,16 @@ public class CustomEvent extends TmfEvent {
      *            The ID/index of the field to display. This corresponds to the
      *            index in the event content.
      * @return The String to display in the cell
+     * @deprecated Use {@link ITmfEventField#getField(String...)} instead.
      */
+    @Deprecated
     public String getEventString(int index) {
-        if (fData != null) {
-            processData();
-        }
-        if (index < 0 || index >= fColumnData.length) {
+        Collection<? extends ITmfEventField> fields = getContent().getFields();
+        if (index < 0 || index >= fields.size()) {
             return ""; //$NON-NLS-1$
         }
 
-        return fColumnData[index].getValue().toString();
+        return nullToEmptyString(checkNotNull(Iterables.get(fields, index)).getValue());
     }
 
     private void processData() {
@@ -261,19 +267,17 @@ public class CustomEvent extends TmfEvent {
             ((CustomEventType) type).setName(eventName);
         }
 
-        int i = 0;
-        fColumnData = new TmfEventField[fDefinition.outputs.size()];
+        List<ITmfEventField> fields = new ArrayList<>(fDefinition.outputs.size());
         for (OutputColumn outputColumn : fDefinition.outputs) {
             Object key = (outputColumn.tag.equals(Tag.OTHER) ? outputColumn.name : outputColumn.tag);
-            String value = fData.get(key);
             if (outputColumn.tag.equals(Tag.TIMESTAMP) && timestamp != null) {
                 TmfTimestampFormat timestampFormat = new TmfTimestampFormat(fDefinition.timeStampOutputFormat);
-                fColumnData[i++] = new TmfEventField(outputColumn.name, timestampFormat.format(timestamp.getValue()), null);
-            } else {
-                fColumnData[i++] = new TmfEventField(outputColumn.name, (value != null ? value : ""), null); //$NON-NLS-1$
+                fields.add(new TmfEventField(outputColumn.name, timestampFormat.format(timestamp.getValue()), null));
+            } else if (!outputColumn.tag.equals(Tag.EVENT_TYPE)){
+                fields.add(new TmfEventField(outputColumn.name, nullToEmptyString(fData.get(key)), null));
             }
         }
-        setContent(new CustomEventContent(customEventContent.getName(), customEventContent.getValue(), fColumnData));
+        setContent(new CustomEventContent(customEventContent.getName(), customEventContent.getValue(), fields.toArray(new ITmfEventField[0])));
         fData = null;
     }
 
This page took 0.02838 seconds and 5 git commands to generate.