Module: PryStackprofiler

Defined in:
lib/pry-stackprofiler.rb

Class Method Summary collapse

Class Method Details

.profile(opts = {}, &blk) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/pry-stackprofiler.rb', line 10

def profile opts={}, &blk
  # todo: pass through options perhaps?
  opts.merge!({mode: :wall, raw: true})
  @last_profile = StackProf.run(opts) { blk.call }
  @blk_obj_id = RubyVM::InstructionSequence::of(blk).object_id
  @needs_send = true
end

.try_sendObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pry-stackprofiler.rb', line 18

def try_send
  return unless @needs_send
  @needs_send = false

  pry_file = Pry.line_buffer.join
  @last_profile[:files] = {'(pry)' => pry_file}
  @last_profile[:suggested_rebase] = @blk_obj_id

  url = URI::parse ui_url
  headers = {'Content-Type' => 'application/x-ruby-marshal'}
  req = Net::HTTP::Post.new(url.to_s, headers)
  req.body = Marshal.dump @last_profile

  response = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
end

.ui_urlObject



34
35
36
# File 'lib/pry-stackprofiler.rb', line 34

def ui_url
  Pry.config.pry_stackprofiler_ui_url ||= ENV['PRY_STACKPROFILER_UI_URL']
end