From: Tuukka Lehtonen Date: Wed, 10 Jun 2020 18:51:12 +0000 (+0300) Subject: Help investigation of query caching problems via query histogram data X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=86239efa9f50ae671563e6149a586093751a3e69;p=simantics%2Fplatform.git Help investigation of query caching problems via query histogram data Change-Id: I5e3d86e642e0bbe0aa50623cae0bf9e389eb3632 --- diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Objects.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Objects.java index 0b3e1be34..b49f88c24 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Objects.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Objects.java @@ -59,6 +59,9 @@ final public class Objects extends CollectionBinaryQuery { public final static void runner(ReadGraphImpl graph, final int r1, final int r2, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) { if(parent == null && listener == null) { + if(Development.DEVELOPMENT) + Development.recordHistogram(new Objects(r1, r2).toString()); + Objects.computeForEach(graph, r1, r2, null, procedure); return; } @@ -73,6 +76,9 @@ final public class Objects extends CollectionBinaryQuery { entry.clearResult(processor.querySupport); entry.putEntry(processor); + if(Development.DEVELOPMENT) + Development.recordHistogram(entry.toString()); + processor.performForEach(graph, entry, parent, listener, procedure); } else { diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java index ff15d301b..9009f8feb 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java @@ -2008,6 +2008,10 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap for(Pair entry : entries) { b.println(entry.first + ": " + entry.second); + Exception e = Development.histogramExceptions.get(entry.first); + if (e != null) { + e.printStackTrace(b); + } } b.close(); diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Statements.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Statements.java index 935b81159..5e9b58970 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Statements.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Statements.java @@ -24,6 +24,7 @@ import org.simantics.db.impl.procedure.InternalProcedure; import org.simantics.db.impl.procedure.TripleIntProcedureAdapter; import org.simantics.db.procedure.ListenerBase; import org.simantics.db.request.RequestFlags; +import org.simantics.utils.Development; final public class Statements extends CollectionBinaryQuery { @@ -55,6 +56,9 @@ final public class Statements extends CollectionBinaryQuery entry.clearResult(processor.querySupport); entry.putEntry(processor); + if(Development.DEVELOPMENT) + Development.recordHistogram(entry.toString()); + processor.performForEach(graph, entry, parent, listener, procedure); } else { @@ -83,6 +87,8 @@ final public class Statements extends CollectionBinaryQuery assert(r2 != 0); if(parent == null && listener == null) { + if(Development.DEVELOPMENT) + Development.recordHistogram(new Statements(r1, r2).toString()); Statements.computeForEach(graph, r1, r2, null, procedure); return; } diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java index 29f34b45f..d3587f76e 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java @@ -816,6 +816,11 @@ final public class ClusterBig extends ClusterImpl { throw new Error("Not supported."); } + @Override + public String toString() { + return "ClusterBig[" + getClusterId() + "]"; + } + public int makeResourceKey(int resourceIndex) throws DatabaseException { int key = 0; // if (ClusterTraitsBase.isIllegalResourceIndex(resourceIndex)) diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/Development.java b/bundles/org.simantics.utils/src/org/simantics/utils/Development.java index 96c3453c7..26359e799 100644 --- a/bundles/org.simantics.utils/src/org/simantics/utils/Development.java +++ b/bundles/org.simantics.utils/src/org/simantics/utils/Development.java @@ -17,9 +17,11 @@ public class Development { private static final Logger LOGGER = LoggerFactory.getLogger(Development.class); public static TreeMap histogram = new TreeMap<>(); + public static Map histogramExceptions = new HashMap<>(); public static final boolean DEVELOPMENT = false; - + private static final int histogramExceptionThreshold = 100; + public static final String PRINT = "Development.print"; public interface DevelopmentListener { @@ -98,6 +100,9 @@ public class Development { String key = o.toString(); Integer i = histogram.get(key); histogram.put(key, i == null ? 1 : i+1); + if (i != null && i >= histogramExceptionThreshold) { + histogramExceptions.computeIfAbsent(key, k -> new Exception()); + } } }