/*******************************************************************************
- * Copyright (c) 2015 Ericsson
+ * Copyright (c) 2015, 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
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
-import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
import com.google.common.collect.HashMultimap;
* order before creating the time event lists as this is optimal for state
* system queries.
*
- * @since 2.0
+ * @since 1.1
*/
public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraphView {
// ------------------------------------------------------------------------
/** The state system to entry list hash map */
- private final Map<ITmfStateSystem, List<TimeGraphEntry>> fSSEntryListMap = new HashMap<>();
+ private final Map<ITmfStateSystem, List<@NonNull TimeGraphEntry>> fSSEntryListMap = new HashMap<>();
/** The trace to state system multi map */
private final Multimap<ITmfTrace, ITmfStateSystem> fTraceSSMap = HashMultimap.create();
+ private static final Logger LOGGER = TraceCompassLog.getLogger(AbstractStateSystemTimeGraphView.class);
+
// ------------------------------------------------------------------------
// Classes
// ------------------------------------------------------------------------
}
@Override
- public void run() {
+ public void doRun() {
final List<ILinkEvent> links = new ArrayList<>();
+ final List<IMarkerEvent> markers = new ArrayList<>();
if (fClearZoomedLists) {
clearZoomedLists();
}
entryList = fSSEntryListMap.get(ss);
}
if (entryList != null) {
- zoomByTime(ss, entryList, links, getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
+ zoomByTime(ss, entryList, links, markers, getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
}
}
if (!getMonitor().isCanceled()) {
- getTimeGraphViewer().setLinks(links);
+ /* Refresh the trace-specific markers when zooming */
+ markers.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
+ applyResults(() -> {
+ getTimeGraphViewer().setLinks(links);
+ getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
+ getTimeGraphViewer().setMarkers(markers);
+ });
+ } else {
+ LOGGER.info(() -> "[TimeGraphView:ZoomThreadCanceled]"); //$NON-NLS-1$
}
}
}
}
- private void zoomByTime(final ITmfStateSystem ss, final List<TimeGraphEntry> entryList, final List<ILinkEvent> links,
+ private void zoomByTime(final ITmfStateSystem ss, final List<TimeGraphEntry> entryList, final List<ILinkEvent> links, final List<IMarkerEvent> markers,
long startTime, long endTime, long resolution, final @NonNull IProgressMonitor monitor) {
final long start = Math.max(startTime, ss.getStartTime());
final long end = Math.min(endTime, ss.getCurrentEndTime());
queryFullStates(ss, start, end, resolution, monitor, new IQueryHandler() {
@Override
public void handle(@NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState) {
+ LOGGER.config(() -> "[TimeGraphView:ZoomThreadGettingStates]"); //$NON-NLS-1$
if (!fullRange) {
for (TimeGraphEntry entry : entryList) {
zoom(checkNotNull(entry), ss, fullStates, prevFullState, monitor);
}
}
/* Refresh the arrows when zooming */
- links.addAll(getLinkList(ss, fullStates, monitor));
+ LOGGER.config(() -> "[TimeGraphView:ZoomThreadGettingLinks]"); //$NON-NLS-1$
+ links.addAll(getLinkList(ss, fullStates, prevFullState, monitor));
+ /* Refresh the view-specific markers when zooming */
+ LOGGER.config(() -> "[TimeGraphView:ZoomThreadGettingMarkers]"); //$NON-NLS-1$
+ markers.addAll(getViewMarkerList(ss, fullStates, prevFullState, monitor));
+ LOGGER.config(() -> "[TimeGraphView:ZoomThreadDone]"); //$NON-NLS-1$
}
});
refresh();
private void zoom(@NonNull TimeGraphEntry entry, ITmfStateSystem ss, @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) {
List<ITimeEvent> eventList = getEventList(entry, ss, fullStates, prevFullState, monitor);
if (eventList != null) {
- for (ITimeEvent event : eventList) {
- entry.addZoomedEvent(event);
- }
+ applyResults(() -> {
+ for (ITimeEvent event : eventList) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ entry.addZoomedEvent(event);
+ }
+ });
}
- for (ITimeGraphEntry child : entry.getChildren()) {
+ for (TimeGraphEntry child : entry.getChildren()) {
if (monitor.isCanceled()) {
+ LOGGER.info(() -> "[TimeGraphView:ZoomThreadCanceled]"); //$NON-NLS-1$
return;
}
- if (child instanceof TimeGraphEntry) {
- zoom((TimeGraphEntry) child, ss, fullStates, prevFullState, monitor);
- }
+ zoom(child, ss, fullStates, prevFullState, monitor);
}
}
private void clearZoomedList(TimeGraphEntry entry) {
entry.setZoomedEventList(null);
- for (ITimeGraphEntry child : entry.getChildren()) {
- if (child instanceof TimeGraphEntry) {
- clearZoomedList((TimeGraphEntry) child);
- }
+ for (TimeGraphEntry child : entry.getChildren()) {
+ clearZoomedList(child);
}
}
}
*
* @return the entry list map
*/
- protected List<TimeGraphEntry> getEntryList(ITmfStateSystem ss) {
+ protected List<@NonNull TimeGraphEntry> getEntryList(ITmfStateSystem ss) {
synchronized (fSSEntryListMap) {
return fSSEntryListMap.get(ss);
}
* @param list
* the list of time graph entries
*/
- protected void putEntryList(ITmfTrace trace, ITmfStateSystem ss, List<TimeGraphEntry> list) {
+ protected void putEntryList(ITmfTrace trace, ITmfStateSystem ss, List<@NonNull TimeGraphEntry> list) {
super.putEntryList(trace, list);
synchronized (fSSEntryListMap) {
fSSEntryListMap.put(ss, new CopyOnWriteArrayList<>(list));
* @param list
* the list of time graph entries to add
*/
- protected void addToEntryList(ITmfTrace trace, ITmfStateSystem ss, List<TimeGraphEntry> list) {
+ protected void addToEntryList(ITmfTrace trace, ITmfStateSystem ss, List<@NonNull TimeGraphEntry> list) {
super.addToEntryList(trace, list);
synchronized (fSSEntryListMap) {
- List<TimeGraphEntry> entryList = fSSEntryListMap.get(ss);
+ List<@NonNull TimeGraphEntry> entryList = fSSEntryListMap.get(ss);
if (entryList == null) {
fSSEntryListMap.put(ss, new CopyOnWriteArrayList<>(list));
} else {
/**
* Gets the list of events for an entry for a given list of full states.
+ * <p>
+ * Called from the ZoomThread for every entry to update the zoomed event
+ * list. Can be an empty implementation if the view does not support zoomed
+ * event lists. Can also be used to compute the full event list.
*
* @param tgentry
* The time graph entry
* The state system
* @param fullStates
* A list of full states
+ * @param prevFullState
+ * The previous full state, or null
* @param monitor
* A progress monitor
* @return The list of link events
+ * @since 2.0
*/
protected @NonNull List<ILinkEvent> getLinkList(ITmfStateSystem ss,
- @NonNull List<List<ITmfStateInterval>> fullStates, @NonNull IProgressMonitor monitor) {
+ @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) {
+ return new ArrayList<>();
+ }
+
+ /**
+ * Gets the list of markers for a given list of full
+ * states. The default implementation returns an empty list.
+ *
+ * @param ss
+ * The state system
+ * @param fullStates
+ * A list of full states
+ * @param prevFullState
+ * The previous full state, or null
+ * @param monitor
+ * A progress monitor
+ * @return The list of marker events
+ * @since 2.0
+ */
+ protected @NonNull List<IMarkerEvent> getViewMarkerList(ITmfStateSystem ss,
+ @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) {
return new ArrayList<>();
}
}
/**
- * @deprecated The subclass should implement {@link #getLinkList(ITmfStateSystem, List, IProgressMonitor)} instead.
+ * @deprecated The subclass should implement {@link #getLinkList(ITmfStateSystem, List, List, IProgressMonitor)} instead.
*/
@Deprecated
@Override
throw new UnsupportedOperationException();
}
- // ------------------------------------------------------------------------
- // Signal handlers
- // ------------------------------------------------------------------------
+ /**
+ * @deprecated The subclass should implement {@link #getViewMarkerList(ITmfStateSystem, List, List, IProgressMonitor)} instead.
+ */
+ @Deprecated
+ @Override
+ protected final List<IMarkerEvent> getViewMarkerList(long startTime, long endTime, long resolution, IProgressMonitor monitor) {
+ throw new UnsupportedOperationException();
+ }
- @TmfSignalHandler
@Override
- public void traceClosed(final TmfTraceClosedSignal signal) {
- super.traceClosed(signal);
+ protected void resetView(ITmfTrace viewTrace) {
+ // Don't remove super call
+ super.resetView(viewTrace);
synchronized (fSSEntryListMap) {
- for (ITmfStateSystem ss : fTraceSSMap.removeAll(signal.getTrace())) {
+ for (ITmfStateSystem ss : fTraceSSMap.removeAll(viewTrace)) {
fSSEntryListMap.remove(ss);
}
}