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.



114
115
116
# File 'lib/appmap/trace.rb', line 114

def initialize
  @@stacks ||= {}
end

Class Method Details

.depthObject



109
110
111
# File 'lib/appmap/trace.rb', line 109

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

.enabled?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/appmap/trace.rb', line 105

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

Instance Method Details

#record(event) ⇒ Object



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

def record(event)
  stack = caller.select { |line| !line.index("/lib/appmap/") }[0...StackPrinter.depth].join("\n  ")
  stack_hash = Digest::SHA256.hexdigest(stack)
  return if @@stacks[stack_hash]

  @@stacks[stack_hash] = stack
  puts
  puts "Event: " + event.to_h.map { |k, v| ["#{k}: #{v}"] }.join(", ")
  puts "  " + stack
  puts
end