tmf: Update AbstractTimeGraphView and TimeGraphEntry API
authorPatrick Tasse <patrick.tasse@gmail.com>
Thu, 7 Apr 2016 22:13:55 +0000 (18:13 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 13 Apr 2016 22:16:58 +0000 (18:16 -0400)
AbstractTimeGraphView.buildEventList() is renamed to buildEntryList()
which is more representative of its implementation. The Javadoc of this
method and getEventList() is improved to better explain their use.

TimeGraphEntry methods setParent(), getParent(), getChildren() and
addChild(...) are changed to restrict the entries to TimeGraphEntry.
This avoids instanceof checks in AbstractTimeGraphView implementations,
and avoids unexpected behavior in case a child or parent entry is not of
type TimeGraphEntry.

Change-Id: Ibf1c3f3fad467ab7ff215fd2552bb3350f00ef7e
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/70185
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.graph.ui/src/org/eclipse/tracecompass/internal/analysis/graph/ui/criticalpath/view/CriticalPathView.java
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/controlflow/ControlFlowView.java
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/resources/ResourcesView.java
lttng/org.eclipse.tracecompass.lttng2.kernel.ui/src/org/eclipse/tracecompass/internal/lttng2/kernel/ui/views/vm/vcpuview/VirtualMachineView.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractStateSystemTimeGraphView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java

index 67a5bfe4fc2f7f4bf398fa1dbcc0c4b4594802e5..e716284d5de6281f0764941be616dc2aedf6827c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2015 École Polytechnique de Montréal
+ * Copyright (c) 2015, 2016 École Polytechnique de Montréal
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -468,7 +468,7 @@ public class CriticalPathView extends AbstractTimeGraphView {
     }
 
     @Override
-    protected void buildEventList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor) {
+    protected void buildEntryList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor) {
         /* This class uses a content provider instead */
     }
 
index c31fd207797655cd8364f9c2507c8ca7e822d883..822685c070d5f6ecd789675c869181a5c6a87fb1 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal and others.
+ * Copyright (c) 2012, 2016 Ericsson, École Polytechnique de Montréal and others.
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -246,7 +246,7 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
     // ------------------------------------------------------------------------
 
     @Override
