changeset 12776:a7990d87c26e

added support for unconditionally enabling a DebugTimer or DebugMetric, regardless of whether general Debug capabilities are enabled
author Doug Simon <doug.simon@oracle.com>
date Mon, 18 Nov 2013 14:26:49 +0100
parents 3e013f4512de
children 516ad7baa080
files graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java
diffstat 1 files changed, 36 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Mon Nov 18 09:11:30 2013 +0100
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Mon Nov 18 14:26:49 2013 +0100
@@ -353,8 +353,20 @@
         return null;
     }
 
+    /**
+     * Creates a {@linkplain DebugMetric metric} that is enabled iff debugging is
+     * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to
+     * {@value #ENABLE_METRIC_PROPERTY_NAME_PREFIX} to {@code name} is
+     * {@linkplain Boolean#getBoolean(String) true}. If the latter condition is true, then the
+     * returned metric is {@linkplain DebugMetric#isConditional() unconditional} otherwise it is
+     * conditional.
+     * <p>
+     * A disabled metric has virtually no overhead.
+     */
     public static DebugMetric metric(String name) {
-        if (ENABLED) {
+        if (Boolean.getBoolean(ENABLE_METRIC_PROPERTY_NAME_PREFIX + name)) {
+            return new MetricImpl(name, false);
+        } else if (ENABLED) {
             return new MetricImpl(name, true);
         } else {
             return VOID_METRIC;
@@ -440,8 +452,30 @@
         }
     };
 
+    /**
+     * @see #timer(String)
+     */
+    public static final String ENABLE_TIMER_PROPERTY_NAME_PREFIX = "graal.debug.timer.";
+
+    /**
+     * @see #metric(String)
+     */
+    public static final String ENABLE_METRIC_PROPERTY_NAME_PREFIX = "graal.debug.metric.";
+
+    /**
+     * 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
+     * {@value #ENABLE_TIMER_PROPERTY_NAME_PREFIX} to {@code name} is
+     * {@linkplain Boolean#getBoolean(String) true}. If the latter condition is true, then the
+     * returned timer is {@linkplain DebugMetric#isConditional() unconditional} otherwise it is
+     * conditional.
+     * <p>
+     * A disabled timer has virtually no overhead.
+     */
     public static DebugTimer timer(String name) {
-        if (ENABLED) {
+        if (Boolean.getBoolean(ENABLE_TIMER_PROPERTY_NAME_PREFIX + name)) {
+            return new TimerImpl(name, false);
+        } else if (ENABLED) {
             return new TimerImpl(name, true);
         } else {
             return VOID_TIMER;