# HG changeset patch # User Doug Simon # Date 1411388742 -7200 # Node ID 6c299422ba2399b38bf2473ac339daf21ae015f3 # Parent 099028aa4d8babdc557612c42ff95d370216679d added support for substring matching when specifying unconditional timers and meters (e.g., -Dgraal.debug.timer.NodeClass*) diff -r 099028aa4d8b -r 6c299422ba23 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 Sep 22 09:22:29 2014 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Mon Sep 22 14:25:42 2014 +0200 @@ -929,7 +929,7 @@ private static DebugMetric createMetric(String format, Object arg1, Object arg2) { String name = formatDebugName(format, arg1, arg2); - boolean conditional = enabledMetrics == null || !enabledMetrics.contains(name); + boolean conditional = enabledMetrics == null || !findMatch(enabledMetrics, enabledMetricsSubstrings, name); if (!ENABLED && conditional) { return VOID_METRIC; } @@ -1083,32 +1083,57 @@ private static final Set enabledMetrics; private static final Set enabledTimers; + private static final Set enabledMetricsSubstrings = new HashSet<>(); + private static final Set enabledTimersSubstrings = new HashSet<>(); + static { Set metrics = new HashSet<>(); Set timers = new HashSet<>(); - parseMetricAndTimerSystemProperties(metrics, timers); - enabledMetrics = metrics.isEmpty() ? null : metrics; - enabledTimers = timers.isEmpty() ? null : timers; + parseMetricAndTimerSystemProperties(metrics, timers, enabledMetricsSubstrings, enabledTimersSubstrings); + enabledMetrics = metrics.isEmpty() && enabledMetricsSubstrings.isEmpty() ? null : metrics; + enabledTimers = timers.isEmpty() && enabledTimersSubstrings.isEmpty() ? null : timers; + } + + private static boolean findMatch(Set haystack, Set haystackSubstrings, String needle) { + if (haystack.contains(needle)) { + return true; + } + if (!haystackSubstrings.isEmpty()) { + for (String h : haystackSubstrings) { + if (needle.startsWith(h)) { + return true; + } + } + } + return false; } public static boolean areUnconditionalTimersEnabled() { - return enabledTimers != null && !enabledTimers.isEmpty(); + return enabledTimers != null; } public static boolean areUnconditionalMetricsEnabled() { - return enabledMetrics != null && !enabledMetrics.isEmpty(); + return enabledMetrics != null; } - protected static void parseMetricAndTimerSystemProperties(Set metrics, Set timers) { + protected static void parseMetricAndTimerSystemProperties(Set metrics, Set timers, Set metricsSubstrings, Set timersSubstrings) { do { try { for (Map.Entry 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.endsWith("*")) { + metricsSubstrings.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length(), name.length() - 1)); + } else { + 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())); + if (name.endsWith("*")) { + timersSubstrings.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length(), name.length() - 1)); + } else { + timers.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length())); + } } } return; @@ -1206,7 +1231,7 @@ private static DebugTimer createTimer(String format, Object arg1, Object arg2) { String name = formatDebugName(format, arg1, arg2); - boolean conditional = enabledTimers == null || !enabledTimers.contains(name); + boolean conditional = enabledTimers == null || !findMatch(enabledTimers, enabledTimersSubstrings, name); if (!ENABLED && conditional) { return VOID_TIMER; }