Skip to content

Commit

Permalink
make the profiling service configurable via java properties (#5027)
Browse files Browse the repository at this point in the history
Currently the profiling service can only configured as program argument. With this pull request it will be possible to configure it as java property, too. This feature is importent to start the profiling if you don't run the jruby executable. e.g. you use jruby in a war archive or as script engine in a standard java application.
areman authored and kares committed Feb 18, 2018
1 parent 0101188 commit b22e2ce
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -1529,7 +1529,7 @@ public static ClassLoader defaultClassLoader() {

private ProfilingMode profilingMode = Options.CLI_PROFILING_MODE.load();
private ProfileOutput profileOutput = new ProfileOutput(System.err);
private String profilingService;
private String profilingService = Options.CLI_PROFILING_SERVICE.load();;

private ClassLoader loader = defaultClassLoader();

Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.util.collections.NonBlockingHashMapLong;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -224,6 +224,7 @@ public class Options {
public static final Option<String> CLI_RECORD_SEPARATOR = string(CLI, "cli.record.separator", "\n", "Default record separator.");
public static final Option<String> CLI_BACKUP_EXTENSION = string(CLI, "cli.backup.extension", "Backup extension for in-place ARGV files. Same as -i.");
public static final Option<ProfilingMode> CLI_PROFILING_MODE = enumeration(CLI, "cli.profiling.mode", ProfilingMode.class, ProfilingMode.OFF, "Enable instrumented profiling modes.");
public static final Option<String> CLI_PROFILING_SERVICE = string(CLI, "cli.profiling.service", "Profiling service class to use.");
public static final Option<Boolean> CLI_RUBYGEMS_ENABLE = bool(CLI, "cli.rubygems.enable", true, "Enable/disable RubyGems.");
public static final Option<Boolean> CLI_DID_YOU_MEAN_ENABLE = bool(CLI, "cli.did_you_mean.enable", true, "Enable/disable did_you_mean.");
public static final Option<Boolean> CLI_RUBYOPT_ENABLE = bool(CLI, "cli.rubyopt.enable", true, "Enable/disable RUBYOPT processing at start.");
13 changes: 12 additions & 1 deletion core/src/test/java/org/jruby/runtime/profile/ProfilingTest.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ public void testNoProfilingServerAvailableIfProfilingIsDisabled() {
Ruby ruby = Ruby.newInstance( configOne );

assertNull(ruby.getProfilingService());

}
/**
* Tests the {@link org.jruby.runtime.profile.ProfilingServiceLookup} too
@@ -47,7 +48,17 @@ public void testProfilingServiceLookupWorks() {
assertTrue(ruby.getProfilingService() instanceof TestProfilingService);
} catch( RaiseException e ) {
//e.printStackTrace();
// TODO hwo to mock org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- jruby/profiler/shutdown_hook
// TODO how to mock org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- jruby/profiler/shutdown_hook
}
}

/**
* Tests if the profiling service can be configured as java property
*/
public void testProfilingServiceAsJavaProperty() {

// java -Djruby.cli.profiling.mode=SERVICE -Djruby.cli.profiling.service=org.jruby.runtime.profile.builtin.BuiltinProfilingService -cp jruby.jar org.jruby.Main

// TODO how to test it ??
}
}

0 comments on commit b22e2ce

Please sign in to comment.