Measuring topology performance. Fixing a defect that caused us to run w/o accumulator when config file was not present.

Change-Id: I5ad538b8a441cd6ff2aefea49a0def10b8e0f4d5
diff --git a/core/api/src/main/java/org/onlab/onos/net/topology/Topology.java b/core/api/src/main/java/org/onlab/onos/net/topology/Topology.java
index 70e392f..182db10 100644
--- a/core/api/src/main/java/org/onlab/onos/net/topology/Topology.java
+++ b/core/api/src/main/java/org/onlab/onos/net/topology/Topology.java
@@ -22,17 +22,23 @@
  */
 public interface Topology extends Provided {
 
-    // FIXME: Following is not true right now. It is actually System.nanoTime(),
-    // which has no relation to epoch time, wall clock, etc.
     /**
-     * Returns the time, specified in milliseconds since start of epoch,
-     * when the topology became active and made available.
+     * Returns the time, specified in system nanos of when the topology
+     * became available.
      *
-     * @return time in milliseconds since start of epoch
+     * @return time in system nanos
      */
     long time();
 
     /**
+     * Returns the time, specified in system nanos of how long the topology
+     * took to compute.
+     *
+     * @return elapsed time in system nanos
+     */
+    long computeCost();
+
+    /**
      * Returns the number of SCCs (strongly connected components) in the
      * topology.
      *
diff --git a/core/net/src/main/java/org/onlab/onos/net/topology/impl/DefaultTopologyProvider.java b/core/net/src/main/java/org/onlab/onos/net/topology/impl/DefaultTopologyProvider.java
index 3f6e285..a5d2c5a 100644
--- a/core/net/src/main/java/org/onlab/onos/net/topology/impl/DefaultTopologyProvider.java
+++ b/core/net/src/main/java/org/onlab/onos/net/topology/impl/DefaultTopologyProvider.java
@@ -66,9 +66,9 @@
         implements TopologyProvider {
 
     private static final int MAX_THREADS = 8;
-    private static final int DEFAULT_MAX_EVENTS = 200;
-    private static final int DEFAULT_MAX_BATCH_MS = 60;
-    private static final int DEFAULT_MAX_IDLE_MS = 30;
+    private static final int DEFAULT_MAX_EVENTS = 1000;
+    private static final int DEFAULT_MAX_IDLE_MS = 10;
+    private static final int DEFAULT_MAX_BATCH_MS = 50;
 
     // FIXME: Replace with a system-wide timer instance;
     // TODO: Convert to use HashedWheelTimer or produce a variant of that; then decide which we want to adopt
@@ -116,15 +116,15 @@
     @Activate
     public synchronized void activate(ComponentContext context) {
         executor = newFixedThreadPool(MAX_THREADS, namedThreads("topo-build-%d"));
+        accumulator = new TopologyChangeAccumulator();
+        logConfig("Configured");
+
         modified(context);
 
         providerService = providerRegistry.register(this);
         deviceService.addListener(deviceListener);
         linkService.addListener(linkListener);
 
-        log.info("Configured with maxEvents = {}; maxBatchMs = {}; maxIdleMs = {}",
-                 maxEvents, maxBatchMs, maxIdleMs);
-
         isStarted = true;
         triggerRecompute();
         log.info("Started");
@@ -149,6 +149,7 @@
     public void modified(ComponentContext context) {
         if (context == null) {
             accumulator = new TopologyChangeAccumulator();
+            logConfig("Reconfigured");
             return;
         }
 
@@ -163,6 +164,7 @@
 
             s = (String) properties.get("maxIdleMs");
             newMaxIdleMs = isNullOrEmpty(s) ? maxIdleMs : Integer.parseInt(s);
+
         } catch (Exception e) {
             newMaxEvents = DEFAULT_MAX_EVENTS;
             newMaxBatchMs = DEFAULT_MAX_BATCH_MS;
@@ -174,11 +176,15 @@
             maxBatchMs = newMaxBatchMs;
             maxIdleMs = newMaxIdleMs;
             accumulator = maxEvents > 1 ? new TopologyChangeAccumulator() : null;
-            log.info("Reconfigured with maxEvents = {}; maxBatchMs = {}; maxIdleMs = {}",
-                     maxEvents, maxBatchMs, maxIdleMs);
+            logConfig("Reconfigured");
         }
     }
 
+    private void logConfig(String prefix) {
+        log.info("{} with maxEvents = {}; maxBatchMs = {}; maxIdleMs = {}; accumulator={}",
+                 prefix, maxEvents, maxBatchMs, maxIdleMs, accumulator != null);
+    }
+
 
     @Override
     public void triggerRecompute() {
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java b/core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java
index 4aafa35..939e558 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java
@@ -65,6 +65,7 @@
             new TarjanGraphSearch<>();
 
     private final long time;
+    private final long computeCost;
     private final TopologyGraph graph;
 
     private final SCCResult<TopologyVertex, TopologyEdge> clusterResults;
@@ -104,6 +105,7 @@
 
         this.broadcastSets = buildBroadcastSets();
         this.infrastructurePoints = findInfrastructurePoints();
+        this.computeCost = Math.max(0, System.nanoTime() - time);
     }
 
     @Override
@@ -112,6 +114,11 @@
     }
 
     @Override
+    public long computeCost() {
+        return computeCost;
+    }
+
+    @Override
     public int clusterCount() {
         return clusters.size();
     }
@@ -453,6 +460,7 @@
     public String toString() {
         return toStringHelper(this)
                 .add("time", time)
+                .add("computeCost", computeCost)
                 .add("clusters", clusterCount())
                 .add("devices", deviceCount())
                 .add("links", linkCount())
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/DefaultTopology.java b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/DefaultTopology.java
index 5478806..066089a 100644
--- a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/DefaultTopology.java
+++ b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/DefaultTopology.java
@@ -65,6 +65,7 @@
             new TarjanGraphSearch<>();
 
     private final long time;
+    private final long computeCost;
     private final TopologyGraph graph;
 
     private final SCCResult<TopologyVertex, TopologyEdge> clusterResults;
@@ -104,6 +105,7 @@
 
         this.broadcastSets = buildBroadcastSets();
         this.infrastructurePoints = findInfrastructurePoints();
+        this.computeCost = Math.max(0, System.nanoTime() - time);
     }
 
     @Override
@@ -112,6 +114,11 @@
     }
 
     @Override
+    public long computeCost() {
+        return computeCost;
+    }
+
+    @Override
     public int clusterCount() {
         return clusters.size();
     }
@@ -453,6 +460,7 @@
     public String toString() {
         return toStringHelper(this)
                 .add("time", time)
+                .add("computeCost", computeCost)
                 .add("clusters", clusterCount())
                 .add("devices", deviceCount())
                 .add("links", linkCount())