Module: Datadog::CI::SourceCode::ISeqCollector Private
- Defined in:
- lib/datadog/ci/source_code/static_dependencies.rb,
ext/datadog_ci_native/iseq_collector.c
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
ISeqCollector provides native access to Ruby’s object space for collecting instruction sequences (ISeqs).
Constant Summary collapse
- STATIC_DEPENDENCIES_EXTRACTION_AVAILABLE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
begin # We support Ruby >= 3.2 even though technically it is possible to support 3.1 # The issue is that Ruby 3.1 and earlier doesn't have opt_getconstant_path YARV instruction # which makes it a lot harder to parse fully qualified constant access. # # See the PR https://github.com/DataDog/datadog-ci-rb/pull/442 for more context if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.2") require "datadog_ci_native.#{RUBY_VERSION}_#{RUBY_PLATFORM}" true else false end rescue LoadError false end
Class Method Summary collapse
-
.collect ⇒ Array<RubyVM::InstructionSequence>
private
Collect all live ISeqs from the Ruby object space.
-
.collect_iseqs ⇒ Array<RubyVM::InstructionSequence>
private
ISeqCollector.collect_iseqs.
Class Method Details
.collect ⇒ Array<RubyVM::InstructionSequence>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Collect all live ISeqs from the Ruby object space. Falls back to empty array if native extension is not available.
33 34 35 36 37 |
# File 'lib/datadog/ci/source_code/static_dependencies.rb', line 33 def self.collect return [] unless STATIC_DEPENDENCIES_EXTRACTION_AVAILABLE collect_iseqs end |
.collect_iseqs ⇒ Array<RubyVM::InstructionSequence>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
ISeqCollector.collect_iseqs
Walk all live objects in the Ruby object space and collect all instruction sequences (ISeqs) into an array.
NOTE:
-
Only sees ISeqs that still exist (top-level file ISeqs might be GC’d). Method ISeqs usually survive longer.
-
The returned ISeqs include all types: method bodies, class bodies, blocks, etc.
It is very similar to iseq_collector from debug gem: github.com/ruby/debug/blob/master/ext/debug/iseq_collector.c
47 48 49 50 51 52 53 |
# File 'ext/datadog_ci_native/iseq_collector.c', line 47 static VALUE iseq_collector_collect(VALUE self) { VALUE iseqs_array = rb_ary_new(); rb_objspace_each_objects(collect_iseqs_callback, (void *)iseqs_array); return iseqs_array; } |