Module: NewRelic::LanguageSupport

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

Defined Under Namespace

Modules: Control

Constant Summary collapse

@@forkable =
nil

Instance Method Summary collapse

Instance Method Details

#broken_gc?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
# File 'lib/new_relic/language_support.rb', line 48

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)


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/new_relic/language_support.rb', line 26

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

#test_forkabilityObject



83
84
85
86
87
88
89
90
91
# File 'lib/new_relic/language_support.rb', line 83

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)


40
41
42
43
44
45
46
# File 'lib/new_relic/language_support.rb', line 40

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

#using_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
# File 'lib/new_relic/language_support.rb', line 78

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

#with_cautious_gcObject



70
71
72
73
74
75
76
# File 'lib/new_relic/language_support.rb', line 70

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

#with_disabled_gcObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/new_relic/language_support.rb', line 55

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