Class: PerfMonger::Command::PlayCommand

Inherits:
BaseCommand show all
Defined in:
lib/perfmonger/command/play.rb

Instance Method Summary collapse

Methods inherited from BaseCommand

register_alias, register_command

Constructor Details

#initializePlayCommand

Returns a new instance of PlayCommand.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/perfmonger/command/play.rb', line 11

def initialize
  @parser = OptionParser.new
  @parser.banner = "Usage: perfmonger play [options] LOG_FILE\n\nOptions:\n"

  @color = false
  @parser.on("-c", "--color", "Use colored JSON ouptut") do
    @color = true
  end

  @pretty = false
  @parser.on("-p", "--pretty", "Use human readable JSON ouptut") do
    @pretty = true
  end

  @disk_only_regex = nil
  @parser.on('--disk-only REGEX', "Select disk devices that matches REGEX (Ex. 'sd[b-d]')") do |regex|
    @disk_only_regex = regex
  end
end

Instance Method Details

#parse_args(argv) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/perfmonger/command/play.rb', line 35

def parse_args(argv)
  @parser.parse!(argv)

  if argv.size == 0
    puts("ERROR: PerfMonger log file is required")
    puts(@parser.help)
    exit(false)
  end

  @logfile = argv.shift
  if ! File.exists?(@logfile)
    puts("ERROR: No such file: #{@logfile}")
    puts(@parser.help)
    exit(false)
  end
end

#run(argv) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/perfmonger/command/play.rb', line 52

def run(argv)
  parse_args(argv)

  @player_bin = ::PerfMonger::Command::CoreFinder.player()

  if ! @player_bin
    puts("[ERROR] no executable binary found.")
    exit(false)
  end

  cmd = [@player_bin]
  if @color
    cmd << "-color"
  end
  if @pretty
    cmd << "-pretty"
  end

  if @disk_only_regex
    cmd << "-disk-only"
    cmd << @disk_only_regex
  end

  cmd << @logfile

  Process.exec(*cmd)
end