-    protected void buildEventList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) {
+    protected void buildEntryList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) {
         final ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
         if (ssq == null) {
             return;
index a760e4dbbf37b504288c7ff257bff925ee351ce6..933470ae1479bfc67275c551d65e26f84f0ff9b6 100644 (file)
@@ -155,7 +155,7 @@ public class ResourcesView extends AbstractStateSystemTimeGraphView {
     }
 
     @Override
-    protected void buildEventList(ITmfTrace trace, ITmfTrace parentTrace, final IProgressMonitor monitor) {
+    protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, final IProgressMonitor monitor) {
         final ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
         if (ssq == null) {
             return;
@@ -196,34 +196,31 @@ public class ResourcesView extends AbstractStateSystemTimeGraphView {
             if (parentTrace.equals(getTrace())) {
                 refresh();
             }
-            final List<? extends ITimeGraphEntry> traceEntryChildren = traceEntry.getChildren();
+            final List<@NonNull TimeGraphEntry> traceEntryChildren = traceEntry.getChildren();
             final long resolution = Math.max(1, (endTime - ssq.getStartTime()) / getDisplayWidth());
             final long qStart = start;
             final long qEnd = end;
             queryFullStates(ssq, qStart, qEnd, resolution, monitor, new IQueryHandler() {
                 @Override
                 public void handle(List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState) {
-                    for (ITimeGraphEntry child : traceEntryChildren) {
+                    for (TimeGraphEntry child : traceEntryChildren) {
                         if (!populateEventsRecursively(fullStates, prevFullState, child).isOK()) {
                             return;
                         }
                     }
                 }
 
-                private IStatus populateEventsRecursively(@NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, ITimeGraphEntry entry) {
+                private IStatus populateEventsRecursively(@NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull TimeGraphEntry entry) {
                     if (monitor.isCanceled()) {
                         return Status.CANCEL_STATUS;
                     }
-                    if (entry instanceof TimeGraphEntry) {
-                        TimeGraphEntry timeGraphEntry = (TimeGraphEntry) entry;
-                        List<ITimeEvent> eventList = getEventList(timeGraphEntry, ssq, fullStates, prevFullState, monitor);
-                        if (eventList != null) {
-                            for (ITimeEvent event : eventList) {
-                                timeGraphEntry.addEvent(event);
-                            }
+                    List<ITimeEvent> eventList = getEventList(entry, ssq, fullStates, prevFullState, monitor);
+                    if (eventList != null) {
+                        for (ITimeEvent event : eventList) {
+                            entry.addEvent(event);
                         }
                     }
-                    for (ITimeGraphEntry child : entry.getChildren()) {
+                    for (TimeGraphEntry child : entry.getChildren()) {
                         IStatus status = populateEventsRecursively(fullStates, prevFullState, child);
                         if (!status.isOK()) {
                             return status;
@@ -339,7 +336,7 @@ public class ResourcesView extends AbstractStateSystemTimeGraphView {
         return null;
     }
 
-    private static List<ITimeEvent> createCpuEventsList(TimeGraphEntry entry, ITmfStateSystem ssq, List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState, IProgressMonitor monitor, int quark) {
+    private static List<ITimeEvent> createCpuEventsList(ITimeGraphEntry entry, ITmfStateSystem ssq, List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState, IProgressMonitor monitor, int quark) {
         List<ITimeEvent> eventList;
         int statusQuark;
         try {
@@ -384,7 +381,7 @@ public class ResourcesView extends AbstractStateSystemTimeGraphView {
         return eventList;
     }
 
-    private static List<ITimeEvent> createIrqEventsList(TimeGraphEntry entry, List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState, IProgressMonitor monitor, int quark) {
+    private static List<ITimeEvent> createIrqEventsList(ITimeGraphEntry entry, List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState, IProgressMonitor monitor, int quark) {
         List<ITimeEvent> eventList;
         eventList = new ArrayList<>(fullStates.size());
         ITmfStateInterval lastInterval = prevFullState == null || quark >= prevFullState.size() ? null : prevFullState.get(quark);
index 541aad0beee750129629c5730fb4a84198fbca68..4352641034a4546d7f2a7623aae363c648785820 100644 (file)
@@ -131,7 +131,7 @@ public class VirtualMachineView extends AbstractTimeGraphView {
     // ------------------------------------------------------------------------
 
     @Override
-    protected void buildEventList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
+    protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
         setStartTime(Long.MAX_VALUE);
         setEndTime(Long.MIN_VALUE);
 
@@ -311,14 +311,11 @@ public class VirtualMachineView extends AbstractTimeGraphView {
             List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, monitor);
             entry.setEventList(eventList);
             redraw();
-            for (ITimeGraphEntry child : entry.getChildren()) {
-                if (!(child instanceof TimeGraphEntry)) {
-                    continue;
-                }
+            for (TimeGraphEntry child : entry.getChildren()) {
                 if (monitor.isCanceled()) {
                     return;
                 }
-                buildEntryEventList((TimeGraphEntry) child, ssq, start, end, monitor);
+                buildEntryEventList(child, ssq, start, end, monitor);
             }
         }
     }
@@ -465,14 +462,12 @@ public class VirtualMachineView extends AbstractTimeGraphView {
          * The parent VM entry will contain the thread intervals for all
          * threads. Just take the list from there
          */
-        ITimeGraphEntry parent = vmEntry.getParent();
+        TimeGraphEntry parent = vmEntry.getParent();
         while (threadIntervals == null && parent != null) {
             if (parent instanceof VirtualMachineViewEntry) {
                 threadIntervals = ((VirtualMachineViewEntry) parent).getThreadIntervals(vmEntry.getNumericId());
             }
-            if (parent instanceof TimeGraphEntry) {
-                parent = ((TimeGraphEntry) parent).getParent();
-            }
+            parent = parent.getParent();
         }
         return threadIntervals;
     }
index e7116ff57140d01ce5f8666b6c4590d964d03bdb..0b40966ad9800ab47395041cd64857e6308f44bc 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -221,7 +221,7 @@ public class XmlTimeGraphView extends AbstractTimeGraphView {
     // ------------------------------------------------------------------------
 
     @Override
-    protected void buildEventList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
+    protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
 
         /*
          * Get the view element from the XML file. If the element can't be
index 8efa4881f0883df8d96e8202c50fe7ebbb0f5b73..f63595e784f3e87298a1da76c4fe1613480c6fd5 100644 (file)
@@ -534,7 +534,7 @@ public class CallStackView extends AbstractTimeGraphView {
     }
 
     @Override
-    protected void buildEventList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) {
+    protected void buildEntryList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) {
         if (monitor.isCanceled()) {
             return;
         }
index b2ec511046df5251cde08f02df56572fadd3a07a..d27ffb2947615462aa75b5479ee07dd60aca60d6 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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
@@ -33,7 +33,6 @@ import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationPr
 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;
@@ -171,13 +170,11 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
                     }
                 });
             }
-            for (ITimeGraphEntry child : entry.getChildren()) {
+            for (TimeGraphEntry child : entry.getChildren()) {
                 if (monitor.isCanceled()) {
                     return;
                 }
-                if (child instanceof TimeGraphEntry) {
-                    zoom((TimeGraphEntry) child, ss, fullStates, prevFullState, monitor);
-                }
+                zoom(child, ss, fullStates, prevFullState, monitor);
             }
         }
 
@@ -198,10 +195,8 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
 
         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);
             }
         }
     }
@@ -369,6 +364,10 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
 
     /**
      * 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
index 1a31a46dd66aed8938326a753871354095671d70..d65a9f26418516d4b2923b6c54f4af75324c241d 100644 (file)
@@ -696,7 +696,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
 
         @Override
         public void run() {
-            buildEventList(fBuildTrace, fParentTrace, fMonitor);
+            buildEntryList(fBuildTrace, fParentTrace, fMonitor);
             synchronized (fBuildThreadMap) {
                 fBuildThreadMap.remove(fBuildTrace);
             }
@@ -849,13 +849,11 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                 }
             }
             redraw();
-            for (ITimeGraphEntry child : entry.getChildren()) {
+            for (TimeGraphEntry child : entry.getChildren()) {
                 if (monitor.isCanceled()) {
                     return;
                 }
-                if (child instanceof TimeGraphEntry) {
-                    zoom((TimeGraphEntry) child, monitor);
-                }
+                zoom(child, monitor);
             }
         }
 
@@ -1644,9 +1642,11 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
     }
 
     /**
-     * Build the entries list to show in this time graph
-     *
-     * Called from the BuildThread
+     * Build the entry list to show in this time graph view.
+     * <p>
+     * Called from the BuildThread for each trace returned by
+     * {@link #getTracesToBuild(ITmfTrace)}. The full event list is also
+     * normally computed for every entry that is created.
      *
      * @param trace
      *            The trace being built
@@ -1654,11 +1654,16 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
      *            The parent of the trace set, or the trace itself
      * @param monitor
      *            The progress monitor object
+     * @since 2.0
      */
-    protected abstract void buildEventList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor);
+    protected abstract void buildEntryList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor);
 
     /**
-     * Gets the list of event for an entry in a given timerange
+     * Gets the list of event for an entry in a given time range.
+     * <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 entry
      *            The entry to get events for
@@ -2264,7 +2269,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
         fEntryMenuManager.addMenuListener(new IMenuListener() {
             @Override
             public void menuAboutToShow(IMenuManager manager) {
-               fillTimeGraphEntryContextMenu(fEntryMenuManager);
+                fillTimeGraphEntryContextMenu(fEntryMenuManager);
                 fEntryMenuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
             }
         });
index 4c6356bb6a4ad345da0f0b29f8d97467fb9ce757..f25342a91ee79f3db58164e3b95cd953a38996bd 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2012, 2016 Ericsson, École Polytechnique de Montréal
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -30,10 +30,10 @@ import org.eclipse.swt.SWT;
 public class TimeGraphEntry implements ITimeGraphEntry {
 
     /** Entry's parent */
-    private ITimeGraphEntry fParent = null;
+    private TimeGraphEntry fParent = null;
 
     /** List of child entries */
-    private final List<@NonNull ITimeGraphEntry> fChildren = new CopyOnWriteArrayList<>();
+    private final List<@NonNull TimeGraphEntry> fChildren = new CopyOnWriteArrayList<>();
 
     /** Name of this entry (text to show) */
     private String fName;
@@ -63,32 +63,21 @@ public class TimeGraphEntry implements ITimeGraphEntry {
     // Getters and setters
     // ---------------------------------------------
 
-    @Override
-    public ITimeGraphEntry getParent() {
-        return fParent;
-    }
-
     /**
-     * Sets the entry's parent
-     *
-     * @param entry The new parent entry
-     */
-    /*
-     * TODO: This method can be removed in the next major API version.
+     * @since 2.0
      */
-    protected void setParent(TimeGraphEntry entry) {
-        fParent = entry;
+    @Override
+    public TimeGraphEntry getParent() {
+        return fParent;
     }
 
     /**
      * Sets the entry's parent
      *
      * @param entry The new parent entry
+     * @since 2.0
      */
-    /*
-     * TODO: This method should be added to the interface in the next major API version.
-     */
-    protected void setParent(ITimeGraphEntry entry) {
+    public void setParent(TimeGraphEntry entry) {
         fParent = entry;
     }
 
@@ -98,7 +87,7 @@ public class TimeGraphEntry implements ITimeGraphEntry {
     }
 
     @Override
-    public synchronized List<@NonNull ? extends ITimeGraphEntry> getChildren() {
+    public synchronized List<@NonNull TimeGraphEntry> getChildren() {
         return fChildren;
     }
 
@@ -250,19 +239,6 @@ public class TimeGraphEntry implements ITimeGraphEntry {
         }
     }
 
-    /**
-     * Add a child entry to this one
-     *
-     * @param child
-     *            The child entry
-     */
-    /*
-     * TODO: This method can be removed in the next major API version.
-     */
-    public synchronized void addChild(@NonNull TimeGraphEntry child) {
-        addChild((ITimeGraphEntry) child);
-    }
-
     /**
      * Add a child entry to this one. If a comparator was previously set with
      * {@link #sortChildren(Comparator)}, the entry will be inserted in its
@@ -271,13 +247,8 @@ public class TimeGraphEntry implements ITimeGraphEntry {
      * @param child
      *            The child entry
      */
-    public synchronized void addChild(@NonNull ITimeGraphEntry child) {
-        /*
-         * TODO: Use setParent() once it is added to the interface.
-         */
-        if (child instanceof TimeGraphEntry) {
-            ((TimeGraphEntry) child).fParent = this;
-        }
+    public synchronized void addChild(@NonNull TimeGraphEntry child) {
+        child.setParent(this);
         if (fComparator == null) {
             fChildren.add(child);
         } else {
@@ -299,20 +270,16 @@ public class TimeGraphEntry implements ITimeGraphEntry {
      *            Index at which the specified entry is to be inserted
      * @param child
      *            The child entry
+     * @since 2.0
      */
-    public synchronized void addChild(int index, @NonNull ITimeGraphEntry child) {
-        /*
-         * TODO: Use setParent() once it is added to the interface.
-         */
-        if (child instanceof TimeGraphEntry) {
-            ((TimeGraphEntry) child).fParent = this;
-        }
+    public synchronized void addChild(int index, @NonNull TimeGraphEntry child) {
+        child.setParent(this);
         fChildren.add(index, child);
     }
 
     /**
      * Sort the children of this entry using the provided comparator. Subsequent
-     * calls to {@link #addChild(ITimeGraphEntry)} will use this comparator to
+     * calls to {@link #addChild(TimeGraphEntry)} will use this comparator to
      * maintain the sort order.
      *
      * @param comparator
@@ -323,7 +290,7 @@ public class TimeGraphEntry implements ITimeGraphEntry {
         if (comparator == null) {
             return;
         }
-        @NonNull ITimeGraphEntry[] array = fChildren.toArray(new @NonNull ITimeGraphEntry[0]);
+        @NonNull TimeGraphEntry[] array = fChildren.toArray(new @NonNull TimeGraphEntry[0]);
         Arrays.sort(array, comparator);
         fChildren.clear();
         fChildren.addAll(Arrays.asList(array));
This page took 0.03519 seconds and 5 git commands to generate.