Skip to content

Commit e0de28c

Browse files
committed
8257424: RecordingStream does not specify the recording name
Reviewed-by: egahlin
1 parent 60f2ba9 commit e0de28c

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingStream.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
public final class RecordingStream implements AutoCloseable, EventStream {
7070

7171
private final Recording recording;
72+
private final Instant creationTime;
7273
private final EventDirectoryStream directoryStream;
7374

7475
/**
@@ -86,6 +87,8 @@ public RecordingStream() {
8687
Utils.checkAccessFlightRecorder();
8788
AccessControlContext acc = AccessController.getContext();
8889
this.recording = new Recording();
90+
this.creationTime = Instant.now();
91+
this.recording.setName("Recording Stream: " + creationTime);
8992
try {
9093
PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);
9194
this.directoryStream = new EventDirectoryStream(acc, null, SecuritySupport.PRIVILEGED, pr, configurations());
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2020, NTT DATA.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
11+
*
12+
* This code is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
* version 2 for more details (a copy is included in the LICENSE file that
16+
* accompanied this code).
17+
*
18+
* You should have received a copy of the GNU General Public License version
19+
* 2 along with this work; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*
22+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23+
* or visit www.oracle.com if you need additional information or have any
24+
* questions.
25+
*/
26+
27+
package jdk.jfr.api.consumer.recordingstream;
28+
29+
import jdk.jfr.consumer.RecordingStream;
30+
import jdk.test.lib.jfr.EventNames;
31+
32+
/**
33+
* @test
34+
* @bug 8257424
35+
* @summary Tests recording name for RecordingStrream
36+
* @key jfr
37+
* @requires vm.hasJFR
38+
* @library /test/lib
39+
* @run main/othervm jdk.jfr.api.consumer.recordingstream.TestRecordingName
40+
*/
41+
public class TestRecordingName {
42+
43+
public static void main(String... args) throws Exception {
44+
try (RecordingStream r = new RecordingStream()) {
45+
r.enable(EventNames.ActiveRecording);
46+
r.onEvent(e -> {
47+
System.out.println(e);
48+
String name = e.getString("name");
49+
if (name.startsWith("Recording Stream: ")) {
50+
r.close();
51+
return;
52+
}
53+
System.err.println("Recording name not set, was " + name + ", but expected \"Recording Stream: <Instant>\"");
54+
});
55+
r.start();
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)