Module: NewRelic::LanguageSupport

Extended by:
LanguageSupport
Included in:
LanguageSupport
Defined in:
lib/new_relic/language_support.rb

Overview

This file is distributed under New Relic’s license terms. See github.com/newrelic/rpm/blob/master/LICENSE for complete details.

Constant Summary collapse

@@forkable =
nil

Instance Method Summary collapse

Instance Method Details

#broken_gc?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'lib/new_relic/language_support.rb', line 37

def broken_gc?
  NewRelic::LanguageSupport.using_version?('1.8.7') &&
    RUBY_PATCHLEVEL < 348 &&
    !NewRelic::LanguageSupport.using_engine?('jruby') &&
    !NewRelic::LanguageSupport.using_engine?('rbx')
end

#can_fork?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/new_relic/language_support.rb', line 15

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

#needs_syck?Boolean

need to use syck rather than psych when possible

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/new_relic/language_support.rb', line 9

def needs_syck?
  !NewRelic::LanguageSupport.using_engine?('jruby') &&
       NewRelic::LanguageSupport.using_version?('1.9.2')
end

#object_space_enabled?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
# File 'lib/new_relic/language_support.rb', line 67

def object_space_enabled?
  if defined?(::JRuby) && JRuby.respond_to?(:runtime)
    JRuby.runtime.is_object_space_enabled
  else
    defined?(::ObjectSpace) ? true : false
  end
end

#test_forkabilityObject



80
81
82
83
84
85
86
87
88
# File 'lib/new_relic/language_support.rb', line 80

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

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/new_relic/language_support.rb', line 29

def using_engine?(engine)
  if defined?(::RUBY_ENGINE)
    ::RUBY_ENGINE == engine
  else
    engine == 'ruby'
  end
end

#using_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/new_relic/language_support.rb', line 75

def using_version?(version)
  numbers = version.split('.')
  numbers == ::RUBY_VERSION.split('.')[0, numbers.size]
end

#with_cautious_gcObject



59
60
61
62
63
64
65
# File 'lib/new_relic/language_support.rb', line 59

def with_cautious_gc
  if broken_gc?
    with_disabled_gc { yield }
  else
    yield
  end
end

#with_disabled_gcObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/new_relic/language_support.rb', line 44

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