# HG changeset patch # User Doug Simon # Date 1384781209 -3600 # Node ID a7990d87c26ef9333aad6d86cdb7454e59cb0bbc # Parent 3e013f4512de13653584be1fa9d12df1bf0bba81 added support for unconditionally enabling a DebugTimer or DebugMetric, regardless of whether general Debug capabilities are enabled diff -r 3e013f4512de -r a7990d87c26e graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java --- 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. + *

+ * 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. + *

+ * 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;