class StackProf::CLI::Session

Attributes

ctx[R]

Public Instance Methods

all() click to toggle source

Print all the methods by sample time. Paged.

# File lib/stackprof/cli.rb, line 74
def all
  check_for_report
  page do |out|
    @report.print_text(false, nil, out)
  end
end
check_for_report() click to toggle source

Simple check to see if a report has been loaded.

# File lib/stackprof/cli.rb, line 98
def check_for_report
  if !@report
    puts "You have to load a dump first with load-dump"
    return
  end
end
load_dump(file) click to toggle source

Load a dump into a StackProf::Report object.

# File lib/stackprof/cli.rb, line 54
def load_dump(file)
  data = File.read(file)
  @report = StackProf::Remote::ProcessReportCollector.report_from_marshaled_results(data)
  @current_report = File.basename(file)
  puts ">>> #{@current_report} loaded"
end
page() { |out| ... } click to toggle source

Wrap the output in pry’s pager (less)

# File lib/stackprof/cli.rb, line 119
def page(&block)
  out = StringIO.new
  yield out
  ctx._pry_.pager.page out.string
end
print_file(file) click to toggle source
print_method(method) click to toggle source

Print callers/callees of methods matching method. Paged.

puts(*args) click to toggle source

Helper to delegate puts to the current context

# File lib/stackprof/cli.rb, line 114
def puts(*args)
  ctx.output.puts(*args)
end
top(limit = 10) click to toggle source

Print the top ‘limit` methods by sample time

# File lib/stackprof/cli.rb, line 62
def top(limit = 10)
  check_for_report
  @report.print_text(false, limit.to_i, ctx.output)
end
total(limit = 10) click to toggle source

Print the top ‘limit` methods by total time

# File lib/stackprof/cli.rb, line 68
def total(limit = 10)
  check_for_report
  @report.print_text(true, limit.to_i, ctx.output)
end
with_context(ctx) { |self| ... } click to toggle source

Wrap the execution of a method with a Pry context

# File lib/stackprof/cli.rb, line 106
def with_context(ctx, &block)
  @ctx = ctx
  res = yield self
  @ctx = nil
  res
end