tmf: Bug 509613: Trace Manager loses Linux trace context data
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 21 Dec 2016 20:40:24 +0000 (15:40 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 30 Dec 2016 13:17:22 +0000 (08:17 -0500)
The trace context classes are updated to provide a builder that can be
extended and that is used to create a duplicate of a trace context with
some data that can be modified.

Change-Id: Icd3de5891cb37976795f485c837ac2e0e66f5501
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/87588
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/trace/LinuxTraceContext.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTraceContext.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTraceManager.java

index e963ffbb93122b5dc85f1a954048ed5fbe1191e2..da8019cea44219ee253ce7f6e8b9fa6831e31029 100644 (file)
@@ -59,6 +59,20 @@ public class LinuxTraceContext extends TmfTraceContext {
         fTrace = trace;
     }
 
+    /**
+     * Constructs a new trace context with data taken from a builder.
+     *
+     * @param builder
+     *            the builder
+     * @since 2.2
+     */
+    public LinuxTraceContext(LinuxBuilder builder) {
+        super(builder);
+        fCpu = builder.cpu;
+        fTid = builder.tid;
+        fTrace = builder.trace;
+    }
+
     @Override
     public void receive(@NonNull TmfTraceModelSignal signal) {
         if (signal.getHostId().equals(fTrace.getHostId())) {
@@ -88,4 +102,42 @@ public class LinuxTraceContext extends TmfTraceContext {
         return fTid;
     }
 
+    @Override
+    public @NonNull Builder builder() {
+        return new LinuxBuilder(this);
+    }
+
+    /**
+     * A builder for creating trace context instances.
+     *
+     * @since 2.2
+     */
+    public class LinuxBuilder extends Builder {
+        private int cpu;
+        private int tid;
+        private ITmfTrace trace;
+
+        /**
+         * Constructor
+         *
+         * @param ctx
+         *            the trace context used to initialize the builder
+         */
+        public LinuxBuilder(LinuxTraceContext ctx) {
+            super(ctx);
+            this.cpu = ctx.fCpu;
+            this.tid = ctx.fTid;
+            this.trace = ctx.fTrace;
+        }
+
+        /**
+         * Build the trace context.
+         *
+         * @return a trace context
+         */
+        @Override
+        public TmfTraceContext build() {
+            return new LinuxTraceContext(this);
+        }
+    }
 }
index f87a88501b4c6d447b9f508241ea9e704150cc16..139cff30e47099b2ff42f25d5c7fd4f4feee0ea8 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
+ * Copyright (c) 2013, 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
@@ -48,7 +48,7 @@ public class TmfTraceContext implements ITraceContextSignalHandler {
     private final TmfTimeRange fWindowRange;
     private final @Nullable IFile fEditorFile;
     private final @Nullable ITmfFilter fFilter;
-    private final Map<@NonNull String, @NonNull Object> fData = new HashMap<>();
+    private final Map<@NonNull String, @NonNull Object> fData;
 
     /**
      * Build a new trace context.
@@ -68,7 +68,22 @@ public class TmfTraceContext implements ITraceContextSignalHandler {
         fWindowRange = windowRange;
         fEditorFile = editorFile;
         fFilter = filter;
-        fData.clear();
+        fData = new HashMap<>();
+    }
+
+    /**
+     * Constructs a new trace context with data taken from a builder.
+     *
+     * @param builder
+     *            the builder
+     * @since 2.3
+     */
+    public TmfTraceContext(Builder builder) {
+        fSelection = builder.selection;
+        fWindowRange = builder.windowRange;
+        fEditorFile = builder.editorFile;
+        fFilter = builder.filter;
+        fData = new HashMap<>(builder.data);
     }
 
     /**
@@ -153,6 +168,89 @@ public class TmfTraceContext implements ITraceContextSignalHandler {
         return ImmutableMap.copyOf(fData);
     }
 
+    /**
+     * Returns a new builder that is initialized with the data from this trace
+     * context.
+     *
+     * @return the builder
+     * @since 2.3
+     */
+    public Builder builder() {
+        return new Builder(this);
+    }
+
+    /**
+     * A builder for creating trace context instances.
+     *
+     * @since 2.3
+     */
+    public class Builder {
+        private TmfTimeRange selection;
+        private TmfTimeRange windowRange;
+        private @Nullable IFile editorFile;
+        private @Nullable ITmfFilter filter;
+        private Map<String, Object> data;
+
+        /**
+         * Constructor
+         *
+         * @param ctx
+         *            the trace context used to initialize the builder
+         */
+        public Builder(TmfTraceContext ctx) {
+            this.selection = ctx.fSelection;
+            this.windowRange = ctx.fWindowRange;
+            this.editorFile = ctx.fEditorFile;
+            this.filter = ctx.fFilter;
+            this.data = new HashMap<>(ctx.fData);
+        }
+
+        /**
+         * Build the trace context.
+         *
+         * @return a trace context
+         */
+        public TmfTraceContext build() {
+            return new TmfTraceContext(this);
+        }
+
+        /**
+         * Sets the selected time range.
+         *
+         * @param selection
+         *            the selected time range
+         * @return this {@code Builder} object
+         */
+        public Builder setSelection(TmfTimeRange selection) {
+            this.selection = selection;
+            return this;
+        }
+
+        /**
+         * Sets the window range.
+         *
+         * @param windowRange
+         *            the window range
+         * @return this {@code Builder} object
+         */
+        public Builder setWindowRange(TmfTimeRange windowRange) {
+            this.windowRange = windowRange;
+            return this;
+        }
+
+        /**
+         * Sets the current filter.
+         *
+         * @param filter
+         *            the current filter
+         * @return this {@code Builder} object
+         */
+        public Builder setFilter(@Nullable ITmfFilter filter) {
+            this.filter = filter;
+            return this;
+        }
+    }
+
     @Override
     public String toString() {
         return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$
index e5c862f45028d3f83c98595ea187fd6927e54c03..049c7ad83cb192412adda8e1937b83f7548cda8a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013, 2015 Ericsson
+ * Copyright (c) 2013, 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
@@ -368,17 +368,15 @@ public final class TmfTraceManager {
      */
     @TmfSignalHandler
     public synchronized void filterApplied(TmfEventFilterAppliedSignal signal) {
-        final ITmfTrace newTrace = signal.getTrace();
-        TmfTraceContext context = fTraces.get(newTrace);
+        final ITmfTrace trace = signal.getTrace();
+        TmfTraceContext context = fTraces.get(trace);
         if (context == null) {
             throw new RuntimeException();
         }
-        final TmfTraceContext newContext = newTrace.createTraceContext(context.getSelectionRange(),
-                context.getWindowRange(),
-                context.getEditorFile(),
-                signal.getEventFilter());
-        newContext.setData(context.getData());
-        fTraces.put(newTrace, newContext);
+        final TmfTraceContext newContext = context.builder()
+                .setFilter(signal.getEventFilter())
+                .build();
+        fTraces.put(trace, newContext);
     }
 
     /**
@@ -424,11 +422,9 @@ public final class TmfTraceManager {
                  * else the same as the previous trace context.
                  */
                 TmfTimeRange newSelectionRange = new TmfTimeRange(beginTs, endTs);
-                TmfTraceContext newCtx = trace.createTraceContext(newSelectionRange,
-                        prevCtx.getWindowRange(),
-                        prevCtx.getEditorFile(),
-                        prevCtx.getFilter());
-                newCtx.setData(prevCtx.getData());
+                TmfTraceContext newCtx = prevCtx.builder()
+                        .setSelection(newSelectionRange)
+                        .build();
                 entry.setValue(newCtx);
             }
         }
@@ -460,9 +456,9 @@ public final class TmfTraceManager {
             TmfTimeRange newWindowTr = (targetTr == null ? prevCtx.getWindowRange() : targetTr);
 
             /* Keep the values from the old context, except for the window range */
-            TmfTraceContext newCtx = trace.createTraceContext(prevCtx.getSelectionRange(),
-                    newWindowTr, prevCtx.getEditorFile(), prevCtx.getFilter());
-            newCtx.setData(prevCtx.getData());
+            TmfTraceContext newCtx = prevCtx.builder()
+                    .setWindowRange(newWindowTr)
+                    .build();
             entry.setValue(newCtx);
         }
     }
This page took 0.028017 seconds and 5 git commands to generate.