1 /*
2 * Copyright (c) 2016, 2018, 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. 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
34 import javax.management.openmbean.CompositeData;
35 import javax.management.openmbean.TabularData;
36
37 import jdk.jfr.Recording;
38 import jdk.jfr.RecordingState;
39 import jdk.jfr.internal.management.ManagementSupport;
40
41 /**
42 * Management representation of a {@code Recording}.
43 *
44 * @see Recording
45 *
46 * @since 9
47 */
48 public final class RecordingInfo {
49 private final long id;
50 private final String name;
51 private final String state;
52 private final boolean dumpOnExit;
53 private final long size;
54 private final boolean disk;
55 private final long maxAge;
56 private final long maxSize;
57 private final long startTime;
58 private final long stopTime;
59 private final String destination;
60 private final long durationInSeconds;
61 private final Map<String, String> settings;
62
63 // package private
64 RecordingInfo(Recording recording) {
65 id = recording.getId();
66 name = recording.getName();
67 state = recording.getState().toString();
68 dumpOnExit = recording.getDumpOnExit();
69 size = recording.getSize();
70 disk = recording.isToDisk();
71
72 Duration d = recording.getMaxAge();
73 if (d == null) {
74 maxAge = 0;
75 } else {
76 maxAge = d.getSeconds();
77 }
78 maxSize = recording.getMaxSize();
79 Instant s = recording.getStartTime();
80 startTime = s == null ? 0L : s.toEpochMilli();
81 Instant st = recording.getStopTime();
82 stopTime = st == null ? 0L : st.toEpochMilli();
83 destination = ManagementSupport.getDestinationOriginalText(recording);
84 Duration duration = recording.getDuration();
85 durationInSeconds = duration == null ? 0 : duration.getSeconds();
86 settings = recording.getSettings();
87 }
88
89 private RecordingInfo(CompositeData cd) {
90 id = (int) cd.get("id");
91 name = (String) cd.get("name");
92 state = (String) cd.get("state");
93 dumpOnExit = (boolean) cd.get("dumpOnExit");
94 size = (long) cd.get("size");
95 disk = (boolean) cd.get("disk");
96 maxAge = (Long) cd.get("maxAge");
97 maxSize = (Long) cd.get("maxSize");
98 startTime = (Long) cd.get("startTime");
99 stopTime = (Long) cd.get("stopTime");
100 destination = (String) cd.get("destination");
101 durationInSeconds = (long) cd.get("duration");
102 settings = new LinkedHashMap<>();
103 Object map = cd.get("settings");
104 if (map instanceof TabularData) {
105 TabularData td = (TabularData) map;
106 List<String> keyNames = td.getTabularType().getIndexNames();
107 int size = keyNames.size();
108 for (Object keys : td.keySet()) {
109 Object[] keyValues = ((List<?>) keys).toArray();
110 for (int i = 0; i < size; i++) {
111 String key = keyNames.get(i);
112 Object value = keyValues[i];
113 if (value instanceof String) {
114 settings.put(key, (String) value);
115 }
273 }
274
275 /**
276 * Returns the amount data recorded by recording. associated with this
277 * {@link RecordingInfo}.
278 *
279 * @return the amount of recorded data, measured in bytes
280 */
281 public long getSize() {
282 return size;
283 }
284
285 /**
286 * Returns {@code true} if the recording associated with this
287 * {@code RecordingInfo} should be flushed to disk, when memory buffers are
288 * full, {@code false} otherwise.
289 *
290 * @return {@code true} if recording is to disk, {@code false} otherwise
291 */
292 public boolean isToDisk() {
293 return disk;
294 }
295
296 /**
297 * Returns the desired duration, measured in seconds, of the recording
298 * associated with this {@link RecordingInfo}, or {code 0} if no duration
299 * has been set.
300 *
301 * @return the desired duration, or {code 0} if no duration has been set
302 *
303 * @see Recording#getDuration()
304 */
305 public long getDuration() {
306 return durationInSeconds;
307 }
308
309 /**
310 * Returns a {@code RecordingInfo} represented by the specified
311 * {@code CompositeData} object.
312 * <p>
313 * The specified {@code CompositeData} must have the following item names and
325 * <th scope="row">id</th>
326 * <td>{@code Long}</td>
327 * </tr>
328 * <tr>
329 * <th scope="row">name</th>
330 * <td>{@code String}</td>
331 * </tr>
332 * <tr>
333 * <th scope="row">state</th>
334 * <td>{@code String}</td>
335 * </tr>
336 * <tr>
337 * <th scope="row">dumpOnExit</th>
338 * <td>{@code Boolean}</td>
339 * </tr>
340 * <tr>
341 * <th scope="row">size</th>
342 * <td>{@code Long}</td>
343 * </tr>
344 * <tr>
345 * <th scope="row">disk</th>
346 * <td>{@code Boolean}</td>
347 * </tr>
348 * <tr>
349 * <th scope="row">maxAge</th>
350 * <td>{@code Long}</td>
351 * </tr>
352 * <tr>
353 * <th scope="row">maxSize</th>
354 * <td>{@code Long}</td>
355 * </tr>
356 * <tr>
357 * <th scope="row">startTime</th>
358 * <td>{@code Long}</td>
359 * </tr>
360 * <tr>
361 * <th scope="row">stopTime</th>
362 * <td>{@code Long}</td>
363 * </tr>
364 * <tr>
365 * <th scope="row">destination</th>
|
1 /*
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.
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. 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
34 import javax.management.openmbean.CompositeData;
35 import javax.management.openmbean.TabularData;
36
37 import jdk.jfr.Recording;
38 import jdk.jfr.RecordingState;
39 import jdk.jfr.internal.management.ManagementSupport;
40
41 /**
42 * Management representation of a {@code Recording}.
43 *
44 * @see Recording
45 *
46 * @since 9
47 */
48 public final class RecordingInfo {
49 private final long id;
50 private final String name;
51 private final String state;
52 private final boolean dumpOnExit;
53 private final long size;
54 private final boolean toDisk;
55 private final long maxAge;
56 private final long maxSize;
57 private final long startTime;
58 private final long stopTime;
59 private final String destination;
60 private final long durationInSeconds;
61 private final Map<String, String> settings;
62
63 // package private
64 RecordingInfo(Recording recording) {
65 id = recording.getId();
66 name = recording.getName();
67 state = recording.getState().toString();
68 dumpOnExit = recording.getDumpOnExit();
69 size = recording.getSize();
70 toDisk = recording.isToDisk();
71
72 Duration d = recording.getMaxAge();
73 if (d == null) {
74 maxAge = 0;
75 } else {
76 maxAge = d.getSeconds();
77 }
78 maxSize = recording.getMaxSize();
79 Instant s = recording.getStartTime();
80 startTime = s == null ? 0L : s.toEpochMilli();
81 Instant st = recording.getStopTime();
82 stopTime = st == null ? 0L : st.toEpochMilli();
83 destination = ManagementSupport.getDestinationOriginalText(recording);
84 Duration duration = recording.getDuration();
85 durationInSeconds = duration == null ? 0 : duration.getSeconds();
86 settings = recording.getSettings();
87 }
88
89 private RecordingInfo(CompositeData cd) {
90 id = (long) cd.get("id");
91 name = (String) cd.get("name");
92 state = (String) cd.get("state");
93 dumpOnExit = (boolean) cd.get("dumpOnExit");
94 size = (long) cd.get("size");
95 if(cd.containsKey("toDisk")){
96 toDisk = (boolean) cd.get("toDisk");
97 } else {
98 // Before JDK-8219904 was fixed, the element name was disk, so for compatibility
99 toDisk = (boolean) cd.get("disk");
100 }
101 maxAge = (Long) cd.get("maxAge");
102 maxSize = (Long) cd.get("maxSize");
103 startTime = (Long) cd.get("startTime");
104 stopTime = (Long) cd.get("stopTime");
105 destination = (String) cd.get("destination");
106 durationInSeconds = (long) cd.get("duration");
107 settings = new LinkedHashMap<>();
108 Object map = cd.get("settings");
109 if (map instanceof TabularData) {
110 TabularData td = (TabularData) map;
111 List<String> keyNames = td.getTabularType().getIndexNames();
112 int size = keyNames.size();
113 for (Object keys : td.keySet()) {
114 Object[] keyValues = ((List<?>) keys).toArray();
115 for (int i = 0; i < size; i++) {
116 String key = keyNames.get(i);
117 Object value = keyValues[i];
118 if (value instanceof String) {
119 settings.put(key, (String) value);
120 }
278 }
279
280 /**
281 * Returns the amount data recorded by recording. associated with this
282 * {@link RecordingInfo}.
283 *
284 * @return the amount of recorded data, measured in bytes
285 */
286 public long getSize() {
287 return size;
288 }
289
290 /**
291 * Returns {@code true} if the recording associated with this
292 * {@code RecordingInfo} should be flushed to disk, when memory buffers are
293 * full, {@code false} otherwise.
294 *
295 * @return {@code true} if recording is to disk, {@code false} otherwise
296 */
297 public boolean isToDisk() {
298 return toDisk;
299 }
300
301 /**
302 * Returns the desired duration, measured in seconds, of the recording
303 * associated with this {@link RecordingInfo}, or {code 0} if no duration
304 * has been set.
305 *
306 * @return the desired duration, or {code 0} if no duration has been set
307 *
308 * @see Recording#getDuration()
309 */
310 public long getDuration() {
311 return durationInSeconds;
312 }
313
314 /**
315 * Returns a {@code RecordingInfo} represented by the specified
316 * {@code CompositeData} object.
317 * <p>
318 * The specified {@code CompositeData} must have the following item names and
330 * <th scope="row">id</th>
331 * <td>{@code Long}</td>
332 * </tr>
333 * <tr>
334 * <th scope="row">name</th>
335 * <td>{@code String}</td>
336 * </tr>
337 * <tr>
338 * <th scope="row">state</th>
339 * <td>{@code String}</td>
340 * </tr>
341 * <tr>
342 * <th scope="row">dumpOnExit</th>
343 * <td>{@code Boolean}</td>
344 * </tr>
345 * <tr>
346 * <th scope="row">size</th>
347 * <td>{@code Long}</td>
348 * </tr>
349 * <tr>
350 * <th scope="row">toDisk</th>
351 * <td>{@code Boolean}</td>
352 * </tr>
353 * <tr>
354 * <th scope="row">maxAge</th>
355 * <td>{@code Long}</td>
356 * </tr>
357 * <tr>
358 * <th scope="row">maxSize</th>
359 * <td>{@code Long}</td>
360 * </tr>
361 * <tr>
362 * <th scope="row">startTime</th>
363 * <td>{@code Long}</td>
364 * </tr>
365 * <tr>
366 * <th scope="row">stopTime</th>
367 * <td>{@code Long}</td>
368 * </tr>
369 * <tr>
370 * <th scope="row">destination</th>
|