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.



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

def ctx
  @ctx
end

Instance Method Details

#allObject

Print all the methods by sample time. Paged.



74
75
76
77
78
79
# 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_reportObject

Simple check to see if a report has been loaded.



98
99
100
101
102
103
# 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) ⇒ Object

Load a dump into a StackProf::Report object.



54
55
56
57
58
59
# 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| ... } ⇒ Object

Wrap the output in pry’s pager (less)

Yields:

  • (out)


119
120
121
122
123
# File 'lib/stackprof/cli.rb', line 119

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


89
90
91
92
93
94
95
# File 'lib/stackprof/cli.rb', line 89

def print_file(file)
  check_for_report

  page do |out|
    @report.print_file(file, out)
  end
end

Print callers/callees of methods matching method. Paged.



82
83
84
85
86
87
# File 'lib/stackprof/cli.rb', line 82

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



114
115
116
# File 'lib/stackprof/cli.rb', line 114

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

#top(limit = 10) ⇒ Object

Print the top ‘limit` methods by sample time



62
63
64
65
# 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) ⇒ Object

Print the top ‘limit` methods by total time



68
69
70
71
# 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, &block) ⇒ Object

Wrap the execution of a method with a Pry context



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

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