Module: Kernel

Defined in:
lib/logstash/patches/profile_require_calls.rb

Instance Method Summary collapse

Instance Method Details

#load(path) ⇒ Object



42
43
44
45
# File 'lib/logstash/patches/profile_require_calls.rb', line 42

def load(path)
  puts "load(\"#{path}\")"
  return load_debug(path)
end

#load_debugObject



40
# File 'lib/logstash/patches/profile_require_calls.rb', line 40

alias_method :load_debug, :load

#require(path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/logstash/patches/profile_require_calls.rb', line 7

def require(path)
  start = Time.now
  result = require_debug(path)
  duration = Time.now - start

  origin = caller[1]
  if origin =~ /rubygems\/custom_require/
    origin = caller[3]
    if origin.nil?
      STDERR.puts "Unknown origin"
      STDERR.puts caller.join("\n")
    end
  end
  origin = origin.gsub(/:[0-9]+:in .*/, "") if origin

  # Only print require() calls that did actual work.
  # require() returns true on load, false if already loaded.
  if result
    source = caller[0]
    #p source.include?("/lib/polyglot.rb:63:in `require'") => source
    if source.include?("/lib/polyglot.rb:63:in `require'")
      source = caller[1]
    end

    #target = $LOADED_FEATURES.grep(/#{path}/).first
    #puts path
    #puts caller.map { |c| "  #{c}" }.join("\n")
    #fontsize = [10, duration * 48].max
    puts "#{duration},#{path},#{source}"
  end
  #puts caller.map { |c| " => #{c}" }.join("\n")
end

#require_debugObject



5
# File 'lib/logstash/patches/profile_require_calls.rb', line 5

alias_method :require_debug, :require