Skip to content

Commit 22c6856

Browse files
committed
[GR-41997] Add missing commands to Use GraalVM Dashboard to Optimize the Size of a Native Executable.
PullRequest: graal/13015
2 parents 7425d5d + 9f7de15 commit 22c6856

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

docs/reference-manual/native-image/guides/use-graalvm-dashboard.md

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,33 @@ This guide demonstrates how to use the dashboard to optimize the size of a nativ
1717
## Fortune
1818
Package the contents of the first implementation ([fortune](https://github.com/graalvm/graalvm-demos/tree/master/fortune-demo/fortune)) as a native executable and review its composition.
1919

20-
1. Clone the project, build the application, and run it:
21-
```shell
20+
1. Download or clone the repository and navigate into the _fortune-demo/fortune_ directory:
21+
```
2222
git clone https://github.com/graalvm/graalvm-demos
2323
cd fortune-demo/fortune
24-
mvn package
24+
```
25+
2. Build the project:
26+
```
27+
mvn clean package
28+
```
29+
3. When the build succeeds, run the application on the JVM with the [Tracing agent](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#agent-support). Since you have installed GraalVM, it will run on GraalVM JDK.
30+
```
31+
mvn -Pnative -Dagent exec:exec@java-agent
32+
```
33+
The application will return a random saying.
34+
The agent generates the configuration files in the `target/native/agent-output` subdirectory.
35+
36+
4. Build a native executable of this application with GraalVM Native Image and Maven:
37+
```
38+
mvn -Pnative -Dagent package
39+
```
40+
When the command completes, a native executable, `fortune`, is generated in the `/target` directory of the project and ready for use.
41+
42+
5. Run the application by launching a native executable directly:
43+
```
2544
./target/fortune
2645
```
46+
2747
The application should slowly print a random phrase.
2848
2949
The application's [_pom.xml_](https://github.com/graalvm/graalvm-demos/blob/master/fortune-demo/fortune/pom.xml) file employs the [Native Image Maven plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to build a native executable, configured to produce diagnostic data using these two options:
@@ -53,7 +73,7 @@ Package the contents of the first implementation ([fortune](https://github.com/g
5373
5474
The size of the JAR file is 2MB, compared to the 17MB size of the native executable. The increase in size is because the native executable contains all necessary runtime code as well as pre-initialized data in its heap.
5575
56-
2. Open the [GraalVM Dashboard](https://www.graalvm.org/dashboard) and load the _fortune.bgv_ file. (Click **+**, click **Select File**, select the _fortune.bgv_ file from the _target_ directory, and then click **OK**.)
76+
6. Open the [GraalVM Dashboard](https://www.graalvm.org/dashboard) and load the _fortune.bgv_ file. (Click **+**, click **Select File**, select the _fortune.bgv_ file from the _target_ directory, and then click **OK**.)
5777
5878
The GraalVM dashboard provides two visualizations of a native executable: code size breakdown and heap size breakdown. (For more information, see [Code Size Breakdown](https://www.graalvm.org/dashboard/?ojr=help%3Btopic%3Dcode-size-histogram.md) and [Heap Size Breakdown](https://www.graalvm.org/dashboard/?ojr=help%3Btopic%3Dheap-size-histogram.md), respectively.)
5979
@@ -71,10 +91,28 @@ Package the contents of the first implementation ([fortune](https://github.com/g
7191
7292
The first implementation of the fortune application uses the [Jackson JSON parser](https://github.com/FasterXML/jackson) (package `com.fasterxml`) at **runtime** to parse the contents of a [resource file](https://github.com/graalvm/graalvm-demos/blob/master/fortune-demo/fortune/src/main/resources/fortunes.json) that the native image builder has included in the native executable. An alternative implementation (named "staticfortune") parses the contents of the resource file at build time. This means that the resource file is no longer included in the executable, and the code required to parse the file is omitted from the native executable because it is only required at build time.
7393
74-
1. Build the application and run it:
75-
```shell
94+
1. Change to the project directory and build the project:
95+
```
7696
cd ../staticfortune
77-
mvn package
97+
```
98+
```
99+
mvn clean package
100+
```
101+
102+
2. Run the application on the JVM (GraalVM JDK) with the [Tracing agent](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#agent-support):
103+
```
104+
mvn -Pnative -Dagent exec:exec@java-agent
105+
```
106+
The application will print a random saying. The agent generates the configuration files in the `target/native/agent-output` subdirectory.
107+
3. Build a static native executable:
108+
```
109+
mvn -Pnative -Dagent package
110+
```
111+
When the command completes, a native executable, `staticfortune`, is generated in the `/target` directory of the project and ready for use.
112+
113+
4. Run the demo by launching a native executable directly or with the Maven profile:
114+
115+
```
78116
./target/staticfortune
79117
```
80118
The application should behave in exactly the same way as the first implementation.
@@ -106,7 +144,7 @@ The first implementation of the fortune application uses the [Jackson JSON parse
106144
107145
The reduction in size is due to the use of the `--initialize-at-build-time=` argument used with the [Native Image Maven plugin](use-native-image-maven-plugin.md).
108146
109-
2. The build created a file named _staticfortune.bgv_. Load it into the GraalVM Dashboard to view the composition of the `staticfortune` native executable.
147+
5. The build created a file named _staticfortune.bgv_. Load it into the GraalVM Dashboard to view the composition of the `staticfortune` native executable.
110148
111149
![Code Size Breakdown View](img/staticfortune-codesize.png)
112150

0 commit comments

Comments
 (0)