analysis: Clean up critical path algorithm a bit
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Sat, 24 Oct 2015 02:23:10 +0000 (22:23 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 27 Oct 2015 19:29:00 +0000 (15:29 -0400)
Change-Id: I8c798fc612a28640b29292a6e51af046ebe50d97
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/58872
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.graph.core.tests/src/org/eclipse/tracecompass/analysis/graph/core/tests/analysis/criticalpath/TmfCriticalPathAlgoBoundedTest.java
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/criticalpath/CriticalPathAlgorithmException.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/criticalpath/CriticalPathModule.java
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/criticalpath/ICriticalPathAlgorithm.java
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/internal/analysis/graph/core/criticalpath/CriticalPathAlgorithmBounded.java

index 43db003da78316d98d9daf56c77cb64dad2279a3..03eb26369f83c8d3e63056648e7a9bbe30f67dc0 100644 (file)
 package org.eclipse.tracecompass.analysis.graph.core.tests.analysis.criticalpath;
 
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
 import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
+import org.eclipse.tracecompass.analysis.graph.core.criticalpath.CriticalPathAlgorithmException;
 import org.eclipse.tracecompass.analysis.graph.core.criticalpath.ICriticalPathAlgorithm;
 import org.eclipse.tracecompass.analysis.graph.core.tests.stubs.GraphBuilder;
 import org.eclipse.tracecompass.internal.analysis.graph.core.criticalpath.CriticalPathAlgorithmBounded;
@@ -29,8 +31,12 @@ public class TmfCriticalPathAlgoBoundedTest extends TmfCriticalPathAlgorithmTest
     protected TmfGraph computeCriticalPath(TmfGraph graph, TmfVertex start) {
         assertNotNull(graph);
         ICriticalPathAlgorithm cp = new CriticalPathAlgorithmBounded(graph);
-        TmfGraph bounded = cp.compute(start, null);
-        return bounded;
+        try {
+            return cp.compute(start, null);
+        } catch (CriticalPathAlgorithmException e) {
+            fail(e.getMessage());
+        }
+        return null;
     }
 
     @Override
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/criticalpath/CriticalPathAlgorithmException.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/criticalpath/CriticalPathAlgorithmException.java
new file mode 100644 (file)
index 0000000..92c2c6e
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2015 É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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.tracecompass.analysis.graph.core.criticalpath;
+
+/**
+ * Critical Path Algorithm Exception
+ * @author Matthew Khouzam
+ */
+public class CriticalPathAlgorithmException extends Exception {
+    /**
+     * Serial ID for serialization
+     */
+    private static final long serialVersionUID = -919020777158527567L;
+
+    /**
+     * Constructor
+     * @param message message
+     */
+    public CriticalPathAlgorithmException(String message){
+        super(message);
+    }
+}
\ No newline at end of file
index 549bc6c653185ded92b48602dea5b020b7d02e94..6064f3b345158bc1e5846e97db3fe3fd34f34e48 100644 (file)
@@ -106,9 +106,13 @@ public class CriticalPathModule extends TmfAbstractAnalysisModule {
             return true;
         }
         ICriticalPathAlgorithm cp = getAlgorithm(graph);
-        fCriticalPath = cp.compute(start, null);
-
-        return true;
+        try {
+            fCriticalPath = cp.compute(start, null);
+            return true;
+        } catch (CriticalPathAlgorithmException e) {
+            Activator.getInstance().logError(NonNullUtils.nullToEmptyString(e.getMessage()), e);
+        }
+        return false;
     }
 
     @Override
