]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/BarrierTracing.java
Add possibility to bookkeep barrier tracing with env var
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / BarrierTracing.java
index 3ff77f6bc108c18b59535a3c02f3f1b51f78fac0..3c9b7a011adf71ffa3e48d94293bd9673def5505 100644 (file)
@@ -5,12 +5,18 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.simantics.db.impl.BlockingAsyncProcedure;
 import org.simantics.db.impl.query.CacheEntry;
 import org.simantics.db.impl.query.QueryProcessor.SessionTask;
 
 public class BarrierTracing {
 
-    public static final boolean BOOKKEEPING = false;
+    private static final String KEY = "SIMANTICS_DB_IMPL_BARRIER_TRACING";
+
+    public static final boolean BOOKKEEPING = Boolean.parseBoolean(
+            System.getProperty("org.simantics.db.impl.barrierTracing",
+            System.getenv(KEY) != null ? System.getenv(KEY) : "false")
+        );
     static final boolean RESTART_GUARD = BOOKKEEPING && false;
 
     public static Map<SessionTask,Exception> tasks = new HashMap<>();
@@ -19,7 +25,25 @@ public class BarrierTracing {
     public static final HashMap<AsyncBarrierImpl, CacheEntry<?>> entryMap = new HashMap<>();
     public static final HashMap<AsyncBarrierImpl, Throwable> restartMap = new HashMap<>();
     public static final HashMap<AsyncBarrierImpl, Throwable> startMap = new HashMap<>();
+    public static final HashMap<BlockingAsyncProcedure, Throwable> baps = new HashMap<>();
+
+    synchronized public static void registerBAP(BlockingAsyncProcedure bap) {
+        baps.put(bap, new Exception());
+    }
+    
+    synchronized public static void unregisterBAP(BlockingAsyncProcedure bap) {
+        baps.remove(bap);
+    }
 
+    synchronized public static void printBAPS() {
+        for(BlockingAsyncProcedure bap : baps.keySet()) {
+            bap.print();
+            Throwable t = baps.get(bap);
+            if(t != null)
+                t.printStackTrace();
+        }
+    }
+    
     public static void trace(AsyncBarrierImpl barrier, CacheEntry<?> entry) {
 
         if (RESTART_GUARD) {