jdk.jfr.FlightRecorderListener Java Examples

The following examples show how to use jdk.jfr.FlightRecorderListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestFlightRecorderListenerRecorderInitialized.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    FlightRecorder.addListener(new FlightRecorderListener() {

        @Override
        public void recorderInitialized(FlightRecorder recorder) {
            log("Recorder initialized");
            Signal.signal();
        }

    });
    FlightRecorder.getFlightRecorder();

    Signal.waitFor(3, TimeUnit.SECONDS);

    assertTrue(Signal.signalled, "FlightRecorderListener.recorderInitialized has not been called");

}
 
Example #2
Source File: TestFlightRecorderListenerRecorderInitialized.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    FlightRecorder.addListener(new FlightRecorderListener() {

        @Override
        public void recorderInitialized(FlightRecorder recorder) {
            log("Recorder initialized");
            Signal.signal();
        }

    });
    FlightRecorder.getFlightRecorder();

    Signal.waitFor(3, TimeUnit.SECONDS);

    assertTrue(Signal.signalled, "FlightRecorderListener.recorderInitialized has not been called");

}
 
Example #3
Source File: TestFlightRecorderListenerRecorderInitialized.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    FlightRecorder.addListener(new FlightRecorderListener() {

        @Override
        public void recorderInitialized(FlightRecorder recorder) {
            log("Recorder initialized");
            Signal.signal();
        }

    });
    FlightRecorder.getFlightRecorder();

    Signal.waitFor(3, TimeUnit.SECONDS);

    assertTrue(Signal.signalled, "FlightRecorderListener.recorderInitialized has not been called");

}
 
Example #4
Source File: PlatformRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public synchronized static void addListener(FlightRecorderListener changeListener) {
    AccessControlContext context = AccessController.getContext();
    SecureRecorderListener sl = new SecureRecorderListener(context, changeListener);
    boolean runInitialized;
    synchronized (PlatformRecorder.class) {
        runInitialized = FlightRecorder.isInitialized();
        changeListeners.add(sl);
    }
    if (runInitialized) {
        sl.recorderInitialized(FlightRecorder.getFlightRecorder());
    }
}
 
Example #5
Source File: TestIsInitialized.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Asserts.assertFalse(FlightRecorder.isInitialized());
    FlightRecorder.addListener(new FlightRecorderListener() {
        public void recorderInitialized(FlightRecorder recorder) {
            Asserts.assertTrue(FlightRecorder.isInitialized());
        }
    });
    FlightRecorder.getFlightRecorder();
    Asserts.assertTrue(FlightRecorder.isInitialized());
}
 
Example #6
Source File: PlatformRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public synchronized static boolean removeListener(FlightRecorderListener changeListener) {
    for (SecureRecorderListener s : new ArrayList<>(changeListeners)) {
        if (s.getChangeListener() == changeListener) {
            changeListeners.remove(s);
            return true;
        }
    }
    return false;
}
 
Example #7
Source File: PlatformRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public synchronized static void addListener(FlightRecorderListener changeListener) {
    AccessControlContext context = AccessController.getContext();
    SecureRecorderListener sl = new SecureRecorderListener(context, changeListener);
    boolean runInitialized;
    synchronized (PlatformRecorder.class) {
        runInitialized = FlightRecorder.isInitialized();
        changeListeners.add(sl);
    }
    if (runInitialized) {
        sl.recorderInitialized(FlightRecorder.getFlightRecorder());
    }
}
 
Example #8
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void notifyIfStateChanged(RecordingState newState, RecordingState oldState) {
    if (oldState == newState) {
        return;
    }
    for (FlightRecorderListener cl : PlatformRecorder.getListeners()) {
        try {
            cl.recordingStateChanged(getRecording());
        } catch (RuntimeException re) {
            Logger.log(JFR, WARN, "Error notifying recorder listener:" + re.getMessage());
        }
    }
}
 
Example #9
Source File: TestIsInitialized.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Asserts.assertFalse(FlightRecorder.isInitialized());
    FlightRecorder.addListener(new FlightRecorderListener() {
        public void recorderInitialized(FlightRecorder recorder) {
            Asserts.assertTrue(FlightRecorder.isInitialized());
        }
    });
    FlightRecorder.getFlightRecorder();
    Asserts.assertTrue(FlightRecorder.isInitialized());
}
 
