src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java
changeset 58863 c16ac7a2eba4
parent 55302 686dedba1d9a
equal deleted inserted replaced
58861:2c3cc4b01880 58863:c16ac7a2eba4
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 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
    79      * @return result output
    79      * @return result output
    80      *
    80      *
    81      * @throws DCmdException if recording could not be started
    81      * @throws DCmdException if recording could not be started
    82      */
    82      */
    83     @SuppressWarnings("resource")
    83     @SuppressWarnings("resource")
    84     public String execute(String name, String[] settings, Long delay, Long duration, Boolean disk, String path, Long maxAge, Long maxSize, Boolean dumpOnExit, Boolean pathToGcRoots) throws DCmdException {
    84     public String execute(String name, String[] settings, Long delay, Long duration, Boolean disk, String path, Long maxAge, Long maxSize, Long flush, Boolean dumpOnExit, Boolean pathToGcRoots) throws DCmdException {
    85         if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
    85         if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
    86             Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG, "Executing DCmdStart: name=" + name +
    86             Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG, "Executing DCmdStart: name=" + name +
    87                     ", settings=" + Arrays.asList(settings) +
    87                     ", settings=" + Arrays.asList(settings) +
    88                     ", delay=" + delay +
    88                     ", delay=" + delay +
    89                     ", duration=" + duration +
    89                     ", duration=" + duration +
    90                     ", disk=" + disk+
    90                     ", disk=" + disk+
    91                     ", filename=" + path +
    91                     ", filename=" + path +
    92                     ", maxage=" + maxAge +
    92                     ", maxage=" + maxAge +
       
    93                     ", flush=" + flush +
    93                     ", maxsize=" + maxSize +
    94                     ", maxsize=" + maxSize +
    94                     ", dumponexit =" + dumpOnExit +
    95                     ", dumponexit =" + dumpOnExit +
    95                     ", path-to-gc-roots=" + pathToGcRoots);
    96                     ", path-to-gc-roots=" + pathToGcRoots);
    96         }
    97         }
    97         if (name != null) {
    98         if (name != null) {
   134                 // to avoid typo, delay shorter than 1s makes no sense.
   135                 // to avoid typo, delay shorter than 1s makes no sense.
   135                 throw new DCmdException("Could not start recording, delay must be at least 1 second.");
   136                 throw new DCmdException("Could not start recording, delay must be at least 1 second.");
   136             }
   137             }
   137         }
   138         }
   138 
   139 
       
   140         if (flush != null) {
       
   141             if (Boolean.FALSE.equals(disk)) {
       
   142                 throw new DCmdException("Flush can only be set for recordings that are to disk.");
       
   143             }
       
   144         }
       
   145 
   139         if (!FlightRecorder.isInitialized() && delay == null) {
   146         if (!FlightRecorder.isInitialized() && delay == null) {
   140             initializeWithForcedInstrumentation(s);
   147             initializeWithForcedInstrumentation(s);
   141         }
   148         }
   142 
   149 
   143         Recording recording = new Recording();
   150         Recording recording = new Recording();
   146         }
   153         }
   147 
   154 
   148         if (disk != null) {
   155         if (disk != null) {
   149             recording.setToDisk(disk.booleanValue());
   156             recording.setToDisk(disk.booleanValue());
   150         }
   157         }
       
   158 
   151         recording.setSettings(s);
   159         recording.setSettings(s);
   152         SafePath safePath = null;
   160         SafePath safePath = null;
   153 
   161 
   154         if (path != null) {
   162         if (path != null) {
   155             try {
   163             try {
   175 
   183 
   176         if (maxAge != null) {
   184         if (maxAge != null) {
   177             recording.setMaxAge(Duration.ofNanos(maxAge));
   185             recording.setMaxAge(Duration.ofNanos(maxAge));
   178         }
   186         }
   179 
   187 
       
   188         if (flush != null) {
       
   189             recording.setFlushInterval(Duration.ofNanos(flush));
       
   190         }
       
   191 
   180         if (maxSize != null) {
   192         if (maxSize != null) {
   181             recording.setMaxSize(maxSize);
   193             recording.setMaxSize(maxSize);
   182         }
   194         }
   183 
   195 
   184         if (duration != null) {
   196         if (duration != null) {
   220                 recordingspecifier = "name=" + quoteIfNeeded(name);
   232                 recordingspecifier = "name=" + quoteIfNeeded(name);
   221             }
   233             }
   222             print("Use jcmd " + getPid() + " JFR." + cmd + " " + recordingspecifier + " " + fileOption + "to copy recording data to file.");
   234             print("Use jcmd " + getPid() + " JFR." + cmd + " " + recordingspecifier + " " + fileOption + "to copy recording data to file.");
   223             println();
   235             println();
   224         }
   236         }
       
   237 
   225         return getResult();
   238         return getResult();
   226     }
   239     }
   227 
   240 
   228 
   241 
   229     // Instruments JDK-events on class load to reduce startup time
   242     // Instruments JDK-events on class load to reduce startup time