Module: AppMap

Defined in:
lib/appmap.rb,
lib/appmap/hook.rb,
lib/appmap/util.rb,
lib/appmap/event.rb,
lib/appmap/rspec.rb,
lib/appmap/trace.rb,
lib/appmap/railtie.rb,
lib/appmap/version.rb,
lib/appmap/cucumber.rb,
lib/appmap/metadata.rb,
lib/appmap/class_map.rb,
lib/appmap/command/stats.rb,
lib/appmap/command/record.rb,
lib/appmap/algorithm/stats.rb,
lib/appmap/rails/sql_handler.rb,
lib/appmap/rails/action_handler.rb,
lib/appmap/algorithm/prune_class_map.rb,
lib/appmap/middleware/remote_recording.rb

Defined Under Namespace

Modules: Algorithm, Command, Cucumber, Event, Metadata, Middleware, RSpec, Rails, Trace, Util Classes: ClassMap, Hook, Railtie, Tracer

Constant Summary collapse

URL =
'https://github.com/applandinc/appmap-ruby'
VERSION =
'0.28.0'
APPMAP_FORMAT_VERSION =
'1.2'

Class Method Summary collapse

Class Method Details

.class_map(methods) ⇒ Object

class_map builds a class map from a config and a list of Ruby methods.



70
71
72
73
# File 'lib/appmap.rb', line 70

def class_map(methods)
  require 'appmap/class_map'
  ClassMap.build_from_methods(configuration, methods)
end

.configurationObject

configuration gets the configuration. If there is no configuration, the default configuration is initialized.



19
20
21
# File 'lib/appmap.rb', line 19

def configuration
  @configuration ||= configure
end

.configuration=(config) ⇒ Object

configuration= sets the configuration. This is only expected to happen once per Ruby process.



25
26
27
28
29
# File 'lib/appmap.rb', line 25

def configuration=(config)
  warn 'AppMap is already configured' if @configuration && config

  @configuration = config
end

.detect_metadataObject

detect_metadata returns default metadata detected from the Ruby system and from the filesystem.



77
78
79
80
81
# File 'lib/appmap.rb', line 77

def 
  require 'appmap/metadata'
  @metadata ||= Metadata.detect.freeze
  @metadata.deep_dup
end

.initialize(config_file_path = 'appmap.yml') ⇒ Object

initialize configures AppMap for recording. Default behavior is to configure from “appmap.yml”. This method also activates the code hooks which record function calls as trace events. Call this function before the program code is loaded by the Ruby VM, otherwise the load events won’t be seen and the hooks won’t activate.



35
36
37
38
39
40
# File 'lib/appmap.rb', line 35

def initialize(config_file_path = 'appmap.yml')
  warn "Configuring AppMap from path #{config_file_path}"
  require 'appmap/hook'
  self.configuration = Hook::Config.load_from_file(config_file_path)
  Hook.hook(configuration)
end

.recordObject

record records the events which occur while processing a block, and returns an AppMap as a Hash.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/appmap.rb', line 50

def record
  tracer = tracing.trace
  begin
    yield
  ensure
    tracing.delete(tracer)
  end

  events = [].tap do |event_list|
    event_list << tracer.next_event.to_h while tracer.event?
  end
  {
    'version' => AppMap::APPMAP_FORMAT_VERSION,
    'metadata' => ,
    'classMap' => class_map(tracer.event_methods),
    'events' => events
  }
end

.tracingObject

tracing can be used to start tracing, stop tracing, and record events.



43
44
45
46
# File 'lib/appmap.rb', line 43

def tracing
  require 'appmap/trace'
  @tracing ||= Trace::Tracing.new
end