Skip to content

Commit

Permalink
cells: allow configuration selection for JFR
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kofemann committed Apr 4, 2023
1 parent 5415410 commit 7c14b06
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/cells/src/main/java/dmg/cells/nucleus/SystemCell.java
Expand Up @@ -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;
Expand Down Expand Up @@ -146,22 +147,30 @@ 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<String> {

@Argument(usage = "Predefined JFR configuration.", metaVar = "configuration", required = false, valueSpec = "[default|profile|<path>]")
String config = "default";

@Override
public String call() throws Exception {

if (recording != null) {
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();
}
}

Expand Down

0 comments on commit 7c14b06

Please sign in to comment.