Skip to content

Commit

Permalink
Merge pull request #261 from graalvm/og/graalvm-dashboard
Browse files Browse the repository at this point in the history
[GR-52382] Update demos to not use GraalVM Dashboard but use Native Image Build Reports instead.
  • Loading branch information
olyagpl committed Apr 27, 2024
2 parents 10d3568 + 867fa7e commit 245fad6
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/fortune-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ jobs:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
version: ${{ matrix.version }}
java-version: '17.0.10'
java-version: '21'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run 'fortune'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/multithreading-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
java-version: ['21', 'dev']
java-version: ['22', 'latest-ea']
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ cd graalvm-demos
</tr>
<tr>
<td align="left" width="30%"><a href="/fortune-demo/">fortune-demo</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/fortune-demo.yml"><img alt="fortune-demo" src="https://github.com/graalvm/graalvm-demos/actions/workflows/fortune-demo.yml/badge.svg" /></a></td>
<td align="left" width="70%">A fortune teller Unix program. Run it in JIT, build a native executable, or build a mostly-static native executable, using Gradle or Maven build tools.<br><strong>Technologies: </strong>Native Image, Native Build Tools<br><strong>Reference: </strong><a href="https://www.graalvm.org/latest/reference-manual/native-image/guides/use-graalvm-dashboard/">Use GraalVM Dashboard to Optimize the Size of a Native Executable</a></td>
<td align="left" width="70%">A fortune teller Unix program. Run it in JIT, build a native executable, or build a mostly-static native executable, using Gradle or Maven build tools.<br><strong>Technologies: </strong>Native Image, Native Build Tools Maven plugin <br><strong>Reference: </strong><a href="https://graalvm.github.io/native-build-tools/latest/maven-plugin-quickstart.html">Getting Started with Maven Plugin for GraalVM Native Image</a></td>
</tr>
<tr>
<td align="left" width="30%"><a href="/multithreading-demo/">multithreading-demo</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml"><img alt="streams" src="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml/badge.svg" /></a></td>
<td align="left" width="70%">Demonstrates how to optimize a Java application that does synchronous and asynchronous threads execution<br><strong>Technologies: </strong>Native Image, Native Build Tools Maven plugin, GraalVM Dashboard <br><strong>Reference: </strong><a href="https://medium.com/graalvm/making-sense-of-native-image-contents-741a688dab4d">Making sense of Native Image contents</a></td>
<td align="left" width="70%">Demonstrates how to optimize a Java application that does synchronous and asynchronous threads execution<br><strong>Technologies: </strong>Native Image Build Reports, Native Build Tools Maven plugin <br><strong>Reference: </strong><a href="https://medium.com/graalvm/making-sense-of-native-image-contents-741a688dab4d">Making sense of Native Image contents</a></td>
</tr>
<tr>
<td align="left" width="30%"><a href="/native-image-configure-examples/">native-image-configure-examples</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml"><img alt="streams" src="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml/badge.svg" /></a></td>
Expand Down
20 changes: 13 additions & 7 deletions fortune-demo/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Java Fortune Demo For GraalVM Dashboard

