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;
/**
* @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
* 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();
}
/**
public int getCore() {
return fCore;
}
-
- /**
- * Get the trace host id
- *
- * @return the trace host id
- */
- public String getHostId() {
- return fHostId;
- }
}
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;
/**
* @author Matthew Khouzam
* @since 2.0
*/
-public class TmfThreadSelectedSignal extends TmfSignal {
+public class TmfThreadSelectedSignal extends TmfTraceModelSignal {
private final HostThread fHostThread;
* the trace
*/
public TmfThreadSelectedSignal(Object source, int threadId, ITmfTrace trace) {
- super(source);
+ super(source, 0, trace.getHostId());
fHostThread = new HostThread(trace.getHostId(), threadId);
}
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.
* @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);
+ }
}
--- /dev/null
+/*******************************************************************************
+ * 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;
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * 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;
+ }
+
+}
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;
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;
*/
@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);
+ }
}
--- /dev/null
+/*******************************************************************************
+ * 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
* @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;
return fWindowRange;
}
-
/**
* Get the editor's file
*
return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$
", fWindowRange=" + fWindowRange + ']'; //$NON-NLS-1$
}
+
}
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;
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);
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.
*
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()));
* 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());
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);
}