1 /* |
1 /* |
2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 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 |
28 import java.io.FileReader; |
28 import java.io.FileReader; |
29 import java.io.IOException; |
29 import java.io.IOException; |
30 import java.nio.file.Files; |
30 import java.nio.file.Files; |
31 import java.nio.file.Path; |
31 import java.nio.file.Path; |
32 import java.nio.file.Paths; |
32 import java.nio.file.Paths; |
|
33 import java.time.Duration; |
33 import java.util.ArrayList; |
34 import java.util.ArrayList; |
34 import java.util.concurrent.Callable; |
35 import java.util.concurrent.Callable; |
|
36 import java.util.concurrent.atomic.AtomicBoolean; |
35 |
37 |
36 import jdk.jfr.AnnotationElement; |
38 import jdk.jfr.AnnotationElement; |
37 import jdk.jfr.Configuration; |
39 import jdk.jfr.Configuration; |
38 import jdk.jfr.Description; |
40 import jdk.jfr.Description; |
39 import jdk.jfr.Event; |
41 import jdk.jfr.Event; |
46 import jdk.jfr.Label; |
48 import jdk.jfr.Label; |
47 import jdk.jfr.Recording; |
49 import jdk.jfr.Recording; |
48 import jdk.jfr.RecordingState; |
50 import jdk.jfr.RecordingState; |
49 import jdk.jfr.SettingControl; |
51 import jdk.jfr.SettingControl; |
50 import jdk.jfr.ValueDescriptor; |
52 import jdk.jfr.ValueDescriptor; |
|
53 import jdk.jfr.consumer.EventStream; |
51 import jdk.jfr.consumer.RecordedClass; |
54 import jdk.jfr.consumer.RecordedClass; |
52 import jdk.jfr.consumer.RecordedEvent; |
55 import jdk.jfr.consumer.RecordedEvent; |
53 import jdk.jfr.consumer.RecordedFrame; |
56 import jdk.jfr.consumer.RecordedFrame; |
54 import jdk.jfr.consumer.RecordedMethod; |
57 import jdk.jfr.consumer.RecordedMethod; |
55 import jdk.jfr.consumer.RecordedObject; |
58 import jdk.jfr.consumer.RecordedObject; |
56 import jdk.jfr.consumer.RecordedStackTrace; |
59 import jdk.jfr.consumer.RecordedStackTrace; |
57 import jdk.jfr.consumer.RecordedThread; |
60 import jdk.jfr.consumer.RecordedThread; |
58 import jdk.jfr.consumer.RecordedThreadGroup; |
61 import jdk.jfr.consumer.RecordedThreadGroup; |
59 import jdk.jfr.consumer.RecordingFile; |
62 import jdk.jfr.consumer.RecordingFile; |
|
63 import jdk.jfr.consumer.RecordingStream; |
60 import jdk.management.jfr.ConfigurationInfo; |
64 import jdk.management.jfr.ConfigurationInfo; |
61 import jdk.management.jfr.EventTypeInfo; |
65 import jdk.management.jfr.EventTypeInfo; |
62 import jdk.management.jfr.FlightRecorderMXBean; |
66 import jdk.management.jfr.FlightRecorderMXBean; |
63 import jdk.management.jfr.RecordingInfo; |
67 import jdk.management.jfr.RecordingInfo; |
64 import jdk.management.jfr.SettingDescriptorInfo; |
68 import jdk.management.jfr.SettingDescriptorInfo; |
104 RecordingFile.class, |
108 RecordingFile.class, |
105 RecordingInfo.class, |
109 RecordingInfo.class, |
106 RecordingState.class, |
110 RecordingState.class, |
107 SettingControl.class, |
111 SettingControl.class, |
108 SettingDescriptorInfo.class, |
112 SettingDescriptorInfo.class, |
109 ValueDescriptor.class |
113 ValueDescriptor.class, |
|
114 EventStream.class, |
|
115 RecordingStream.class |
110 }; |
116 }; |
111 // * @run main/othervm -Dprepare-recording=true jdk.jfr.jvm.TestUnsupportedVM |
117 |
112 @Label("My Event") |
118 @Label("My Event") |
113 @Description("My fine event") |
119 @Description("My fine event") |
114 static class MyEvent extends Event { |
120 static class MyEvent extends Event { |
115 int myValue; |
121 int myValue; |
116 } |
122 } |
123 r.dump(RECORDING_FILE); |
129 r.dump(RECORDING_FILE); |
124 r.close(); |
130 r.close(); |
125 return; |
131 return; |
126 } |
132 } |
127 |
133 |
128 System.out.println("jdk.jfr.unsupportedvm=" + System.getProperty("jdk.jfr.unsupportedvm")); |
134 System.out.println("jfr.unsupported.vm=" + System.getProperty("jfr.unsupported.vm")); |
129 // Class FlightRecorder |
135 // Class FlightRecorder |
130 if (FlightRecorder.isAvailable()) { |
136 if (FlightRecorder.isAvailable()) { |
131 throw new AssertionError("JFR should not be available on an unsupported VM"); |
137 throw new AssertionError("JFR should not be available on an unsupported VM"); |
132 } |
138 } |
133 |
139 |
134 if (FlightRecorder.isInitialized()) { |
140 if (FlightRecorder.isInitialized()) { |
135 throw new AssertionError("JFR should not be initialized on an unsupported VM"); |
141 throw new AssertionError("JFR should not be initialized on an unsupported VM"); |
136 } |
142 } |
137 |
143 |
138 assertIllegalStateException(() -> FlightRecorder.getFlightRecorder()); |
144 assertIllegalStateException(() -> FlightRecorder.getFlightRecorder()); |
|
145 assertIllegalStateException(() -> new RecordingStream()); |
139 assertSwallow(() -> FlightRecorder.addListener(new FlightRecorderListener() {})); |
146 assertSwallow(() -> FlightRecorder.addListener(new FlightRecorderListener() {})); |
140 assertSwallow(() -> FlightRecorder.removeListener(new FlightRecorderListener() {})); |
147 assertSwallow(() -> FlightRecorder.removeListener(new FlightRecorderListener() {})); |
141 assertSwallow(() -> FlightRecorder.register(MyEvent.class)); |
148 assertSwallow(() -> FlightRecorder.register(MyEvent.class)); |
142 assertSwallow(() -> FlightRecorder.unregister(MyEvent.class)); |
149 assertSwallow(() -> FlightRecorder.unregister(MyEvent.class)); |
143 assertSwallow(() -> FlightRecorder.addPeriodicEvent(MyEvent.class, new Runnable() { public void run() {} })); |
150 assertSwallow(() -> FlightRecorder.addPeriodicEvent(MyEvent.class, new Runnable() { public void run() {} })); |
172 |
179 |
173 // jdk.jfr.consumer.* |
180 // jdk.jfr.consumer.* |
174 // Only run this part of tests if we are on VM |
181 // Only run this part of tests if we are on VM |
175 // that can produce a recording file |
182 // that can produce a recording file |
176 if (Files.exists(RECORDING_FILE)) { |
183 if (Files.exists(RECORDING_FILE)) { |
|
184 boolean firstFileEvent = true; |
177 for(RecordedEvent re : RecordingFile.readAllEvents(RECORDING_FILE)) { |
185 for(RecordedEvent re : RecordingFile.readAllEvents(RECORDING_FILE)) { |
178 System.out.println(re); |
186 // Print one event |
|
187 if (firstFileEvent) { |
|
188 System.out.println(re); |
|
189 firstFileEvent = false; |
|
190 } |
|
191 } |
|
192 AtomicBoolean firstStreamEvent = new AtomicBoolean(true); |
|
193 try (EventStream es = EventStream.openFile(RECORDING_FILE)) { |
|
194 es.onEvent(e -> { |
|
195 // Print one event |
|
196 if (firstStreamEvent.get()) { |
|
197 try { |
|
198 System.out.println(e); |
|
199 firstStreamEvent.set(false); |
|
200 } catch (Throwable t) { |
|
201 t.printStackTrace(); |
|
202 } |
|
203 } |
|
204 }); |
|
205 es.start(); |
|
206 if (firstStreamEvent.get()) { |
|
207 throw new AssertionError("Didn't print streaming event"); |
|
208 } |
|
209 } |
|
210 |
|
211 try (EventStream es = EventStream.openRepository()) { |
|
212 es.onEvent(e -> { |
|
213 System.out.println(e); |
|
214 }); |
|
215 es.startAsync(); |
|
216 es.awaitTermination(Duration.ofMillis(10)); |
179 } |
217 } |
180 } |
218 } |
181 } |
219 } |
182 |
220 |
183 private static void assertNoClassInitFailure(Class<?> clazz) { |
221 private static void assertNoClassInitFailure(Class<?> clazz) { |