changeset 14582:5fc6b8b54d82

reduced overhead of Debug.metric() and Debug.timer() when no metrics or timers are enabled
author Doug Simon <doug.simon@oracle.com>
date Tue, 18 Mar 2014 12:39:23 +0100
parents 69dfb976fd26
children 2ec76bd5f309
files graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java
diffstat 1 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Tue Mar 18 10:04:29 2014 +0100
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Tue Mar 18 12:39:23 2014 +0100
@@ -380,7 +380,7 @@
      * A disabled metric has virtually no overhead.
      */
     public static DebugMetric metric(String name) {
-        if (Boolean.getBoolean(ENABLE_METRIC_PROPERTY_NAME_PREFIX + name)) {
+        if (enabledMetrics != null && enabledMetrics.contains(name)) {
             return new MetricImpl(name, false);
         } else if (ENABLED) {
             return new MetricImpl(name, true);
@@ -504,6 +504,24 @@
      */
     public static final String ENABLE_METRIC_PROPERTY_NAME_PREFIX = "graal.debug.metric.";
 
+    private static final Set<String> enabledMetrics;
+    private static final Set<String> enabledTimers;
+    static {
+        Set<String> metrics = new HashSet<>();
+        Set<String> timers = new HashSet<>();
+        for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) {
+            String name = e.getKey().toString();
+            if (name.startsWith(ENABLE_METRIC_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) {
+                metrics.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length()));
+            }
+            if (name.startsWith(ENABLE_TIMER_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) {
+                timers.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length()));
+            }
+        }
+        enabledMetrics = metrics.isEmpty() ? null : metrics;
+        enabledTimers = timers.isEmpty() ? null : timers;
+    }
+
     /**
      * Creates a {@linkplain DebugTimer timer} that is enabled iff debugging is
      * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to
@@ -515,7 +533,7 @@
      * A disabled timer has virtually no overhead.
      */
     public static DebugTimer timer(String name) {
-        if (Boolean.getBoolean(ENABLE_TIMER_PROPERTY_NAME_PREFIX + name)) {
+        if (enabledTimers != null && enabledTimers.contains(name)) {
             return new TimerImpl(name, false);
         } else if (ENABLED) {
             return new TimerImpl(name, true);