Module: OneApm::LanguageSupport
- Extended by:
- LanguageSupport
- Included in:
- LanguageSupport
- Defined in:
- lib/one_apm/support/language_support.rb
Constant Summary collapse
- @@forkable =
nil
Instance Method Summary collapse
- #broken_gc? ⇒ Boolean
- #can_fork? ⇒ Boolean
- #constant_is_defined?(const_name) ⇒ Boolean
- #gc_profiler_enabled? ⇒ Boolean
- #gc_profiler_usable? ⇒ Boolean
- #jruby? ⇒ Boolean
-
#needs_syck? ⇒ Boolean
need to use syck rather than psych when possible.
- #object_space_usable? ⇒ Boolean
- #ree? ⇒ Boolean
- #rubinius? ⇒ Boolean
- #supports_string_encodings? ⇒ Boolean
- #test_forkability ⇒ Object
- #using_engine?(engine) ⇒ Boolean
- #using_version?(version) ⇒ Boolean
- #with_cautious_gc ⇒ Object
- #with_disabled_gc ⇒ Object
Instance Method Details
#broken_gc? ⇒ Boolean
35 36 37 38 39 40 |
# File 'lib/one_apm/support/language_support.rb', line 35 def broken_gc? OneApm::LanguageSupport.using_version?('1.8.7') && RUBY_PATCHLEVEL < 348 && !OneApm::LanguageSupport.using_engine?('jruby') && !OneApm::LanguageSupport.using_engine?('rbx') end |
#can_fork? ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/one_apm/support/language_support.rb', line 13 def can_fork? # this is expensive to check, so we should only check once return @@forkable if @@forkable != nil if Process.respond_to?(:fork) # if this is not 1.9.2 or higher, we have to make sure @@forkable = ::RUBY_VERSION < '1.9.2' ? test_forkability : true else @@forkable = false end @@forkable end |
#constant_is_defined?(const_name) ⇒ Boolean
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/one_apm/support/language_support.rb', line 122 def constant_is_defined?(const_name) const_name.to_s.sub(/\A::/,'').split('::').inject(Object) do |namespace, name| begin result = namespace.const_get(name) # const_get looks up the inheritence chain, so if it's a class # in the constant make sure we found the one in our namespace. # # Can't help if the constant isn't a class... if result.is_a?(Module) expected_name = "#{namespace}::#{name}".gsub(/^Object::/, "") return false unless expected_name == result.to_s end result rescue NameError false end end end |
#gc_profiler_enabled? ⇒ Boolean
73 74 75 76 77 78 79 |
# File 'lib/one_apm/support/language_support.rb', line 73 def gc_profiler_enabled? if gc_profiler_usable? && ::GC::Profiler.enabled? && !OneApm::Manager.config[:disable_gc_profiler] true else false end end |
#gc_profiler_usable? ⇒ Boolean
65 66 67 68 69 70 71 |
# File 'lib/one_apm/support/language_support.rb', line 65 def gc_profiler_usable? if defined?(::GC::Profiler) && !jruby? true else false end end |
#jruby? ⇒ Boolean
91 92 93 |
# File 'lib/one_apm/support/language_support.rb', line 91 def jruby? defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' end |
#needs_syck? ⇒ Boolean
need to use syck rather than psych when possible
7 8 9 10 |
# File 'lib/one_apm/support/language_support.rb', line 7 def needs_syck? !OneApm::LanguageSupport.using_engine?('jruby') && OneApm::LanguageSupport.using_version?('1.9.2') end |
#object_space_usable? ⇒ Boolean
81 82 83 84 85 86 87 88 89 |
# File 'lib/one_apm/support/language_support.rb', line 81 def object_space_usable? if defined?(::JRuby) && JRuby.respond_to?(:runtime) JRuby.runtime.is_object_space_enabled elsif defined?(::ObjectSpace) && !rubinius? true else false end end |
#ree? ⇒ Boolean
99 100 101 |
# File 'lib/one_apm/support/language_support.rb', line 99 def ree? defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Ruby Enterprise Edition/ end |
#rubinius? ⇒ Boolean
95 96 97 |
# File 'lib/one_apm/support/language_support.rb', line 95 def rubinius? defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' end |
#supports_string_encodings? ⇒ Boolean
108 109 110 |
# File 'lib/one_apm/support/language_support.rb', line 108 def supports_string_encodings? RUBY_VERSION >= '1.9.0' end |
#test_forkability ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/one_apm/support/language_support.rb', line 112 def test_forkability child = Process.fork { exit! } # calling wait here doesn't seem like it should necessary, but it seems to # resolve some weird edge cases with resque forking. Process.wait child true rescue NotImplementedError false end |
#using_engine?(engine) ⇒ Boolean
27 28 29 30 31 32 33 |
# File 'lib/one_apm/support/language_support.rb', line 27 def using_engine?(engine) if defined?(::RUBY_ENGINE) ::RUBY_ENGINE == engine else engine == 'ruby' end end |
#using_version?(version) ⇒ Boolean
103 104 105 106 |
# File 'lib/one_apm/support/language_support.rb', line 103 def using_version?(version) numbers = version.split('.') numbers == ::RUBY_VERSION.split('.')[0, numbers.size] end |
#with_cautious_gc ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/one_apm/support/language_support.rb', line 57 def with_cautious_gc if broken_gc? with_disabled_gc { yield } else yield end end |
#with_disabled_gc ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/one_apm/support/language_support.rb', line 42 def with_disabled_gc if defined?(::GC) && ::GC.respond_to?(:disable) val = nil begin ::GC.disable val = yield ensure ::GC.enable end val else yield end end |