module Pry::Stackprofiler

Public Class Methods

profile(opts={}) click to toggle source
# File lib/pry-stackprofiler.rb, line 19
def profile opts={}, &blk
  # todo: pass through options perhaps?
  opts.merge!({mode: :wall, raw: true})
  @last_profile = StackProfx.run(opts) { blk.call }
  @blk_obj_id = RubyVM::InstructionSequence::of(blk).object_id
  @needs_send = true
end
try_send() click to toggle source
# File lib/pry-stackprofiler.rb, line 27
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_url() click to toggle source
# File lib/pry-stackprofiler.rb, line 43
def ui_url
  Pry.config.pry_stackprofiler_ui_url ||= ENV['PRY_STACKPROFILER_UI_URL']
end