Class: HeapInspect::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



8
9
10
11
12
13
# File 'lib/heap_inspect.rb', line 8

def initialize(argv)
  @cmd    = argv.shift
  @file   = argv.shift
  @number = argv.shift
  @args   = argv
end

Instance Method Details

#helpObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/heap_inspect.rb', line 15

def help
  puts <<-HALP
$ heap_inspect read <file|command> <number>

When run with only a file, it will output the generation and count pairs:

  $ heap_inspect read tmp/2015-09-30-heap.dump
Generation:  0 object count: 209191
Generation: 14 object count: 407
Generation: 15 object count: 638
Generation: 16 object count: 748
Generation: 17 object count: 1023
Generation: 18 object count: 805

When run with a file and a number it will output detailed information for that
generation:

  $ heap_inspect read tmp/2015-09-30-heap.dump 17

Analyzing Heap (Generation: 17)
-------------------------------

allocated by memory (in bytes)
==============================
/Users/richardschneeman/Documents/projects/codetriage/app/views/layouts/application.html.slim:1 (Memory: 377065, Count: 1 )
/Users/richardschneeman/.gem/ruby/2.2.3/gems/actionview-4.2.3/lib/action_view/template.rb:296 (Memory: 35814, Count: 67 )
/Users/richardschneeman/.gem/ruby/2.2.3/gems/activerecord-4.2.3/lib/active_record/attribute.rb:5 (Memory: 30672, Count: 426 )

HALP
end

#runObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/heap_inspect.rb', line 46

def run

  case @cmd
  when "--help"
    help
  when nil
    help
  when "read"
    if @number
      Analyzer.new(@file).drill_down(@number)
    else
      Analyzer.new(@file).analyze
    end
  else
    help
  end
end