pvalena / rpms / ruby

Forked from rpms/ruby 2 years ago
Clone
4c12d4
require 'set'
919598
4c12d4
LIBRUBY_SO = 'libruby.so'
4c12d4
PROBES_D = 'probes.d'
919598
3130f8
# These probes are excluded by VM_COLLECT_USAGE_DETAILS ifdef.
3130f8
EXCLUDE_PROBES = Set.new %w(insn insn__operand)
3130f8
3130f8
## Detect SystemTap section headers presence
4c12d4
4c12d4
stap_headers = [
4c12d4
  '\.stapsdt\.base',
4c12d4
  '\.note\.stapsdt'
4c12d4
]
4c12d4
4c12d4
header_regexp = %r{ (#{stap_headers.join('|')}) }
4c12d4
4c12d4
section_headers = `readelf -S "#{LIBRUBY_SO}"`
4c12d4
detected_stap_headers = section_headers.scan(header_regexp).flatten
4c12d4
4c12d4
# Assume there are both headers until this is proven wrong ;)
4c12d4
unless detected_stap_headers.size == 2
4c12d4
  puts 'ERROR: SystemTap (DTrace) headers were not detected in resulting library.'
4c12d4
  exit false
4c12d4
end
4c12d4
3130f8
## Find if every declared probe is propagated to resulting library
4c12d4
4c12d4
# Colect probes specified in probes.d file.
3130f8
probes_declared = []
4c12d4
4c12d4
File.open(PROBES_D) do |file|
4c12d4
  file.each_line do |line|
4c12d4
    if probe = line[/probe (\S+)\(.*\);/, 1]
3130f8
      probes_declared << probe
4c12d4
    end
4c12d4
  end
4c12d4
end
4c12d4
3130f8
probes_declared = Set.new probes_declared
4c12d4
3130f8
unless EXCLUDE_PROBES.subset? probes_declared
4c12d4
  puts 'ERROR: Change in SystemTap (DTrace) probes definition file detected.'
4c12d4
  exit false
4c12d4
end
4c12d4
3130f8
probes_declared -= EXCLUDE_PROBES
4c12d4
4c12d4
# Detect probes in resulting library.
3130f8
get_probes_detected = %r{
3130f8
^\s*Provider:\s+ruby,\s+Name:\s+(\S+),\s+.*$
4c12d4
}
4c12d4
3130f8
probes_detected = `eu-readelf -n "#{LIBRUBY_SO}"`
3130f8
3130f8
probes_detected = Set.new probes_detected.scan(get_probes_detected).flatten
4c12d4
4c12d4
# Both sets must be equal, otherwise something is wrong.
3130f8
unless probes_declared == probes_detected
4c12d4
  puts 'ERROR: SystemTap (DTrace) probes were not correctly propagated into resulting library.'
3130f8
  puts "       Undetected probes: #{(probes_declared - probes_detected).sort.join(', ')}\n",
3130f8
       "       Additional detected probes: #{(probes_detected - probes_declared).sort.join(', ')}"
3130f8
919598
  exit false
919598
end