ext/object_tracing/extconf.rb in plain_apm-0.8.3 vs ext/object_tracing/extconf.rb in plain_apm-0.8.4
- old
+ new
@@ -1,6 +1,84 @@
require "mkmf"
-have_header("ruby/ruby.h") or missing("ruby/ruby.h")
-have_header("ruby/debug.h") or missing("ruby/debug.h")
+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")