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

Class Method Details

.collectArray<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.

Returns:

  • (Array<RubyVM::InstructionSequence>)

    Array of all live ISeqs



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_iseqsObject



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;
}