Sha256: 3318c2a4d086571dec490e80845a05fa594adbaa9f37a1a93f095ca7695b9d77

Contents?: true

Size: 1.97 KB

Versions: 16

Compression:

Stored size: 1.97 KB

Contents

require "mkmf"

def abort_on_missing_ruby_header(name)
  abort(
  <<-MSG

      PlainAPM extension needs #{name} Ruby library header to compile.

      If Ruby is installed from a package on your system, please ensure the
      corresponding Ruby development package is installed as well.

      E.g. on Debian/Ubuntu, this would be achieved by running

      sudo apt install ruby-dev

      on CentOS/Fedora, run

      sudo yum install ruby-devel

      etc...
  MSG
  )
end

def warn_on_ruby_ractor_bugs
  warn(
  <<-MSG

     PlainAPM extension to track object allocation on a per-thread basis is
     built on top of Ruby's TracePoint API.

     However, the currently running Ruby version contains bugs which,
     when Tracepoints are used in together with Ractors, can cause
     crashes or inconsistent tracing results.

     Per-thread object allocation tracing will be disabled.

     If you are sure your app is not using Ractors, you can override this by
     installing plain_apm with --enable-object-tracing-override flag:

     gem install plain_apm -- --enable-object-tracing-override

     When using bundler, you can configure it to pass this flag to the gem
     install by running:

     bundle config set --global build.plain_apm --enable-object-tracing-override

     See also:

     https://bugs.ruby-lang.org/issues/18464
     https://bugs.ruby-lang.org/issues/19112

  MSG
  )
end

def try_ruby(file)
  system("ruby", "-W0", File.join(__dir__, file), [:out, :err] => File::NULL)
end

def enable_object_tracing
  $defs.push("-DOBJECT_TRACING_ENABLED") unless $defs.include? "-DOBJECT_TRACING_ENABLED"
end

%w(
  ruby/ruby.h
  ruby/debug.h
).each do |header|
  have_header(header) or abort_on_missing_ruby_header(header)
end

if enable_config("object-tracing-override", false)
  enable_object_tracing
else
  bugs = %w(bug18464.rb bug19112).count { |f| !try_ruby(f) }

  if bugs.zero?
    enable_object_tracing
  else
    warn_on_ruby_ractor_bugs
  end
end

create_makefile("object_tracing")

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
plain_apm-0.10.2 ext/object_tracing/extconf.rb
plain_apm-0.10.0 ext/object_tracing/extconf.rb
plain_apm-0.9.8 ext/object_tracing/extconf.rb
plain_apm-0.9.7 ext/object_tracing/extconf.rb
plain_apm-0.9.6 ext/object_tracing/extconf.rb
plain_apm-0.9.5 ext/object_tracing/extconf.rb
plain_apm-0.9.4 ext/object_tracing/extconf.rb
plain_apm-0.9.3 ext/object_tracing/extconf.rb
plain_apm-0.9.2 ext/object_tracing/extconf.rb
plain_apm-0.9.1 ext/object_tracing/extconf.rb
plain_apm-0.9.0 ext/object_tracing/extconf.rb
plain_apm-0.8.8 ext/object_tracing/extconf.rb
plain_apm-0.8.7 ext/object_tracing/extconf.rb
plain_apm-0.8.6 ext/object_tracing/extconf.rb
plain_apm-0.8.5 ext/object_tracing/extconf.rb
plain_apm-0.8.4 ext/object_tracing/extconf.rb