Class: AppMap::StackPrinter

Inherits:
Object show all
Defined in:
lib/appmap/trace.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStackPrinter

Returns a new instance of StackPrinter.



98
99
100
# File 'lib/appmap/trace.rb', line 98

def initialize
  @@stacks ||= Hash.new
end

Class Method Details

.depthObject



93
94
95
# File 'lib/appmap/trace.rb', line 93

def depth
  (ENV['APPMAP_STACK_DEPTH'] || 20).to_i
end

.enabled?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/appmap/trace.rb', line 89

def enabled?
  ENV['APPMAP_PRINT_STACKS'] == 'true'
end

Instance Method Details

#record(event) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/appmap/trace.rb', line 102

def record(event)
  stack = caller.select { |line| !line.index('/lib/appmap/') }[0...StackPrinter.depth].join("\n  ")
  stack_hash = Digest::SHA256.hexdigest(stack)
  unless @@stacks[stack_hash]
    @@stacks[stack_hash] = stack
    puts
    puts 'Event: ' + event.to_h.map { |k, v| [ "#{k}: #{v}" ] }.join(", ")
    puts '  ' + stack
    puts
  end
end