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.

Defined Under Namespace

Modules: Control

Constant Summary collapse

@@forkable =
nil

Instance Method Summary collapse

Instance Method Details

#broken_gc?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
# File 'lib/new_relic/language_support.rb', line 52

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)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/new_relic/language_support.rb', line 30

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



87
88
89
90
91
92
93
94
95
# File 'lib/new_relic/language_support.rb', line 87

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)


44
45
46
47
48
49
50
# File 'lib/new_relic/language_support.rb', line 44

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

#using_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
# File 'lib/new_relic/language_support.rb', line 82

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

#with_cautious_gcObject



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

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

#with_disabled_gcObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/new_relic/language_support.rb', line 59

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