GraalDebugInitializationParticipant.java revision 12651:6ef01bd40ce2
1/*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23package org.graalvm.compiler.core;
24
25import org.graalvm.compiler.debug.Debug;
26import org.graalvm.compiler.debug.Debug.Params;
27import org.graalvm.compiler.debug.DebugInitializationParticipant;
28import org.graalvm.compiler.debug.GraalDebugConfig;
29import org.graalvm.compiler.debug.TTY;
30import org.graalvm.compiler.debug.internal.method.MethodMetricsPrinter;
31import org.graalvm.compiler.serviceprovider.ServiceProvider;
32
33/**
34 * A service provider that may modify the initialization of {@link Debug} based on the values
35 * specified for various {@link GraalDebugConfig} options.
36 */
37@ServiceProvider(DebugInitializationParticipant.class)
38public class GraalDebugInitializationParticipant implements DebugInitializationParticipant {
39
40    @Override
41    public void apply(Params params) {
42        if (GraalDebugConfig.areDebugScopePatternsEnabled()) {
43            params.enable = true;
44        }
45        if ("".equals(GraalDebugConfig.Options.Count.getValue())) {
46            params.enableUnscopedCounters = true;
47        }
48        if ("".equals(GraalDebugConfig.Options.MethodMeter.getValue())) {
49            params.enableUnscopedMethodMetrics = true;
50            // mm requires full debugging support
51            params.enable = true;
52        }
53        if ("".equals(GraalDebugConfig.Options.Time.getValue())) {
54            params.enableUnscopedTimers = true;
55        }
56        if ("".equals(GraalDebugConfig.Options.TrackMemUse.getValue())) {
57            params.enableUnscopedMemUseTrackers = true;
58        }
59        // unscoped counters/timers/mem use trackers/method metrics should respect method filter
60        // semantics
61        if (!params.enable && (params.enableUnscopedMemUseTrackers || params.enableUnscopedMethodMetrics || params.enableUnscopedCounters || params.enableUnscopedTimers) &&
62                        GraalDebugConfig.isNotEmpty(GraalDebugConfig.Options.MethodFilter)) {
63            params.enable = true;
64            params.enableMethodFilter = true;
65        }
66
67        if (!params.enableUnscopedMethodMetrics && GraalDebugConfig.Options.MethodMeter.getValue() != null) {
68            // mm requires full debugging support
69            params.enable = true;
70        }
71
72        if (GraalDebugConfig.isGlobalMetricsInterceptedByMethodMetricsEnabled()) {
73            if (!params.enable) {
74                TTY.println("WARNING: MethodMeter is disabled but GlobalMetricsInterceptedByMethodMetrics is enabled. Ignoring MethodMeter and GlobalMetricsInterceptedByMethodMetrics.");
75            } else {
76                parseMethodMetricsDebugValueInterception(params);
77            }
78        }
79        if (GraalDebugConfig.isNotEmpty(GraalDebugConfig.Options.MethodMeter) || params.enableUnscopedMethodMetrics) {
80            if (!MethodMetricsPrinter.methodMetricsDumpingEnabled()) {
81                TTY.println("WARNING: MethodMeter is enabled but MethodMeter dumping is disabled. Output will not contain MethodMetrics.");
82            }
83        }
84    }
85
86    private static void parseMethodMetricsDebugValueInterception(Params params) {
87        String interceptionGroup = GraalDebugConfig.Options.GlobalMetricsInterceptedByMethodMetrics.getValue();
88        boolean intercepted = false;
89        if (interceptionGroup.contains("Timers")) {
90            params.interceptTime = true;
91            intercepted = true;
92        }
93        if (interceptionGroup.contains("Counters")) {
94            params.interceptCount = true;
95            intercepted = true;
96        }
97        if (interceptionGroup.contains("MemUseTrackers")) {
98            params.interceptMem = true;
99            intercepted = true;
100        }
101
102        if (!intercepted) {
103            TTY.println("WARNING: Ignoring GlobalMetricsInterceptedByMethodMetrics as the supplied argument does not contain Timers/Counters/MemUseTrackers.");
104            GraalDebugConfig.Options.GlobalMetricsInterceptedByMethodMetrics.setValue(null);
105        }
106    }
107}
108