Example #10
Source File: PlatformRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized static boolean removeListener(FlightRecorderListener changeListener) {
    for (SecureRecorderListener s : new ArrayList<>(changeListeners)) {
        if (s.getChangeListener() == changeListener) {
            changeListeners.remove(s);
            return true;
        }
    }
    return false;
}
 
Example #11
Source File: PlatformRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized static void addListener(FlightRecorderListener changeListener) {
    AccessControlContext context = AccessController.getContext();
    SecureRecorderListener sl = new SecureRecorderListener(context, changeListener);
    boolean runInitialized;
    synchronized (PlatformRecorder.class) {
        runInitialized = FlightRecorder.isInitialized();
        changeListeners.add(sl);
    }
    if (runInitialized) {
        sl.recorderInitialized(FlightRecorder.getFlightRecorder());
    }
}
 
Example #12
Source File: TestIsInitialized.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Asserts.assertFalse(FlightRecorder.isInitialized());
    FlightRecorder.addListener(new FlightRecorderListener() {
        public void recorderInitialized(FlightRecorder recorder) {
            Asserts.assertTrue(FlightRecorder.isInitialized());
        }
    });
    FlightRecorder.getFlightRecorder();
    Asserts.assertTrue(FlightRecorder.isInitialized());
}
 
Example #13
Source File: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void notifyIfStateChanged(RecordingState newState, RecordingState oldState) {
    if (oldState == newState) {
        return;
    }
    for (FlightRecorderListener cl : PlatformRecorder.getListeners()) {
        try {
            cl.recordingStateChanged(getRecording());
        } catch (RuntimeException re) {
            Logger.log(JFR, WARN, "Error notifying recorder listener:" + re.getMessage());
        }
    }
}
 
Example #14
Source File: PlatformRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public synchronized static boolean removeListener(FlightRecorderListener changeListener) {
    for (SecureRecorderListener s : new ArrayList<>(changeListeners)) {
        if (s.getChangeListener() == changeListener) {
            changeListeners.remove(s);
            return true;
        }
    }
    return false;
}
 
Example #15
Source File: PlatformRecording.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void notifyIfStateChanged(RecordingState newState, RecordingState oldState) {
    if (oldState == newState) {
        return;
    }
    for (FlightRecorderListener cl : PlatformRecorder.getListeners()) {
        try {
            cl.recordingStateChanged(getRecording());
        } catch (RuntimeException re) {
            Logger.log(JFR, WARN, "Error notifying recorder listener:" + re.getMessage());
        }
    }
}
 
Example #16
Source File: PlatformRecorder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void notifyRecorderInitialized(FlightRecorder recorder) {
    Logger.log(JFR_SYSTEM, TRACE, "Notifying listeners that Flight Recorder is initialized");
    for (FlightRecorderListener r : getListeners()) {
        r.recorderInitialized(recorder);
    }
}
 
Example #17
Source File: SecuritySupport.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
SecureRecorderListener(AccessControlContext context, FlightRecorderListener changeListener) {
    this.context = Objects.requireNonNull(context);
    this.changeListener = Objects.requireNonNull(changeListener);
}
 
Example #18
Source File: SecuritySupport.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public FlightRecorderListener getChangeListener() {
    return changeListener;
}
 
Example #19
Source File: TestUnsupportedVM.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String... args) throws Exception {
    if (Boolean.getBoolean("prepare-recording")) {
        Recording r = new Recording(Configuration.getConfiguration("default"));
        r.start();
        r.stop();
        r.dump(RECORDING_FILE);
        r.close();
        return;
    }

    System.out.println("jdk.jfr.unsupportedvm=" + System.getProperty("jdk.jfr.unsupportedvm"));
    // Class FlightRecorder
    if (FlightRecorder.isAvailable()) {
        throw new AssertionError("JFR should not be available on an unsupported VM");
    }

    if (FlightRecorder.isInitialized()) {
        throw new AssertionError("JFR should not be initialized on an unsupported VM");
    }

    assertIllegalStateException(() -> FlightRecorder.getFlightRecorder());
    assertSwallow(() -> FlightRecorder.addListener(new FlightRecorderListener() {}));
    assertSwallow(() -> FlightRecorder.removeListener(new FlightRecorderListener() {}));
    assertSwallow(() -> FlightRecorder.register(MyEvent.class));
    assertSwallow(() -> FlightRecorder.unregister(MyEvent.class));
    assertSwallow(() -> FlightRecorder.addPeriodicEvent(MyEvent.class, new Runnable() { public void run() {} }));
    assertSwallow(() -> FlightRecorder.removePeriodicEvent(new Runnable() { public void run() {} }));

    // Class Configuration
    if (!Configuration.getConfigurations().isEmpty()) {
        throw new AssertionError("Configuration files should not exist on an unsupported VM");
    }
    Path jfcFile = Utils.createTempFile("empty", ".jfr");
    assertIOException(() -> Configuration.getConfiguration("default"));
    assertIOException(() -> Configuration.create(jfcFile));
    assertIOException(() -> Configuration.create(new FileReader(jfcFile.toFile())));

    // Class EventType
    assertInternalError(() -> EventType.getEventType(MyEvent.class));

    // Class EventFactory
    assertInternalError(() -> EventFactory.create(new ArrayList<>(), new ArrayList<>()));

    // Create a static event
    MyEvent myEvent = new MyEvent();
    myEvent.begin();
    myEvent.end();
    myEvent.shouldCommit();
    myEvent.commit();

    // Trigger class initialization failure
    for (Class<?> c : APIClasses) {
        assertNoClassInitFailure(c);
    }

    // jdk.jfr.consumer.*
    // Only run this part of tests if we are on VM
    // that can produce a recording file
    if (Files.exists(RECORDING_FILE)) {
        for(RecordedEvent re : RecordingFile.readAllEvents(RECORDING_FILE)) {
            System.out.println(re);
        }
    }
}
 
Example #20
Source File: TestUnsupportedVM.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String... args) throws Exception {
    if (Boolean.getBoolean("prepare-recording")) {
        Recording r = new Recording(Configuration.getConfiguration("default"));
        r.start();
        r.stop();
        r.dump(RECORDING_FILE);
        r.close();
        return;
    }

    System.out.println("jdk.jfr.unsupportedvm=" + System.getProperty("jdk.jfr.unsupportedvm"));
    // Class FlightRecorder
    if (FlightRecorder.isAvailable()) {
        throw new AssertionError("JFR should not be available on an unsupported VM");
    }

    if (FlightRecorder.isInitialized()) {
        throw new AssertionError("JFR should not be initialized on an unsupported VM");
    }

    assertIllegalStateException(() -> FlightRecorder.getFlightRecorder());
    assertSwallow(() -> FlightRecorder.addListener(new FlightRecorderListener() {}));
    assertSwallow(() -> FlightRecorder.removeListener(new FlightRecorderListener() {}));
    assertSwallow(() -> FlightRecorder.register(MyEvent.class));
    assertSwallow(() -> FlightRecorder.unregister(MyEvent.class));
    assertSwallow(() -> FlightRecorder.addPeriodicEvent(MyEvent.class, new Runnable() { public void run() {} }));
    assertSwallow(() -> FlightRecorder.removePeriodicEvent(new Runnable() { public void run() {} }));

    // Class Configuration
    if (!Configuration.getConfigurations().isEmpty()) {
        throw new AssertionError("Configuration files should not exist on an unsupported VM");
    }
    Path jfcFile = Files.createTempFile("my", ".jfr");
    assertIOException(() -> Configuration.getConfiguration("default"));
    assertIOException(() -> Configuration.create(jfcFile));
    assertIOException(() -> Configuration.create(new FileReader(jfcFile.toFile())));

    // Class EventType
    assertInternalError(() -> EventType.getEventType(MyEvent.class));

    // Class EventFactory
    assertInternalError(() -> EventFactory.create(new ArrayList<>(), new ArrayList<>()));

    // Create a static event
    MyEvent myEvent = new MyEvent();
    myEvent.begin();
    myEvent.end();
    myEvent.shouldCommit();
    myEvent.commit();

    // Trigger class initialization failure
    for (Class<?> c : APIClasses) {
        assertNoClassInitFailure(c);
    }

    // jdk.jfr.consumer.*
    // Only run this part of tests if we are on VM
    // that can produce a recording file
    if (Files.exists(RECORDING_FILE)) {
        for(RecordedEvent re : RecordingFile.readAllEvents(RECORDING_FILE)) {
            System.out.println(re);
        }
    }
}
 
Example #21
Source File: SecuritySupport.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public FlightRecorderListener getChangeListener() {
    return changeListener;
}
 
