< prev index next >

src/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java

Print this page
rev 13686 : 8216064: -XX:StartFlightRecording:settings= doesn't work properly
Reviewed-by: mgronlun


   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.jfr.internal.dcmd;
  26 

  27 import java.io.IOException;
  28 import java.nio.file.Files;
  29 import java.nio.file.InvalidPathException;
  30 import java.nio.file.Path;
  31 import java.nio.file.Paths;
  32 import java.text.ParseException;
  33 import java.time.Duration;
  34 import java.util.Arrays;
  35 import java.util.HashMap;
  36 import java.util.Map;
  37 
  38 import jdk.jfr.FlightRecorder;
  39 import jdk.jfr.Recording;
  40 import jdk.jfr.internal.JVM;
  41 import jdk.jfr.internal.LogLevel;
  42 import jdk.jfr.internal.LogTag;
  43 import jdk.jfr.internal.Logger;
  44 import jdk.jfr.internal.OldObjectSample;
  45 import jdk.jfr.internal.PrivateAccess;
  46 import jdk.jfr.internal.SecuritySupport.SafePath;


  88                     ", duration=" + duration +
  89                     ", disk=" + disk+
  90                     ", filename=" + path +
  91                     ", maxage=" + maxAge +
  92                     ", maxsize=" + maxSize +
  93                     ", dumponexit =" + dumpOnExit +
  94                     ", path-to-gc-roots=" + pathToGcRoots);
  95         }
  96         if (name != null) {
  97             try {
  98                 Integer.parseInt(name);
  99                 throw new DCmdException("Name of recording can't be numeric");
 100             } catch (NumberFormatException nfe) {
 101                 // ok, can't be mixed up with name
 102             }
 103         }
 104 
 105         if (duration == null && Boolean.FALSE.equals(dumpOnExit) && path != null) {
 106             throw new DCmdException("Filename can only be set for a time bound recording or if dumponexit=true. Set duration/dumponexit or omit filename.");
 107         }
 108 
 109 

 110         Map<String, String> s = new HashMap<>();
 111 
 112         if (settings == null || settings.length == 0) {
 113             settings = new String[] { "default" };
 114         }
 115 
 116         for (String configName : settings) {
 117             try {
 118                 s.putAll(JFC.createKnown(configName).getSettings());


 119             } catch (IOException | ParseException e) {
 120                 throw new DCmdException("Could not parse setting " + settings[0], e);
 121             }
 122         }
 123 
 124         OldObjectSample.updateSettingPathToGcRoots(s, pathToGcRoots);
 125 
 126         if (duration != null) {
 127             if (duration < 1000L * 1000L * 1000L) {
 128                 // to avoid typo, duration below 1s makes no sense
 129                 throw new DCmdException("Could not start recording, duration must be at least 1 second.");
 130             }
 131         }
 132 
 133         if (delay != null) {
 134             if (delay < 1000L * 1000L * 1000) {
 135                 // to avoid typo, delay shorter than 1s makes no sense.
 136                 throw new DCmdException("Could not start recording, delay must be at least 1 second.");
 137             }
 138         }
 139 
 140         if (!FlightRecorder.isInitialized() && delay == null) {




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.jfr.internal.dcmd;
  26 
  27 import java.io.FileNotFoundException;
  28 import java.io.IOException;
  29 import java.nio.file.Files;
  30 import java.nio.file.InvalidPathException;
  31 import java.nio.file.Path;
  32 import java.nio.file.Paths;
  33 import java.text.ParseException;
  34 import java.time.Duration;
  35 import java.util.Arrays;
  36 import java.util.HashMap;
  37 import java.util.Map;
  38 
  39 import jdk.jfr.FlightRecorder;
  40 import jdk.jfr.Recording;
  41 import jdk.jfr.internal.JVM;
  42 import jdk.jfr.internal.LogLevel;
  43 import jdk.jfr.internal.LogTag;
  44 import jdk.jfr.internal.Logger;
  45 import jdk.jfr.internal.OldObjectSample;
  46 import jdk.jfr.internal.PrivateAccess;
  47 import jdk.jfr.internal.SecuritySupport.SafePath;


  89                     ", duration=" + duration +
  90                     ", disk=" + disk+
  91                     ", filename=" + path +
  92                     ", maxage=" + maxAge +
  93                     ", maxsize=" + maxSize +
  94                     ", dumponexit =" + dumpOnExit +
  95                     ", path-to-gc-roots=" + pathToGcRoots);
  96         }
  97         if (name != null) {
  98             try {
  99                 Integer.parseInt(name);
 100                 throw new DCmdException("Name of recording can't be numeric");
 101             } catch (NumberFormatException nfe) {
 102                 // ok, can't be mixed up with name
 103             }
 104         }
 105 
 106         if (duration == null && Boolean.FALSE.equals(dumpOnExit) && path != null) {
 107             throw new DCmdException("Filename can only be set for a time bound recording or if dumponexit=true. Set duration/dumponexit or omit filename.");
 108         }
 109         if (settings.length == 1 && settings[0].length() == 0) {
 110             throw new DCmdException("No settings specified. Use settings=none to start without any settings");
 111         }
 112         Map<String, String> s = new HashMap<>();
 113 
 114         if (settings == null || settings.length == 0) {
 115             settings = new String[] { "default" };
 116         }
 117 
 118         for (String configName : settings) {
 119             try {
 120                 s.putAll(JFC.createKnown(configName).getSettings());
 121             } catch(FileNotFoundException e) {
 122                 throw new DCmdException("Could not find settings file'" + configName + "'", e);
 123             } catch (IOException | ParseException e) {
 124                 throw new DCmdException("Could not parse settings file '" + settings[0] + "'", e);
 125             }
 126         }
 127 
 128         OldObjectSample.updateSettingPathToGcRoots(s, pathToGcRoots);
 129 
 130         if (duration != null) {
 131             if (duration < 1000L * 1000L * 1000L) {
 132                 // to avoid typo, duration below 1s makes no sense
 133                 throw new DCmdException("Could not start recording, duration must be at least 1 second.");
 134             }
 135         }
 136 
 137         if (delay != null) {
 138             if (delay < 1000L * 1000L * 1000) {
 139                 // to avoid typo, delay shorter than 1s makes no sense.
 140                 throw new DCmdException("Could not start recording, delay must be at least 1 second.");
 141             }
 142         }
 143 
 144         if (!FlightRecorder.isInitialized() && delay == null) {


< prev index next >