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.



116
117
118
# File 'lib/appmap/trace.rb', line 116

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

Class Method Details

.depthObject



111
112
113
# File 'lib/appmap/trace.rb', line 111

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

.enabled?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/appmap/trace.rb', line 107

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

Instance Method Details

#record(event) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/appmap/trace.rb', line 120

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