#---------------------------------------------------------------# # # # (C) Copyright Rubysophic Inc. 2007-2008 # # All rights reserved. # # # # Use, duplication or disclosure of the code is not permitted # # unless licensed. # # # # Last Updated: 7/09/08 # #---------------------------------------------------------------# # # # RubyRun bootstrap code. # # # # To invoke RubyRun for Rails or a Ruby script, use command # # line option -r. # # # # ruby -rrubyrun script/server # # # # To remove RubyRun, simply remove the -r option. # # # # Generally no other code change is needed to run RubyRun. # # # #---------------------------------------------------------------# # BEGIN section of the code is always executed first. # 1. Intiialize globals, requires and includes # 2. Intitialize RubyRun runtime environment # Note. For $rubyrun_current_buffer, 1 - primary, 2 - secondary BEGIN { require 'rubyrun_globals' require 'rubyrun_instrumentor__' require 'rubyrun_monitor__' require 'rubyrun_initializer__' include RubyRunGlobals include RubyRunInitializer__ include RubyRunInstrumentor__ include RubyRunMonitor__ $rubyrun_include_hash = {} $rubyrun_exclude_hash = {} $rubyrun_thread_stack = {} $rubyrun_metrics_hash = {} $rubyrun_thread_local = {} $rubyrun_file_date_hash = {} $rubyrun_prime_buffer = [] $rubyrun_alt_buffer = [] $rubyrun_controller_classes = [] $rubyrun_current_buffer = 1 $rubyrun_lock = Monitor.new init_rubyrun } # RubyRun uses 2 traps to get control from the interpreter # to decide if a method should be instrumented or passed # # 1. When an instance method is added when a module/class is # loaded, or dynamically created # 2. When a module/static/singleton method is added when a # module/class is loaded, or dynamically created class Module # module/class instance method trap def method_added(id, *args) RubyRunInstrumentor__.instrument_it?('i', self, id) end end class Object # class object/object singleton method trap def singleton_method_added(id, *args) RubyRunInstrumentor__.instrument_it?('s', self, id) end end # 1. Instrument Thread.new method to provide a begin/rescue clause # to catch failure for providing a stack trace # # 2. Start the monitor timer thread instrument_thread_new start_thread_monitor puts '*** RubyRun successfully started. ***'