Example #22
Source File: SecuritySupport.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
SecureRecorderListener(AccessControlContext context, FlightRecorderListener changeListener) {
    this.context = Objects.requireNonNull(context);
    this.changeListener = Objects.requireNonNull(changeListener);
}
 
Example #23
Source File: PlatformRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void notifyRecorderInitialized(FlightRecorder recorder) {
    Logger.log(JFR_SYSTEM, TRACE, "Notifying listeners that Flight Recorder is initialized");
    for (FlightRecorderListener r : getListeners()) {
        r.recorderInitialized(recorder);
    }
}
 
Example #24
Source File: PlatformRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static synchronized List<FlightRecorderListener> getListeners() {
    return new ArrayList<>(changeListeners);
}
 
Example #25
Source File: PlatformRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static synchronized List<FlightRecorderListener> getListeners() {
    return new ArrayList<>(changeListeners);
}
 
Example #26
Source File: PlatformRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void notifyRecorderInitialized(FlightRecorder recorder) {
    Logger.log(JFR_SYSTEM, TRACE, "Notifying listeners that Flight Recorder is initialized");
    for (FlightRecorderListener r : getListeners()) {
        r.recorderInitialized(recorder);
    }
}
 
Example #27
Source File: SecuritySupport.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
SecureRecorderListener(AccessControlContext context, FlightRecorderListener changeListener) {
    this.context = Objects.requireNonNull(context);
    this.changeListener = Objects.requireNonNull(changeListener);
}
 
Example #28
Source File: SecuritySupport.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public FlightRecorderListener getChangeListener() {
    return changeListener;
}
 
Example #29
Source File: TestUnsupportedVM.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String... args) throws Exception {
    if (Boolean.getBoolean("prepare-recording")) {
        Recording r = new Recording(Configuration.getConfiguration("default"));
        r.start();
        r.stop();
        r.dump(RECORDING_FILE);
        r.close();
        return;
    }

    System.out.println("jdk.jfr.unsupportedvm=" + System.getProperty("jdk.jfr.unsupportedvm"));
    // Class FlightRecorder
    if (FlightRecorder.isAvailable()) {
        throw new AssertionError("JFR should not be available on an unsupported VM");
    }

    if (FlightRecorder.isInitialized()) {
        throw new AssertionError("JFR should not be initialized on an unsupported VM");
    }

    assertIllegalStateException(() -> FlightRecorder.getFlightRecorder());
    assertSwallow(() -> FlightRecorder.addListener(new FlightRecorderListener() {}));
    assertSwallow(() -> FlightRecorder.removeListener(new FlightRecorderListener() {}));
    assertSwallow(() -> FlightRecorder.register(MyEvent.class));
    assertSwallow(() -> FlightRecorder.unregister(MyEvent.class));
    assertSwallow(() -> FlightRecorder.addPeriodicEvent(MyEvent.class, new Runnable() { public void run() {} }));
    assertSwallow(() -> FlightRecorder.removePeriodicEvent(new Runnable() { public void run() {} }));

    // Class Configuration
    if (!Configuration.getConfigurations().isEmpty()) {
        throw new AssertionError("Configuration files should not exist on an unsupported VM");
    }
    Path jfcFile = Utils.createTempFile("empty", ".jfr");
    assertIOException(() -> Configuration.getConfiguration("default"));
    assertIOException(() -> Configuration.create(jfcFile));
    assertIOException(() -> Configuration.create(new FileReader(jfcFile.toFile())));

    // Class EventType
    assertInternalError(() -> EventType.getEventType(MyEvent.class));

    // Class EventFactory
    assertInternalError(() -> EventFactory.create(new ArrayList<>(), new ArrayList<>()));

    // Create a static event
    MyEvent myEvent = new MyEvent();
    myEvent.begin();
    myEvent.end();
    myEvent.shouldCommit();
    myEvent.commit();

    // Trigger class initialization failure
    for (Class<?> c : APIClasses) {
        assertNoClassInitFailure(c);
    }

    // jdk.jfr.consumer.*
    // Only run this part of tests if we are on VM
    // that can produce a recording file
    if (Files.exists(RECORDING_FILE)) {
        for(RecordedEvent re : RecordingFile.readAllEvents(RECORDING_FILE)) {
            System.out.println(re);
        }
    }
}
 
Example #30
Source File: PlatformRecorder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static synchronized List<FlightRecorderListener> getListeners() {
    return new ArrayList<>(changeListeners);
}