diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java index 507f88db286d7..933451240e21d 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java @@ -241,11 +241,20 @@ public String getEffectiveBuilderImage() { public Optional> containerRuntimeOptions; /** - * If the resulting image should allow VM introspection + * If the resulting image should allow VM introspection. + * + * @deprecated Use {@code quarkus.native.monitoring} instead. */ @ConfigItem + @Deprecated public boolean enableVmInspection; + /** + * Enable monitoring options that allow the VM to be inspected at run time. + */ + @ConfigItem + public Optional> monitoring; + /** * If full stack traces are enabled in the resulting image */ @@ -452,4 +461,12 @@ public static enum BuilderImageProvider { GRAALVM, MANDREL; } + + public enum MonitoringOption { + HEAPDUMP, + JVMSTAT, + JFR, + ALL, + TRUE // only needed to support -Dquarkus.native.monitoring + } } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 197d066511c49..d53fab22c7eca 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -21,6 +22,7 @@ import java.util.stream.Stream; import org.apache.commons.lang3.SystemUtils; +import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.logging.Logger; import io.quarkus.bootstrap.util.IoUtils; @@ -623,6 +625,7 @@ public Builder setNativeImageName(String nativeImageName) { return this; } + @SuppressWarnings("deprecation") public NativeImageInvokerInfo build() { List nativeImageArgs = new ArrayList<>(); boolean enableSslNative = false; @@ -824,6 +827,21 @@ public NativeImageInvokerInfo build() { if (nativeConfig.enableVmInspection) { nativeImageArgs.add("-H:+AllowVMInspection"); } + + if (nativeConfig.monitoring.isPresent()) { + List monitoringOptions = nativeConfig.monitoring.get(); + if (monitoringOptions.stream().anyMatch(o -> o == NativeConfig.MonitoringOption.TRUE + || o == NativeConfig.MonitoringOption.ALL)) { + nativeImageArgs.add("--enable-monitoring"); + } + nativeImageArgs + .add("--enable-monitoring=" + monitoringOptions.stream().map(o -> o.name().toLowerCase( + Locale.ROOT)).collect(Collectors.joining(","))); + } else if (ConfigProvider.getConfig().getConfigValue("quarkus.native.monitoring").getValue() != null) { + // this only happens when a user has configured 'quarkus.native.monitoring=' + // we want to support this use case as GraalVM allows the use of '--enable-monitoring' without an argument + nativeImageArgs.add("--enable-monitoring"); + } if (nativeConfig.autoServiceLoaderRegistration) { nativeImageArgs.add("-H:+UseServiceLoaderFeature"); //When enabling, at least print what exactly is being added: