Class: StackProf::CLI::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/stackprof/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



48
49
50
# File 'lib/stackprof/cli.rb', line 48

def ctx
  @ctx
end

Instance Method Details

#allObject

Print all the methods by sample time. Paged.



71
72
73
74
75
76
# File 'lib/stackprof/cli.rb', line 71

def all
  check_for_report
  page do |out|
    @report.print_text(false, nil, out)
  end
end

#check_for_reportObject

Simple check to see if a report has been loaded.



87
88
89
90
91
92
# File 'lib/stackprof/cli.rb', line 87

def check_for_report
  if !@report
    puts "You have to load a dump first with load-dump"
    return
  end
end

#load_dump(file) ⇒ Object

Load a dump into a StackProf::Report object.



51
52
53
54
55
56
# File 'lib/stackprof/cli.rb', line 51

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| ... } ⇒ Object

Wrap the output in pry’s pager (less)

Yields:

  • (out)


108
109
110
111
112
# File 'lib/stackprof/cli.rb', line 108

def page(&block)
  out = StringIO.new
  yield out
  ctx._pry_.pager.page out.string
end

Print callers/callees of methods matching method. Paged.



79
80
81
82
83
84
# File 'lib/stackprof/cli.rb', line 79

def print_method(method)
  check_for_report
  page do |out|
    @report.print_method(method, out)
  end
end

#puts(*args) ⇒ Object

Helper to delegate puts to the current context



103
104
105
# File 'lib/stackprof/cli.rb', line 103

def puts(*args)
  ctx.output.puts(*args)
end

#top(limit = 10) ⇒ Object

Print the top ‘limit` methods by sample time



59
60
61
62
# File 'lib/stackprof/cli.rb', line 59

def top(limit = 10)
  check_for_report
  @report.print_text(false, limit.to_i, ctx.output)
end

#total(limit = 10) ⇒ Object

Print the top ‘limit` methods by total time



65
66
67
68
# File 'lib/stackprof/cli.rb', line 65

def total(limit = 10)
  check_for_report
  @report.print_text(true, limit.to_i, ctx.output)
end

#with_context(ctx, &block) ⇒ Object

Wrap the execution of a method with a Pry context



95
96
97
98
99
100
# File 'lib/stackprof/cli.rb', line 95

def with_context(ctx, &block)
  @ctx = ctx
  res = yield self
  @ctx = nil
  res
end