Sha256: 4dee0efe91f9186237cef98972bfdf3a92865bd241c10dc24c6347a1cdf4405f

Contents?: true

Size: 1.17 KB

Versions: 18

Compression:

Stored size: 1.17 KB

Contents

require 'optparse'
require 'json'

module PerfMonger
module Command

class StatCommand < BaseCommand
  register_command 'stat', "Run a command and record system performance during execution"

  def initialize
    super
  end

  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
end

end # module Command
end # module PerfMonger

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
perfmonger-0.14.4 lib/perfmonger/command/stat.rb
perfmonger-0.14.2 lib/perfmonger/command/stat.rb
perfmonger-0.14.1 lib/perfmonger/command/stat.rb
perfmonger-0.14.0 lib/perfmonger/command/stat.rb
perfmonger-0.13.1 lib/perfmonger/command/stat.rb
perfmonger-0.12.1 lib/perfmonger/command/stat.rb
perfmonger-0.12.0 lib/perfmonger/command/stat.rb
perfmonger-0.11.2 lib/perfmonger/command/stat.rb
perfmonger-0.11.1 lib/perfmonger/command/stat.rb
perfmonger-0.11.0 lib/perfmonger/command/stat.rb
perfmonger-0.10.2 lib/perfmonger/command/stat.rb
perfmonger-0.10.1 lib/perfmonger/command/stat.rb
perfmonger-0.9.0 lib/perfmonger/command/stat.rb
perfmonger-0.8.2 lib/perfmonger/command/stat.rb
perfmonger-0.8.1 lib/perfmonger/command/stat.rb
perfmonger-0.8.0 lib/perfmonger/command/stat.rb
perfmonger-0.7.1 lib/perfmonger/command/stat.rb
perfmonger-0.7.0 lib/perfmonger/command/stat.rb