tmf.core: Add cpu and thread to trace context
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 16 Feb 2016 03:51:22 +0000 (22:51 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 16 Mar 2016 01:44:29 +0000 (21:44 -0400)
This patch allows to see what the last selected cpu and thread were
for a given trace. The cpu and thread are stores in a LinuxTraceContext.

To do this, a default method is introduced to ITmfTrace (createTraceContext).
This method is overridden by IKernelTrace to make LinuxTraceContext instead of
the regular TmfTraceContexts. The LinuxTrace Context has the CPU and Thread ID
information. An important thing to note is that if two kernel traces have the same
hostID they both get the signal. This is by design.

Change-Id: I25f044ec05fbd69acf93009861b464506327d616
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/66667
Reviewed-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/signals/TmfCpuSelectedSignal.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/signals/TmfThreadSelectedSignal.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/trace/IKernelTrace.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/trace/LinuxTraceContext.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/signal/TmfTraceModelSignal.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/ITmfTrace.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/ITraceContextSignalHandler.java [new file with mode: 0644]
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 5d7904181a6b680cb1060fdae15640cfe8bcc5dc..07c5af0b98109dbbacbe157c924a24f04c37de39 100644 (file)
@@ -9,7 +9,7 @@
 
 package org.eclipse.tracecompass.analysis.os.linux.core.signals;
 
-import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceModelSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 
 /**
@@ -18,10 +18,9 @@ import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
  * @author Matthew Khouzam
  * @since 2.0
  */
-public class TmfCpuSelectedSignal extends TmfSignal {
+public class TmfCpuSelectedSignal extends TmfTraceModelSignal {
 
     private final int fCore;
-    private final String fHostId;
 
     /**
      * Constructor
@@ -34,9 +33,8 @@ public class TmfCpuSelectedSignal extends TmfSignal {
      *            the current trace that the cpu belongs to
      */
     public TmfCpuSelectedSignal(Object source, int core, ITmfTrace trace) {
-        super(source);
+        super(source, 0, trace.getHostId());
         fCore = core;
-        fHostId = trace.getHostId();
     }
 
     /**
@@ -47,13 +45,4 @@ public class TmfCpuSelectedSignal extends TmfSignal {
     public int getCore() {
         return fCore;
     }
-
-    /**
-     * Get the trace host id
-     *
-     * @return the trace host id
-     */
-    public String getHostId() {
-        return fHostId;
-    }
 }
index 2f964b84a76aac76e2ed673205c00ac25a763f42..ae1e9c2ecfe078972987005608b93bf3aca6d389 100644 (file)
@@ -10,7 +10,7 @@
 package org.eclipse.tracecompass.analysis.os.linux.core.signals;
 
 import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread;
-import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceModelSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 
 /**
@@ -19,7 +19,7 @@ import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
  * @author Matthew Khouzam
  * @since 2.0
  */
-public class TmfThreadSelectedSignal extends TmfSignal {
+public class TmfThreadSelectedSignal extends TmfTraceModelSignal {
 
     private final HostThread fHostThread;
 
@@ -34,7 +34,7 @@ public class TmfThreadSelectedSignal extends TmfSignal {
      *            the trace
      */
     public TmfThreadSelectedSignal(Object source, int threadId, ITmfTrace trace) {
-        super(source);
+        super(source, 0, trace.getHostId());
         fHostThread = new HostThread(trace.getHostId(), threadId);
     }
 
index 92a07bfa1749321b6f20b2cc1509d30c526b57e9..835d25d53f502f6fffef8bab6343deb5820b4353 100644 (file)
 
 package org.eclipse.tracecompass.analysis.os.linux.core.trace;
 
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
 
 /**
  * Trace type that represents a Linux kernel trace.
@@ -31,4 +36,10 @@ public interface IKernelTrace extends ITmfTrace {
      * @return The event layout
      */
     IKernelAnalysisEventLayout getKernelEventLayout();
+
+    /** @since 2.0 */
+    @Override
+    default TmfTraceContext createTraceContext(TmfTimeRange selection, TmfTimeRange windowRange, @Nullable IFile editorFile, @Nullable ITmfFilter filter) {
+        return new LinuxTraceContext(selection, windowRange, editorFile, filter, this);
+    }
 }
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/trace/LinuxTraceContext.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/trace/LinuxTraceContext.java
new file mode 100644 (file)
index 0000000..e963ffb
--- /dev/null
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 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 accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.analysis.os.linux.core.trace;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.analysis.os.linux.core.signals.TmfCpuSelectedSignal;
+import org.eclipse.tracecompass.analysis.os.linux.core.signals.TmfThreadSelectedSignal;
+import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceModelSignal;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
+
+/**
+ * A Linux trace context is a context that stores OS related actions as well as
+ * the regular context of a trace (window time range, selected time or time
+ * range).
+ *
+ * @author Matthew Khouzam
+ * @since 2.0
+ */
+public class LinuxTraceContext extends TmfTraceContext {
+
+    /** An invalid CPU */
+    public static final int INVALID_CPU = -1;
+    /** An invalid thread id */
+    public static final int INVALID_THREAD_ID = -1;
+
+    private int fCpu = INVALID_CPU;
+    private int fTid = INVALID_THREAD_ID;
+    private final ITmfTrace fTrace;
+
+    /**
+     * Build a new trace context.
+     *
+     * @param selection
+     *            The selected time range
+     * @param windowRange
+     *            The visible window's time range
+     * @param editorFile
+     *            The file representing the selected editor
+     * @param filter
+     *            The currently applied filter. 'null' for none.
+     * @param trace
+     *            the trace
+     * @since 2.0
+     */
+    public LinuxTraceContext(TmfTimeRange selection, TmfTimeRange windowRange, @Nullable IFile editorFile, @Nullable ITmfFilter filter, ITmfTrace trace) {
+        super(selection, windowRange, editorFile, filter);
+        fTrace = trace;
+    }
+
+    @Override
+    public void receive(@NonNull TmfTraceModelSignal signal) {
+        if (signal.getHostId().equals(fTrace.getHostId())) {
+            if (signal instanceof TmfThreadSelectedSignal) {
+                fTid = ((TmfThreadSelectedSignal) signal).getThreadId();
+            } else if (signal instanceof TmfCpuSelectedSignal) {
+                fCpu = ((TmfCpuSelectedSignal) signal).getCore();
+            }
+        }
+    }
+
+    /**
+     * Get the current CPU
+     *
+     * @return the current CPU, can be {@link #INVALID_CPU}
+     */
+    public int getCpu() {
+        return fCpu;
+    }
+
+    /**
+     * Get the current thread ID
+     *
+     * @return the current thread ID, can be {@link #INVALID_THREAD_ID}
+     */
+    public int getTid() {
+        return fTid;
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/signal/TmfTraceModelSignal.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/signal/TmfTraceModelSignal.java
new file mode 100644 (file)
index 0000000..b86cd45
--- /dev/null
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.signal;
+
+/**
+ * Base class for TMF signals for a given host, broadcast in a context that
+ * involves the trace itself or rather the system model represented by the trace
+ * (CPU, thread), as opposed to other signals related to the traceCompass
+ * signals (actions on trace, times, analyses).
+ *
+ * @author Matthew Khouzam
+ * @since 2.0
+ */
+public abstract class TmfTraceModelSignal extends TmfSignal {
+
+    private final String fHostId;
+
+    /**
+     * Standard constructor
+     *
+     * @param source
+     *            Object sending this signal
+     * @param reference
+     *            Reference index to assign to this signal
+     * @param host
+     *            the host id
+     */
+    public TmfTraceModelSignal(Object source, int reference, String host) {
+        super(source, reference);
+        fHostId = host;
+    }
+
+    /**
+     * Gets a trace host id
+     *
+     * @return the host id
+     */
+    public String getHostId() {
+        return fHostId;
+    }
+
+}
index 01e326072c42865740be5ed1a5db8b5e5984e74c..d00e6914978b1ccc5b9e5f6624c3f4219397b663 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.eclipse.tracecompass.tmf.core.trace;
 
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IStatus;
@@ -26,6 +27,7 @@ import org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
 import org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
@@ -428,4 +430,21 @@ public interface ITmfTrace extends ITmfEventProvider {
      */
     @NonNull ITmfTimestamp createTimestamp(long ts);
 
+    /**
+     * Build a new trace context.
+     *
+     * @param selection
+     *            The selected time range
+     * @param windowRange
+     *            The visible window's time range
+     * @param editorFile
+     *            The file representing the selected editor
+     * @param filter
+     *            The currently applied filter. 'null' for none.
+     * @return The newly created context
+     * @since 2.0
+     */
+    default TmfTraceContext createTraceContext(@NonNull TmfTimeRange selection, @NonNull TmfTimeRange windowRange, @Nullable IFile editorFile, @Nullable ITmfFilter filter) {
+        return new TmfTraceContext(selection, windowRange, editorFile, filter);
+    }
 }
diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/ITraceContextSignalHandler.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/ITraceContextSignalHandler.java
new file mode 100644 (file)
index 0000000..8d1c93a
--- /dev/null
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 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 accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.trace;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceModelSignal;
+
+/**
+ * Signal handler for all the {@link TmfTraceModelSignal} handling
+ *
+ * @author Matthew Khouzam
+ * @since 2.0
+ *
+ */
+public interface ITraceContextSignalHandler {
+
+    /**
+     * Receive a signal and handle it
+     *
+     * @param signal
+     *            signal to receive
+     */
+    default void receive(@NonNull TmfTraceModelSignal signal) {
+        // do nothing
+    }
+
+}
\ No newline at end of file
index e13a3b0c0eaf762438262e4b729f03b1a5c9fc12..a9ae5238746b0d5258cf0937448f2da22f9bbd99 100644 (file)
@@ -33,11 +33,10 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
  * @since 1.0
  */
 @NonNullByDefault
-public final class TmfTraceContext {
+public class TmfTraceContext implements ITraceContextSignalHandler {
 
-    static final TmfTraceContext NULL_CONTEXT =
-            new TmfTraceContext(new TmfTimeRange(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH),
-                    TmfTimeRange.NULL_RANGE, null, null);
+    static final TmfTraceContext NULL_CONTEXT = new TmfTraceContext(new TmfTimeRange(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH),
+            TmfTimeRange.NULL_RANGE, null, null);
 
     private final TmfTimeRange fSelection;
     private final TmfTimeRange fWindowRange;
@@ -82,7 +81,6 @@ public final class TmfTraceContext {
         return fWindowRange;
     }
 
-
     /**
      * Get the editor's file
      *
@@ -106,4 +104,5 @@ public final class TmfTraceContext {
         return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$
                 ", fWindowRange=" + fWindowRange + ']'; //$NON-NLS-1$
     }
+
 }
index 25eaffe28257dbcf4c42b9b6d46b895c9bec62bb..137c7b9af75d75f374404888ac2b627ed7b7cf08 100644 (file)
@@ -37,6 +37,7 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
 import org.eclipse.tracecompass.tmf.core.signal.TmfEventFilterAppliedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceModelSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
@@ -286,7 +287,7 @@ public final class TmfTraceManager {
         final TmfTimeRange selectionRange = new TmfTimeRange(startTs, startTs);
         final TmfTimeRange windowRange = new TmfTimeRange(startTs, new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE));
 
-        final TmfTraceContext startCtx = new TmfTraceContext(selectionRange, windowRange, editorFile, null);
+        final TmfTraceContext startCtx = trace.createTraceContext(selectionRange, windowRange, editorFile, null);
 
         fTraces.put(trace, startCtx);
 
@@ -294,6 +295,17 @@ public final class TmfTraceManager {
         fCurrentTrace = trace;
     }
 
+    /**
+     * Signal propagator
+     * @param signal any signal
+     * @since 2.0
+     */
+    @TmfSignalHandler
+    public synchronized void signalReceived(final TmfTraceModelSignal signal) {
+        fTraces.forEach((t, u) -> u.receive(signal));
+    }
+
+
     /**
      * Handler for the TmfTraceSelectedSignal.
      *
@@ -322,7 +334,7 @@ public final class TmfTraceManager {
         if (context == null) {
             throw new RuntimeException();
         }
-        fTraces.put(newTrace, new TmfTraceContext(context.getSelectionRange(),
+        fTraces.put(newTrace, newTrace.createTraceContext(context.getSelectionRange(),
                 context.getWindowRange(),
                 context.getEditorFile(),
                 signal.getEventFilter()));
@@ -371,7 +383,7 @@ public final class TmfTraceManager {
                  * else the same as the previous trace context.
                  */
                 TmfTimeRange newSelectionRange = new TmfTimeRange(beginTs, endTs);
-                TmfTraceContext newCtx = new TmfTraceContext(newSelectionRange,
+                TmfTraceContext newCtx = trace.createTraceContext(newSelectionRange,
                         prevCtx.getWindowRange(),
                         prevCtx.getEditorFile(),
                         prevCtx.getFilter());
@@ -406,7 +418,7 @@ 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 = new TmfTraceContext(prevCtx.getSelectionRange(),
+            TmfTraceContext newCtx = trace.createTraceContext(prevCtx.getSelectionRange(),
                     newWindowTr, prevCtx.getEditorFile(), prevCtx.getFilter());
             entry.setValue(newCtx);
         }
This page took 0.034253 seconds and 5 git commands to generate.