]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils/src/org/simantics/utils/Development.java
Help investigation of query caching problems via query histogram data
[simantics/platform.git] / bundles / org.simantics.utils / src / org / simantics / utils / Development.java
index 84c13b4d82973f81706ae881fe2736821f5dff1e..26359e799f0b96c460300d16896a96b57d46fc65 100644 (file)
@@ -16,10 +16,12 @@ import org.slf4j.LoggerFactory;
 public class Development {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(Development.class);
-       public static TreeMap<String,Integer> histogram = new TreeMap<String,Integer>();
+       public static TreeMap<String,Integer> histogram = new TreeMap<>();
+       public static Map<String, Exception> 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 {
@@ -28,9 +30,9 @@ public class Development {
                
        }
        
-       final static private HashMap<String, Variant> properties = new HashMap<String, Variant>(); 
+       final static private HashMap<String, Variant> properties = new HashMap<>(); 
        
-       final static private CopyOnWriteArrayList<DevelopmentListener> listeners = new CopyOnWriteArrayList<DevelopmentListener>();
+       final static private CopyOnWriteArrayList<DevelopmentListener> listeners = new CopyOnWriteArrayList<>();
 
        static {
                
@@ -96,13 +98,11 @@ public class Development {
        
        public static void recordHistogram(Object o) {
                String key = o.toString();
-               Integer i = Development.histogram.get(key);
-               if(i == null) i = 0;
-               int newValue = i+1;
-               if (newValue == 1000) {
-                   newValue = newValue;
+               Integer i = histogram.get(key);
+               histogram.put(key, i == null ? 1 : i+1);
+               if (i != null && i >= histogramExceptionThreshold) {
+                       histogramExceptions.computeIfAbsent(key, k -> new Exception());
                }
-               Development.histogram.put(key, newValue);
        }
        
 }