The Fortune demo is provided to showcase the applicability of [GraalVM Dashboard](https://www.graalvm.org/docs/tools/dashboard/) - a web-based tool that visualizes the composition of a native executable. (Go to the [GraalVM website](https://www.graalvm.org/reference-manual/native-image/) to learn more about Native Image).
# Native Image Fortune Demo

The demo is a Java program that simulates the traditional `fortune` Unix program (for more information, see [fortune](https://en.wikipedia.org/wiki/Fortune_(Unix))). The data for the fortune phrases is provided by [YourFortune](https://github.com/your-fortune).

Expand All @@ -14,10 +12,11 @@ The plugin will also gather the diagnostic data at build time and write it to a

## Preparation

1. Download and install the latest GraalVM JDK using [SDKMAN!](https://sdkman.io/).
1. Download and install the latest GraalVM for JDK 21 using [SDKMAN!](https://sdkman.io/).
```bash
sdk install java 17.0.9-graal
sdk install java 21.0.3-graal
```

2. Download or clone GraalVM demos repository:
```bash
git clone https://github.com/graalvm/graalvm-demos
Expand All @@ -34,6 +33,7 @@ The plugin will also gather the diagnostic data at build time and write it to a
```bash
mvn clean package
```

3. Run your application with the [agent](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#agent-support), on the JVM:
```bash
mvn -Pnative -Dagent exec:exec@java-agent
Expand All @@ -46,7 +46,6 @@ The plugin will also gather the diagnostic data at build time and write it to a
mvn -Pnative -Dagent package
```
When the command completes, a native executable, `fortune`, is generated in the _target_ directory of the project and ready for use.
The diagnostic data for GraalVM Dashboard is written to a dump file _target/fortune.bgv_.

5. Run the application by launching a native executable directly or with the Maven profile:

Expand All @@ -68,19 +67,23 @@ The plugin will also gather the diagnostic data at build time and write it to a
```bash
./gradlew run
```

3. Run your application with the [agent](https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html#agent-support), on the JVM. To enable the agent with the Native Image Gradle plugin, pass the `-Pagent` option to any Gradle tasks that extends `JavaForkOptions`:
```bash
./gradlew -Pagent run
```
The agent captures and records the dynamic features encountered during a test run into multiple *-config.json files.

4. Once the metadata is collected, copy it into the project’s _/META-INF/native-image/_ directory using the `metadataCopy` task:
```bash
./gradlew metadataCopy --task run --dir src/main/resources/META-INF/native-image
```

5. Build a native executable using configuration collected by the agent:
```bash
./gradlew nativeCompile
```

When the command completes, a native executable, `fortune`, is generated in the _build/native/nativeCompile_ directory of the project and ready for use.
6. Run the application from the native executable:
```bash
Expand All @@ -95,22 +98,25 @@ The StaticFortune project contains an enhanced version of the same application a
```bash
cd ../staticfortune
```

2. Build the project:
```bash
mvn clean package
```

3. Run your application with the [agent](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#agent-support), on the JVM:
```bash
mvn -Pnative -Dagent exec:exec@java-agent
```
The application will print a random saying.
The agent generates the configuration files in the _target/native/agent-output_ subdirectory.

4. Build a static native executable:
```bash
mvn -Pnative -Dagent package
```
When the command completes, a native executable, `staticfortune`, is generated in the _target_ directory of the project and ready for use.
The diagnostic data for GraalVM Dashboard is written to a dump file _target/staticfortune.bgv_.

5. Run the demo by launching a native executable directly or with the Maven profile:
```bash
./target/staticfortune
Expand Down
2 changes: 1 addition & 1 deletion fortune-demo/fortune-gradle/fortune/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'org.graalvm.buildtools.native' version '0.9.28'
id 'org.graalvm.buildtools.native' version '0.10.1'
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 3 additions & 6 deletions fortune-demo/fortune-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<native.maven.plugin.version>0.9.28</native.maven.plugin.version>
<native.maven.plugin.version>0.10.1</native.maven.plugin.version>
<junit.jupiter.version>5.8.1</junit.jupiter.version>
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
Expand Down Expand Up @@ -50,9 +50,6 @@
<configuration>
<imageName>${imageName}</imageName>
<fallback>false</fallback>
<buildArgs>
<buildArg>-H:DashboardDump=fortune -H:+DashboardAll</buildArg>
</buildArgs>
<agent>
<enabled>true</enabled>
<defaultMode>Standard</defaultMode>
Expand Down Expand Up @@ -101,8 +98,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>

Expand Down
8 changes: 4 additions & 4 deletions fortune-demo/staticfortune/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<native.maven.plugin.version>0.9.28</native.maven.plugin.version>
<native.maven.plugin.version>0.10.1</native.maven.plugin.version>
<junit.jupiter.version>5.8.1</junit.jupiter.version>
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
Expand Down Expand Up @@ -52,7 +52,7 @@
<fallback>false</fallback>
<buildArgs>
<buildArg>
-H:DashboardDump=staticfortune -H:+DashboardAll --initialize-at-build-time=demo.StaticFortune,com.fasterxml.jackson.databind.ext.Java7SupportImpl
--initialize-at-build-time=demo.StaticFortune,com.fasterxml.jackson.databind.ext.Java7SupportImpl
</buildArg>
</buildArgs>
<agent>
Expand Down Expand Up @@ -103,8 +103,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>

Expand Down
17 changes: 8 additions & 9 deletions multithreading-demo/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Java Multithreading Demo For GraalVM Dashboard

Multithreading demo is provided to showcase the applicability of [GraalVM Dashboard](https://www.graalvm.org/docs/tools/dashboard/) - a web-based dashboard for visualizing aspects of dynamic and static compilations in GraalVM, in particular, [Native Image](https://www.graalvm.org/reference-manual/native-image/).
# Native Image Multithreading Demo

The demo is a Java program which does synchronous and asynchronous threads execution.
Each thread loops through exactly the same array of integers and generates a stream of pseudorandom numbers.
The program calculates the time taken to perform the task synchronously and asynchronously.

Multithreading demo is comprised of two sub-projects, each built with Maven: **Multithreading Demo Oversized** and **Multithreading Demo Improved**.
The _pom.xml_ file of each sub-project includes the [Native Image Maven plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html), which instructs Maven to generate a native image of a JAR file with all dependencies at the `mvn package` step.
The plugin will also gather the diagnostic information during the native image build and write that data to a dump file in the target directory.
The _pom.xml_ file of each sub-project includes the [Native Image Maven plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html), which instructs Maven to generate a native executable of a JAR file with all dependencies at the `mvn package` step.

The plugin also generates a report using the [Native Image Build Reports](https://www.graalvm.org/latest/reference-manual/native-image/overview/Options/#build-output-and-build-report) feature in the _target_ directory with useful visualizations and comprehensive insights into different metrics of the native executable and the build process itself.

```xml
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.28</version>
<version>0.10.1</version>
<extensions>true</extensions>
<executions>
<execution>
Expand All @@ -30,7 +29,7 @@ The plugin will also gather the diagnostic information during the native image b
<fallback>false</fallback>
<buildArgs>
<buildArg>
--no-fallback -H:DashboardDump=dumpfile -H:+DashboardAll --initialize-at-build-time
-H:+UnlockExperimentalVMOptions -H:+BuildReport --initialize-at-build-time
</buildArg>
</buildArgs>
<agent>
Expand All @@ -45,7 +44,7 @@ The plugin will also gather the diagnostic information during the native image b

1. Download and install the latest GraalVM JDK using [SDKMAN!](https://sdkman.io/).
```bash
sdk install java 21.0.1-graal
sdk install java 22.0.1-graal
```

2. Download or clone the repository and navigate into the `multithreading-demo/multithreading-demo-oversized_` directory:
Expand Down Expand Up @@ -92,4 +91,4 @@ Multithreading Demo Improved contains an enhanced version of the same program.

### Learn More

Learn more about GraalVM tooling for Native Image on the [website](https://www.graalvm.org/latest/reference-manual/native-image/debugging-and-diagnostics/).
Learn how you can optimize a Java application by applying Profile-guided optimization (PGO) and inspect a profile using [Native Image Build Reports](https://www.graalvm.org/jdk22/reference-manual/native-image/optimizations-and-performance/PGO/build-reports/).
8 changes: 4 additions & 4 deletions multithreading-demo/multithreading-demo-improved/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<version>1.0</version>

<properties>
<native.maven.plugin.version>0.9.28</native.maven.plugin.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<native.maven.plugin.version>0.10.1</native.maven.plugin.version>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
</properties>

<dependencies>
Expand Down Expand Up @@ -88,7 +88,7 @@
<fallback>false</fallback>
<buildArgs>
<buildArg>
-H:Dump=dumpfileimproved -H:+DashboardAll --initialize-at-build-time
-H:+UnlockExperimentalVMOptions -H:+BuildReport --initialize-at-build-time
</buildArg>
</buildArgs>
<agent>
Expand Down
9 changes: 4 additions & 5 deletions multithreading-demo/multithreading-demo-oversized/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
<version>1.0</version>

<properties>
<native.maven.plugin.version>0.9.28</native.maven.plugin.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<native.maven.plugin.version>0.10.1</native.maven.plugin.version>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
</properties>


<dependencies>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -89,7 +88,7 @@
<fallback>false</fallback>
<buildArgs>
<buildArg>
--no-fallback -H:DashboardDump=dumpfileoversized -H:+DashboardAll --initialize-at-build-time
--no-fallback -H:+UnlockExperimentalVMOptions -H:+BuildReport --initialize-at-build-time
</buildArg>
</buildArgs>
<agent>
Expand Down

0 comments on commit 245fad6

Please sign in to comment.