From 7c14b06ebecde35d66abadcd676aec69b8a16a01 Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Sun, 2 Apr 2023 22:35:06 +0200 Subject: [PATCH] cells: allow configuration selection for JFR Motivation: Java flight recorder starts according to a specific configuration, which can be either one of the pre-defined options provided by JVM or user supplied configuration. Modification: Update `jfr start` admin command to accept ether pre-defined configuration name ('default' or 'profile') or a path to customized configuration file. Result: More flexible out-of-box profiling. Acked-by: Albert Rossi Target: master Require-book: no Require-notes: yes --- .../main/java/dmg/cells/nucleus/SystemCell.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/cells/src/main/java/dmg/cells/nucleus/SystemCell.java b/modules/cells/src/main/java/dmg/cells/nucleus/SystemCell.java index 207eaaeca5d..2932b75e6ac 100644 --- a/modules/cells/src/main/java/dmg/cells/nucleus/SystemCell.java +++ b/modules/cells/src/main/java/dmg/cells/nucleus/SystemCell.java @@ -5,6 +5,7 @@ import com.google.common.base.Throwables; import com.google.common.util.concurrent.MoreExecutors; import dmg.util.AuthorizedString; +import dmg.util.command.Argument; import dmg.util.command.Command; import dmg.util.command.Option; import dmg.util.logback.FilterShell; @@ -146,9 +147,16 @@ public String call() { } - @Command(name = "jfr start", hint = "Starts Java flight recorder", description = "Starts JFR") + @Command(name = "jfr start", hint = "Starts Java flight recorder.", + description = "Starts Java flight recorder. The JFR configuration can be specified as optional" + + " parameter: either as one of JVM pre-defined configuration names 'default' or 'profile', or" + + " as an absolute path to a custom configuration." + ) public class StartJFR implements Callable { + @Argument(usage = "Predefined JFR configuration.", metaVar = "configuration", required = false, valueSpec = "[default|profile|]") + String config = "default"; + @Override public String call() throws Exception { @@ -156,12 +164,13 @@ public String call() throws Exception { return "Another record in progress."; } - Configuration configuration = Configuration.getConfiguration("default"); + var configuration = config.startsWith("/") ? + Configuration.create(Path.of(config)) : Configuration.getConfiguration(config); recording = new Recording(configuration); recording.setName(getCellDomainName()); recording.start(); - return "enabled"; + return "enabled with config: " + configuration.getName(); } }