Skip to content

Instantly share code, notes, and snippets.

@BanzaiMan
Created November 25, 2009 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BanzaiMan/242782 to your computer and use it in GitHub Desktop.
Save BanzaiMan/242782 to your computer and use it in GitHub Desktop.
set org.jruby.runtime.load.LoadService.DEBUG_LOAD_TIMINGS at run time
diff --git a/src/org/jruby/RubyInstanceConfig.java b/src/org/jruby/RubyInstanceConfig.java
index 2451a3b..a02a4e6 100644
--- a/src/org/jruby/RubyInstanceConfig.java
+++ b/src/org/jruby/RubyInstanceConfig.java
@@ -230,6 +230,9 @@ public class RubyInstanceConfig {
public static final boolean DEBUG_LOAD_SERVICE
= SafePropertyAccessor.getBoolean("jruby.debug.loadService", false);
+ public static final boolean DEBUG_LOAD_TIMINGS
+ = SafePropertyAccessor.getBoolean("jruby.debug.loadService.timing", false);
+
public static final boolean DEBUG_LAUNCHING
= SafePropertyAccessor.getBoolean("jruby.debug.launch", false);
@@ -237,11 +240,11 @@ public class RubyInstanceConfig {
= SafePropertyAccessor.getBoolean("jruby.jump.backtrace", false);
public static interface LoadServiceCreator {
- LoadService create(Ruby runtime);
+ LoadService create(Ruby runtime, boolean loadTimings);
LoadServiceCreator DEFAULT = new LoadServiceCreator() {
- public LoadService create(Ruby runtime) {
- return new LoadService(runtime);
+ public LoadService create(Ruby runtime, boolean loadTimings) {
+ return new LoadService(runtime, loadTimings);
}
};
}
@@ -375,7 +378,7 @@ public class RubyInstanceConfig {
}
public LoadService createLoadService(Ruby runtime) {
- return this.creator.create(runtime);
+ return this.creator.create(runtime, DEBUG_LOAD_TIMINGS);
}
public String getBasicUsageHelp() {
@@ -514,6 +517,8 @@ public class RubyInstanceConfig {
.append(" Set whether full traces are enabled (c-call/c-return). Default is false.\n")
.append(" jruby.debug.loadService=true|false\n")
.append(" Log the process of locating and loading libraries. Default is false.\n")
+ .append(" jruby.debug.loadService.timing=true|false\n")
+ .append(" Print load timings for each require'd library. Default is false.\n")
.append(" jruby.jump.backtrace=true|false\n")
.append(" Make non-local flow jumps generate backtraces. Default is false.\n")
.append("\nDEBUGGING/LOGGING:\n")
diff --git a/src/org/jruby/runtime/load/LoadService.java b/src/org/jruby/runtime/load/LoadService.java
index 5a31b03..c8ff16f 100644
--- a/src/org/jruby/runtime/load/LoadService.java
+++ b/src/org/jruby/runtime/load/LoadService.java
@@ -125,18 +125,8 @@ import org.jruby.util.JRubyFile;
* @author jpetersen
*/
public class LoadService {
- // Enabling this would print out load timings for every require'd library.
- // Currently, this is a simple compile-time flag, but we can make it into
- // a configurable option, if there is a need.
- private final static boolean DEBUG_LOAD_TIMINGS = false;
- private final static LoadTimer LOAD_TIMER;
- static {
- if (DEBUG_LOAD_TIMINGS) {
- LOAD_TIMER = new TracingLoadTimer();
- } else {
- LOAD_TIMER = new LoadTimer();
- }
- }
+ private static boolean DEBUG_LOAD_TIMINGS = false;
+ private static LoadTimer LOAD_TIMER = new LoadTimer();
public enum SuffixType {
Source, Extension, Both, Neither;
@@ -174,8 +164,14 @@ public class LoadService {
protected final Ruby runtime;
- public LoadService(Ruby runtime) {
+ public LoadService(Ruby runtime, boolean loadTimings) {
this.runtime = runtime;
+ DEBUG_LOAD_TIMINGS = loadTimings;
+ if (DEBUG_LOAD_TIMINGS) {
+ LOAD_TIMER = new TracingLoadTimer();
+ } else {
+ LOAD_TIMER = new LoadTimer();
+ }
}
public void init(List additionalDirectories) {
--
1.6.4
surfboard:jruby[git:personal]$ jruby -J-Djruby.debug.loadService.timing=true -b -e "require 'rubygems'"
-> builtin/core_ext/symbol
<- builtin/core_ext/symbol - 185ms
-> enumerator
<- enumerator - 53ms
-> rubygems
-> rubygems/defaults
<- rubygems/defaults - 42ms
-> thread
<- thread - 30ms
-> etc
<- etc - 12ms
-> rbconfig
<- rbconfig - 32ms
-> rubygems/exceptions
<- rubygems/exceptions - 56ms
-> rubygems/version
-> rubygems/requirement
<- rubygems/requirement - 36ms
<- rubygems/version - 187ms
-> rubygems/requirement
<- rubygems/requirement - 0ms
-> rubygems/dependency
<- rubygems/dependency - 8ms
-> rubygems/gem_path_searcher
<- rubygems/gem_path_searcher - 5ms
-> rubygems/source_index
-> rubygems/user_interaction
<- rubygems/user_interaction - 29ms
-> rubygems/specification
-> rubygems/version
<- rubygems/version - 0ms
-> rubygems/requirement
<- rubygems/requirement - 0ms
-> rubygems/platform
<- rubygems/platform - 16ms
<- rubygems/specification - 277ms
<- rubygems/source_index - 333ms
-> rubygems/platform
<- rubygems/platform - 0ms
-> rubygems/builder
<- rubygems/builder - 21ms
-> rubygems/defaults/operating_system
<- rubygems/defaults/operating_system - 47ms
-> rubygems/defaults/jruby
-> rubygems/config_file
-> yaml
-> stringio
<- stringio - 13ms
-> yaml/compat
<- yaml/compat - 3ms
-> yaml/error
<- yaml/error - 2ms
-> yaml/yecht
-> yecht
<- yecht - 146ms
-> yaml/basenode
-> yaml/ypath
<- yaml/ypath - 2ms
<- yaml/basenode - 10ms
<- yaml/yecht - 171ms
-> yaml/tag
<- yaml/tag - 5ms
-> yaml/stream
<- yaml/stream - 2ms
-> yaml/constants
<- yaml/constants - 3ms
-> yaml/rubytypes
-> date
-> rational
<- rational - 66ms
-> date/format
-> rational
<- rational - 0ms
<- date/format - 98ms
<- date - 388ms
-> yaml/compat
<- yaml/compat - 0ms
<- yaml/rubytypes - 510ms
-> yaml/types
-> yaml/compat
<- yaml/compat - 0ms
<- yaml/types - 10ms
<- yaml - 750ms
-> Win32API
-> rbconfig
<- rbconfig - 0ms
<- Win32API - 23ms
<- rubygems/config_file - 826ms
-> rubygems/source_index
<- rubygems/source_index - 1ms
<- rubygems/defaults/jruby - 847ms
-> rubygems/config_file
<- rubygems/config_file - 0ms
-> rubygems/custom_require
-> rubygems
<- rubygems - 0ms
<- rubygems/custom_require - 31ms
-> fileutils
-> etc
<- etc - 1ms
<- fileutils - 150ms
-> fileutils
<- fileutils - 0ms
-> fileutils
<- fileutils - 1ms
-> jruby/util
<- jruby/util - 202ms
-> rubygems/command_manager
-> timeout
<- timeout - 32ms
-> rubygems/command
-> optparse
<- optparse - 176ms
-> rubygems/user_interaction
<- rubygems/user_interaction - 0ms
<- rubygems/command - 199ms
-> rubygems/user_interaction
<- rubygems/user_interaction - 0ms
<- rubygems/command_manager - 252ms
-> commands/abstract_command
-> rubygems/local_remote_options
-> uri
-> uri/common
<- uri/common - 171ms
-> uri/generic
-> uri/common
<- uri/common - 0ms
<- uri/generic - 104ms
-> uri/ftp
-> uri/generic
<- uri/generic - 0ms
<- uri/ftp - 13ms
-> uri/http
-> uri/generic
<- uri/generic - 0ms
<- uri/http - 2ms
-> uri/https
-> uri/http
<- uri/http - 0ms
<- uri/https - 3ms
-> uri/ldap
-> uri/generic
<- uri/generic - 1ms
<- uri/ldap - 25ms
-> uri/ldaps
-> uri/ldap
<- uri/ldap - 1ms
<- uri/ldaps - 2ms
-> uri/mailto
-> uri/generic
<- uri/generic - 0ms
<- uri/mailto - 11ms
<- uri - 359ms
-> rubygems
<- rubygems - 0ms
<- rubygems/local_remote_options - 376ms
<- commands/abstract_command - 402ms
-> commands/migrate
<- commands/migrate - 13ms
-> commands/owner
<- commands/owner - 11ms
-> commands/push
<- commands/push - 2ms
-> commands/tumble
<- commands/tumble - 2ms
<- rubygems - 6189ms
Runtime: 6239 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment