Class: PerfMonger::Command::StatCommand

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

Instance Method Summary collapse

Methods inherited from BaseCommand

register_alias, register_command

Constructor Details

#initializeStatCommand

Returns a new instance of StatCommand.



11
12
13
# File 'lib/perfmonger/command/stat.rb', line 11

def initialize
  super
end

Instance Method Details

#run(argv) ⇒ Object



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
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/perfmonger/command/stat.rb', line 15

def run(argv)
  @argv, @option = PerfMonger::Command::StatOption.parse(argv)

  if @argv.size == 0
    puts("ERROR: No command given.")
    exit(false)
  end

  record_cmd = @option.make_command

  begin
    if RUBY_VERSION >= '1.9'
      record_pid = Process.spawn(*record_cmd)
    else
      record_pid = Process.fork do
        Process.exec(*record_cmd)
      end
    end

    Signal.trap(:INT) do
      Process.kill("INT", record_pid)
    end

    @start_time = Time.now
    if RUBY_VERSION >= '1.9'
      command_pid = Process.spawn(*@argv)
    else
      command_pid = Process.fork do
        system(*@argv)
      end
    end

    Process.wait(command_pid)

  ensure
    @end_time = Time.now
    Process.kill(:INT, record_pid)
    Process.wait(record_pid)
  end

  summary_command = SummaryCommand.new.run([@option.logfile], @argv.join(" "))
end