index 090b792ec3272292395b4685ecd81edeb98c6953..562288cb000bbaa53b1da98a9a10235c75730711 100644 (file)
@@ -28,8 +28,10 @@ public interface ICriticalPathAlgorithm {
      * @param end
      *            The end vertex
      * @return The graph of the critical path
+     * @throws CriticalPathAlgorithmException
+     *             an exception in the calculation occurred
      */
-    public TmfGraph compute(TmfVertex start, @Nullable TmfVertex end);
+    public TmfGraph compute(TmfVertex start, @Nullable TmfVertex end) throws CriticalPathAlgorithmException;
 
     /**
      * Unique ID of this algorithm
index 4179b92b178da2176b650684449a529bb9677042..3649de80bfb5c7067d7e0353dad82ea1502b5395 100644 (file)
@@ -9,6 +9,8 @@
 
 package org.eclipse.tracecompass.internal.analysis.graph.core.criticalpath;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
@@ -20,6 +22,7 @@ import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge;
 import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
 import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
 import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection;
+import org.eclipse.tracecompass.analysis.graph.core.criticalpath.CriticalPathAlgorithmException;
 
 /**
  * Critical path bounded algorithm: backward resolution of blocking limited to
@@ -45,7 +48,7 @@ public class CriticalPathAlgorithmBounded extends AbstractCriticalPathAlgorithm
     }
 
     @Override
-    public TmfGraph compute(TmfVertex start, @Nullable TmfVertex end) {
+    public TmfGraph compute(TmfVertex start, @Nullable TmfVertex end) throws CriticalPathAlgorithmException {
         /* Create new graph for the critical path result */
         TmfGraph criticalPath = new TmfGraph();
 
@@ -55,10 +58,7 @@ public class CriticalPathAlgorithmBounded extends AbstractCriticalPathAlgorithm
         /*
          * Calculate path starting from the object the start vertex belongs to
          */
-        IGraphWorker parent = graph.getParentOf(start);
-        if (parent == null) {
-            throw new NullPointerException();
-        }
+        IGraphWorker parent = checkNotNull(graph.getParentOf(start));
         criticalPath.add(parent, new TmfVertex(start));
         TmfVertex currentVertex = start;
         TmfEdge nextEdge = currentVertex.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
@@ -92,12 +92,9 @@ public class CriticalPathAlgorithmBounded extends AbstractCriticalPathAlgorithm
                  * TODO: Normally, the parent of the link's vertex to should be
                  * the object itself, verify if that is true
                  */
-                IGraphWorker parentTo = graph.getParentOf(nextEdge.getVertexTo());
-                if (parentTo == null) {
-                    throw new NullPointerException();
-                }
+                IGraphWorker parentTo = checkNotNull(graph.getParentOf(nextEdge.getVertexTo()));
                 if (parentTo != parent) {
-                    System.err.println("no, the parents of horizontal edges are not always identical... shouldn't they be?"); //$NON-NLS-1$
+                    throw new CriticalPathAlgorithmException("no, the parents of horizontal edges are not always identical... shouldn't they be?"); //$NON-NLS-1$
                 }
                 criticalPath.append(parentTo, new TmfVertex(nextEdge.getVertexTo()), nextEdge.getType());
                 break;
@@ -109,11 +106,11 @@ public class CriticalPathAlgorithmBounded extends AbstractCriticalPathAlgorithm
                 break;
             case EPS:
                 if (nextEdge.getDuration() != 0) {
-                    throw new RuntimeException("epsilon duration is not zero " + nextEdge); //$NON-NLS-1$
+                    throw new CriticalPathAlgorithmException("epsilon duration is not zero " + nextEdge); //$NON-NLS-1$
                 }
                 break;
             case DEFAULT:
-                throw new RuntimeException("Illegal link type " + nextEdge.getType()); //$NON-NLS-1$
+                throw new CriticalPathAlgorithmException("Illegal link type " + nextEdge.getType()); //$NON-NLS-1$
             case UNKNOWN:
             default:
                 break;
@@ -126,10 +123,7 @@ public class CriticalPathAlgorithmBounded extends AbstractCriticalPathAlgorithm
 
     /** Add the links to the critical path, with currentVertex to glue to */
     private void appendPathComponent(TmfGraph criticalPath, TmfGraph graph, TmfVertex currentVertex, List<TmfEdge> links) {
-        IGraphWorker currentActor = graph.getParentOf(currentVertex);
-        if (currentActor == null) {
-            throw new NullPointerException();
-        }
+        IGraphWorker currentActor = checkNotNull(graph.getParentOf(currentVertex));
         if (links.isEmpty()) {
             /*
              * The next vertex should not be null, since we glue only after
@@ -144,21 +138,14 @@ public class CriticalPathAlgorithmBounded extends AbstractCriticalPathAlgorithm
         }
         // FIXME: assert last link.to actor == currentActor
 
-        // attach subpath to b1 and b2
-        TmfVertex b1 = criticalPath.getTail(currentActor);
-        if (b1 == null) {
-            throw new NullPointerException();
-        }
-        // TmfVertex b2 = new TmfVertex(curr.neighbor(TmfVertex.OUTH));
+        // attach subpath to b1
+        TmfVertex b1 = checkNotNull(criticalPath.getTail(currentActor));
 
         // glue head
         TmfEdge lnk = links.get(0);
         TmfVertex anchor = null;
-        IGraphWorker objSrc = graph.getParentOf(lnk.getVertexFrom());
-        if (objSrc == null) {
-            throw new NullPointerException();
-        }
-        if (objSrc == currentActor) {
+        IGraphWorker objSrc = checkNotNull(graph.getParentOf(lnk.getVertexFrom()));
+        if (objSrc.equals( currentActor)) {
             anchor = b1;
         } else {
             anchor = new TmfVertex(currentVertex);
@@ -167,10 +154,7 @@ public class CriticalPathAlgorithmBounded extends AbstractCriticalPathAlgorithm
             /* fill any gap with UNKNOWN */
             if (lnk.getVertexFrom().compareTo(anchor) > 0) {
                 anchor = new TmfVertex(lnk.getVertexFrom());
-                TmfEdge edge = criticalPath.append(objSrc, anchor);
-                if (edge == null) {
-                    throw new NullPointerException();
-                }
+                TmfEdge edge = checkNotNull(criticalPath.append(objSrc, anchor));
                 edge.setType(TmfEdge.EdgeType.UNKNOWN);
             }
         }
@@ -212,10 +196,7 @@ public class CriticalPathAlgorithmBounded extends AbstractCriticalPathAlgorithm
             return subPath;
         }
 
-        TmfEdge down = junction.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE);
-        if (down == null) {
-            throw new NullPointerException();
-        }
+        TmfEdge down = checkNotNull(junction.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
         subPath.add(down);
         TmfVertex vertexFrom = down.getVertexFrom();
 
This page took 0.031457 seconds and 5 git commands to generate.