Class: StackProf::CLI

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

Overview

CLI is a simple wrapper around Pry that defines some helper methods for navigating stackprof dumps.

Defined Under Namespace

Classes: Session

Class Method Summary collapse

Class Method Details

.add_methodsObject

Add the helper methods to pry



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/stackprof/cli.rb', line 19

def add_methods
  session = Session.new
  Pry::Commands.block_command "load-dump", "Load a stackprof dump at file" do |file|
    session.with_context(self) {|s| s.load_dump(file) }
  end
  Pry::Commands.block_command "top", "print the top (n) results by sample time" do |limit|
    session.with_context(self) {|s| s.top(limit) }
  end
  Pry::Commands.block_command "total", "print the top (n) results by total sample time" do |limit|
    session.with_context(self) {|s| s.total(limit) }
  end
  Pry::Commands.block_command "all", "print all results by sample time" do
    session.with_context(self) {|s| s.all }
  end
  Pry::Commands.block_command "method", "scope results to matching methods" do |method|
    session.with_context(self) {|s| s.print_method(method) }
  end
  Pry::Commands.block_command "file", "scope results to matching file" do |method|
    session.with_context(self) {|s| s.print_file(method) }
  end
end

.set_defaultsObject

Set prompts and other defaults



11
12
13
14
15
16
# File 'lib/stackprof/cli.rb', line 11

def set_defaults
  Pry.config.should_load_rc = false
  Pry.config.prompt = proc {
    "stackprof#{@current_report ? " (#{@current_report})" : ""}> "
  }
end

.start(file, options = {}) ⇒ Object

Start a Pry session with an optional file



42
43
44
45
46
47
# File 'lib/stackprof/cli.rb', line 42

def start(file, options = {})
  set_defaults
  add_methods
  initial = file ? StringIO.new("load-dump #{file}") : nil
  Pry.start(nil, :input => initial)
end