< prev index next >

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

Print this page




   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.time.Duration;

  28 import java.util.ArrayList;
  29 import java.util.Collection;
  30 import java.util.Collections;
  31 import java.util.Comparator;
  32 import java.util.List;
  33 import java.util.Map;
  34 import java.util.StringJoiner;
  35 
  36 import jdk.jfr.EventType;
  37 import jdk.jfr.Recording;
  38 import jdk.jfr.SettingDescriptor;
  39 import jdk.jfr.internal.LogLevel;
  40 import jdk.jfr.internal.LogTag;
  41 import jdk.jfr.internal.Logger;


  42 
  43 /**
  44  * JFR.check - invoked from native
  45  *
  46  */
  47 final class DCmdCheck extends AbstractDCmd {
  48     /**
  49      * Execute JFR.check
  50      *
  51      * @param recordingText name or id of the recording to check, or
  52      *        <code>null</code> to show a list of all recordings.
  53      *
  54      * @param verbose if event settings should be included.
  55      *
  56      * @return result output
  57      *
  58      * @throws DCmdException if the check could not be completed.
  59      */
  60     public String execute(String recordingText, Boolean verbose) throws DCmdException {
  61         executeInternal(recordingText, verbose);


  89             if (!first) {
  90                 println();
  91                 if (Boolean.TRUE.equals(verbose)) {
  92                     println();
  93                 }
  94             }
  95             first = false;
  96             printRecording(recording, verbose);
  97         }
  98     }
  99 
 100     private void printRecording(Recording recording, boolean verbose) {
 101         printGeneral(recording);
 102         if (verbose) {
 103             println();
 104             printSetttings(recording);
 105         }
 106     }
 107 
 108     private void printGeneral(Recording recording) {

 109         print("Recording " + recording.getId() + ": name=" + recording.getName());
 110 











 111         Duration duration = recording.getDuration();
 112         if (duration != null) {
 113             print(" duration=");



 114             printTimespan(duration, "");
 115         }
 116 
 117         long maxSize = recording.getMaxSize();
 118         if (maxSize != 0) {
 119             print(" maxsize=");
 120             printBytes(maxSize, "");





 121         }


 122         Duration maxAge = recording.getMaxAge();
 123         if (maxAge != null) {
 124             print(" maxage=");



 125             printTimespan(maxAge, "");
 126         }







 127 
 128         print(" (" + recording.getState().toString().toLowerCase() + ")");
 129         println();
 130     }
 131 
 132     private void printSetttings(Recording recording) {
 133         Map<String, String> settings = recording.getSettings();
 134         for (EventType eventType : sortByEventPath(getFlightRecorder().getEventTypes())) {
 135             StringJoiner sj = new StringJoiner(",", "[", "]");
 136             sj.setEmptyValue("");
 137             for (SettingDescriptor s : eventType.getSettingDescriptors()) {
 138                 String settingsPath = eventType.getName() + "#" + s.getName();
 139                 if (settings.containsKey(settingsPath)) {
 140                     sj.add(s.getName() + "=" + settings.get(settingsPath));
 141                 }
 142             }
 143             String settingsText = sj.toString();
 144             if (!settingsText.isEmpty()) {
 145                 print(" %s (%s)", eventType.getLabel(), eventType.getName());
 146                 println();


   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.time.Duration;
  28 import java.time.ZoneId;
  29 import java.util.ArrayList;
  30 import java.util.Collection;
  31 import java.util.Collections;
  32 import java.util.Comparator;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.StringJoiner;
  36 
  37 import jdk.jfr.EventType;
  38 import jdk.jfr.Recording;
  39 import jdk.jfr.SettingDescriptor;
  40 import jdk.jfr.internal.LogLevel;
  41 import jdk.jfr.internal.LogTag;
  42 import jdk.jfr.internal.Logger;
  43 import jdk.jfr.internal.OldObjectSample;
  44 import jdk.jfr.internal.PrivateAccess;
  45 
  46 /**
  47  * JFR.check - invoked from native
  48  *
  49  */
  50 final class DCmdCheck extends AbstractDCmd {
  51     /**
  52      * Execute JFR.check
  53      *
  54      * @param recordingText name or id of the recording to check, or
  55      *        <code>null</code> to show a list of all recordings.
  56      *
  57      * @param verbose if event settings should be included.
  58      *
  59      * @return result output
  60      *
  61      * @throws DCmdException if the check could not be completed.
  62      */
  63     public String execute(String recordingText, Boolean verbose) throws DCmdException {
  64         executeInternal(recordingText, verbose);


  92             if (!first) {
  93                 println();
  94                 if (Boolean.TRUE.equals(verbose)) {
  95                     println();
  96                 }
  97             }
  98             first = false;
  99             printRecording(recording, verbose);
 100         }
 101     }
 102 
 103     private void printRecording(Recording recording, boolean verbose) {
 104         printGeneral(recording);
 105         if (verbose) {
 106             println();
 107             printSetttings(recording);
 108         }
 109     }
 110 
 111     private void printGeneral(Recording recording) {
 112         var platformRecording = PrivateAccess.getInstance().getPlatformRecording(recording);
 113         print("Recording " + recording.getId() + ": name=" + recording.getName());
 114 
 115         print(" settings=" + platformRecording.getConfigNames());
 116 
 117         var delay = platformRecording.getDelay();
 118         print(" delay=");
 119         if (delay == null) {
 120             print("<N/A>");
 121         } else {
 122             printTimespan(delay, "");
 123             print(" (" + recording.getStartTime().atZone(ZoneId.systemDefault()) + ")");
 124         }
 125 
 126         Duration duration = recording.getDuration();

 127         print(" duration=");
 128         if (duration == null) {
 129             print("<N/A>");
 130         } else {
 131             printTimespan(duration, "");
 132         }
 133 
 134         print(" disk=" + recording.isToDisk());
 135 
 136         print(" filename=");
 137         var path = recording.getDestination();
 138         if (path == null) {
 139             var dir = platformRecording.getDumpOnExitDirectory();
 140             if (dir != null) {
 141                 path = dir.toPath();
 142             }
 143         }
 144         print(path == null ? "<N/A>" : path.toString());
 145 
 146         Duration maxAge = recording.getMaxAge();

 147         print(" maxage=");
 148         if (maxAge == null) {
 149             print("<N/A>");
 150         } else {
 151             printTimespan(maxAge, "");
 152         }
 153 
 154         print(" maxsize=");
 155         printBytes(recording.getMaxSize(), "");
 156 
 157         print(" dumponexit=" + recording.getDumpOnExit());
 158 
 159         print(" path-to-gc-roots=" + OldObjectSample.isPathToGcRootsEnabled(recording));
 160 
 161         print(" (" + recording.getState().toString().toLowerCase() + ")");
 162         println();
 163     }
 164 
 165     private void printSetttings(Recording recording) {
 166         Map<String, String> settings = recording.getSettings();
 167         for (EventType eventType : sortByEventPath(getFlightRecorder().getEventTypes())) {
 168             StringJoiner sj = new StringJoiner(",", "[", "]");
 169             sj.setEmptyValue("");
 170             for (SettingDescriptor s : eventType.getSettingDescriptors()) {
 171                 String settingsPath = eventType.getName() + "#" + s.getName();
 172                 if (settings.containsKey(settingsPath)) {
 173                     sj.add(s.getName() + "=" + settings.get(settingsPath));
 174                 }
 175             }
 176             String settingsText = sj.toString();
 177             if (!settingsText.isEmpty()) {
 178                 print(" %s (%s)", eventType.getLabel(), eventType.getName());
 179                 println();
< prev index next >