Mercurial > hg > graal-jvmci-8
changeset 17173:6c299422ba23
added support for substring matching when specifying unconditional timers and meters (e.g., -Dgraal.debug.timer.NodeClass*)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 22 Sep 2014 14:25:42 +0200 |
parents | 099028aa4d8b |
children | 2cb007e99ed0 |
files | graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java |
diffstat | 1 files changed, 35 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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<String> enabledMetrics; private static final Set<String> enabledTimers; + private static final Set<String> enabledMetricsSubstrings = new HashSet<>(); + private static final Set<String> enabledTimersSubstrings = new HashSet<>(); + static { Set<String> metrics = new HashSet<>(); Set<String> 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<String> haystack, Set<String> 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<String> metrics, Set<String> timers) { + protected static void parseMetricAndTimerSystemProperties(Set<String> metrics, Set<String> timers, Set<String> metricsSubstrings, Set<String> timersSubstrings) { do { try { 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.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; }