You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JDK Flight Recorder (JFR) is a tool for collecting diagnostic and profiling data about a running Java application, built into a JVM.
11
-
GraalVM Native Image supports JFR events and users can use [`jdk.jfr.Event`](https://docs.oracle.com/en/java/javase/11/docs/api/jdk.jfr/jdk/jfr/Event.html) API with a similar experience to using JFR in the Java HotSpot VM.
11
+
GraalVM Native Image supports JFR events and users can use the [`jdk.jfr.Event`](https://docs.oracle.com/en/java/javase/11/docs/api/jdk.jfr/jdk/jfr/Event.html) API with a similar experience to using JFR in the Java HotSpot VM.
12
12
13
-
To record JFR events when running a native executable, JFR support and JFR recording must be enabled, and this guide covers how to do that.
13
+
To record JFR events when running a native executable, enable JFR support and JFR recording as described in this guide.
14
14
15
-
> Note: JFR events recording is not supported on GraalVM JDK for Windows. JFR is only supported with native executables built on GraalVM JDK 11.
15
+
> Note: JFR event recording is not supported on GraalVM JDK for Windows.
16
16
17
17
## Enable JFR Support and Record Events at Run Time
18
18
@@ -23,7 +23,13 @@ To build a native executable with the JFR events support, you first need to add
23
23
24
24
Follow the steps below to practice building a native executable with JFR support and recording events at run time.
25
25
26
-
1. Save the following code to the file named _JFRDemo.java_.
26
+
> Note: You are expected to have GraalVM installed with Native Image support. The easiest way to install GraalVM is to use the [GraalVM JDK Downloader](https://github.com/graalvm/graalvm-jdk-downloader).
27
+
28
+
1. Install VisualVM by running:
29
+
```bash
30
+
gu install visualvm
31
+
```
32
+
2. Save the following code to the file named _JFRDemo.java_.
27
33
28
34
```java
29
35
import jdk.jfr.Event;
@@ -51,31 +57,31 @@ Follow the steps below to practice building a native executable with JFR support
51
57
It creates an event, labelled with the `@Label` annotation from the `jdk.jfr.*` package.
52
58
If you run this application, it will not print anything and just run that event.
53
59
54
-
2. Compile the Java file on GraalVM JDK:
60
+
3. Compile the Java file using the GraalVM JDK:
55
61
```shell
56
62
$JAVA_HOME/bin/javac JFRDemo.java
57
63
```
58
64
It creates two class files: `JFRDemo$HelloWorldEvent.class` and `JFRDemo.class`.
59
65
60
-
3. Build a native executable with the VM inspection enabled:
66
+
4. Build a native executable with the VM inspection enabled:
It runs the application as a native executable. The `-XX:StartFlightRecording` option enables the built-in Flight Recorder and starts recording to a specified binary file, `recording.jfr`.
76
+
This commandruns the application as a native executable. The `-XX:StartFlightRecording` option enables the built-in Flight Recorder and starts recording to a specified binary file, _recording.jfr_.
71
77
72
-
5. Start [VisualVM](https://visualvm.github.io/) to view the contents of the recording file in a user-friendly way. GraalVM provides VisualVM in the core installation. To start the tool, run:
78
+
6. Start [VisualVM](https://visualvm.github.io/) to view the contents of the recording file in a user-friendly way. GraalVM provides VisualVM in the core installation. To start the tool, run:
73
79
74
80
```shell
75
-
$JAVA_HOME/bin/jvisualvm
81
+
$JAVA_HOME/bin/visualvm
76
82
```
77
83
78
-
6. Go to **File**, then **Add JFR Snapshot**, browse _recording.jfr_, and open the selected file. Confirm the display name and click **OK**.
84
+
7. Go to **File**, then**Add JFR Snapshot**, browse _recording.jfr_, and open the selected file. Confirm the display name and click **OK**.
79
85
Once opened, there is a bunch of options you can check: Monitoring, Threads, Exceptions, etc., but you should be mostly interested in the events browsing. It will look something like this:
80
86
81
87

@@ -85,7 +91,7 @@ Follow the steps below to practice building a native executable with JFR support
85
91
```shell
86
92
$JAVA_HOME/bin/jfr print recording.jfr
87
93
```
88
-
It prints all events recorded by Flight Recorder.
94
+
It prints all the events recorded by Flight Recorder.
0 commit comments