src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java
changeset 58863 c16ac7a2eba4
parent 52413 6372f5af9612
equal deleted inserted replaced
58861:2c3cc4b01880 58863:c16ac7a2eba4
     1 /*
     1 /*
     2  * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    31 import java.util.HashMap;
    31 import java.util.HashMap;
    32 import java.util.HashSet;
    32 import java.util.HashSet;
    33 import java.util.LinkedHashMap;
    33 import java.util.LinkedHashMap;
    34 import java.util.List;
    34 import java.util.List;
    35 import java.util.Map;
    35 import java.util.Map;
    36 import java.util.Map.Entry;
       
    37 import java.util.Set;
    36 import java.util.Set;
    38 import java.util.StringJoiner;
    37 import java.util.StringJoiner;
    39 
    38 
       
    39 import jdk.jfr.internal.EventControl.NamedControl;
    40 import jdk.jfr.internal.handlers.EventHandler;
    40 import jdk.jfr.internal.handlers.EventHandler;
    41 
    41 
    42 final class SettingsManager {
    42 final class SettingsManager {
    43 
    43 
    44     private static class InternalSetting {
    44     private static class InternalSetting {
   211       return internals.values();
   211       return internals.values();
   212     }
   212     }
   213 
   213 
   214     void setEventControl(EventControl ec) {
   214     void setEventControl(EventControl ec) {
   215         InternalSetting is = getInternalSetting(ec);
   215         InternalSetting is = getInternalSetting(ec);
   216         Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "Applied settings for " + ec.getEventType().getLogName() + " {");
   216         boolean shouldLog = Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO);
   217         for (Entry<String, Control> entry : ec.getEntries()) {
   217         if (shouldLog) {
       
   218             Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "Applied settings for " + ec.getEventType().getLogName() + " {");
       
   219         }
       
   220         for (NamedControl nc: ec.getNamedControls()) {
   218             Set<String> values = null;
   221             Set<String> values = null;
   219             String settingName = entry.getKey();
   222             String settingName = nc.name;
   220             if (is != null) {
   223             if (is != null) {
   221                 values = is.getValues(settingName);
   224                 values = is.getValues(settingName);
   222             }
   225             }
   223             Control control = entry.getValue();
   226             Control control = nc.control;
   224             if (values != null) {
   227             if (values != null) {
   225                 control.apply(values);
   228                 control.apply(values);
   226                 String after = control.getLastValue();
   229                 String after = control.getLastValue();
   227                 if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO)) {
   230                 if (shouldLog) {
   228                     if (Utils.isSettingVisible(control, ec.getEventType().hasEventHook())) {
   231                     if (Utils.isSettingVisible(control, ec.getEventType().hasEventHook())) {
   229                         if (values.size() > 1) {
   232                         if (values.size() > 1) {
   230                             StringJoiner sj = new StringJoiner(", ", "{", "}");
   233                             StringJoiner sj = new StringJoiner(", ", "{", "}");
   231                             for (String s : values) {
   234                             for (String s : values) {
   232                                 sj.add("\"" + s + "\"");
   235                                 sj.add("\"" + s + "\"");
   239                         }
   242                         }
   240                     }
   243                     }
   241                 }
   244                 }
   242             } else {
   245             } else {
   243                 control.setDefault();
   246                 control.setDefault();
   244                 if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO)) {
   247                 if (shouldLog) {
   245                     String message = "  " + settingName + "=\"" + control.getLastValue() + "\"";
   248                     String message = "  " + settingName + "=\"" + control.getLastValue() + "\"";
   246                     Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, message);
   249                     Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, message);
   247                 }
   250                 }
   248             }
   251             }
   249         }
   252         }
   250         ec.writeActiveSettingEvent();
   253         ec.writeActiveSettingEvent();
   251         Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "}");
   254         if (shouldLog) {
       
   255             Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "}");
       
   256         }
   252     }
   257     }
   253 
   258 
   254     private InternalSetting getInternalSetting(EventControl ec) {
   259     private InternalSetting getInternalSetting(EventControl ec) {
   255         String name = ec.getEventType().getName();
   260         String name = ec.getEventType().getName();
   256         InternalSetting nameBased = availableSettings.get(name);
   261         InternalSetting nameBased = availableSettings.get(name);