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.
  • Loading branch information
areman authored and kares committed Feb 18, 2018
1 parent 0101188 commit b22e2ce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Expand Up @@ -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();

Expand Down
Expand Up @@ -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;

/**
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Expand Up @@ -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.");
Expand Down
13 changes: 12 additions & 1 deletion core/src/test/java/org/jruby/runtime/profile/ProfilingTest.java
Expand Up @@ -29,6 +29,7 @@ public void testNoProfilingServerAvailableIfProfilingIsDisabled() {
Ruby ruby = Ruby.newInstance( configOne );

assertNull(ruby.getProfilingService());

}
/**
* Tests the {@link org.jruby.runtime.profile.ProfilingServiceLookup} too
Expand All @@ -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.