Blob Blame History Raw
require 'set'

PROBES_D = 'probes.d'

# These probes are excluded by VM_COLLECT_USAGE_DETAILS ifdef.
EXCLUDE_PROBES = %w(insn insn__operand)

## Detect SystemTap section headers presence

stap_headers = [

header_regexp = %r{ (#{stap_headers.join('|')}) }

section_headers = `readelf -S "#{LIBRUBY_SO}"`
detected_stap_headers = section_headers.scan(header_regexp).flatten

# Assume there are both headers until this is proven wrong ;)
unless detected_stap_headers.size == 2
  puts 'ERROR: SystemTap (DTrace) headers were not detected in resulting library.'
  exit false

## Find if every declared probe is propagated to resulting library

# Colect probes specified in probes.d file.
probes_declared = [] do |file|
  file.each_line do |line|
    if probe = line[/probe (\S+)\(.*\);/, 1]
      probes_declared << probe

probes_declared = probes_declared

unless EXCLUDE_PROBES.subset? probes_declared
  puts 'ERROR: Change in SystemTap (DTrace) probes definition file detected.'
  exit false

probes_declared -= EXCLUDE_PROBES

# Detect probes in resulting library.
get_probes_detected = %r{

probes_detected = `eu-readelf -n "#{LIBRUBY_SO}"`

probes_detected = probes_detected.scan(get_probes_detected).flatten

# Both sets must be equal, otherwise something is wrong.
unless probes_declared == probes_detected
  puts 'ERROR: SystemTap (DTrace) probes were not correctly propagated into resulting library.'
  puts "       Undetected probes: #{(probes_declared - probes_detected).sort.join(', ')}\n",
       "       Additional detected probes: #{(probes_detected - probes_declared).sort.join(', ')}"

  exit false