Class: ABProf::ABBareProcess

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_line, opts = {}) ⇒ ABBareProcess

Returns a new instance of ABBareProcess.



137
138
139
140
# File 'lib/abprof.rb', line 137

def initialize command_line, opts = {}
  @command = command_line
  @debug = opts[:debug]
end

Instance Attribute Details

#last_itersObject (readonly)

Returns the value of attribute last_iters.



131
132
133
# File 'lib/abprof.rb', line 131

def last_iters
  @last_iters
end

#last_runObject (readonly)

Returns the value of attribute last_run.



130
131
132
# File 'lib/abprof.rb', line 130

def last_run
  @last_run
end

Instance Method Details

#debug(string) ⇒ Object



133
134
135
# File 'lib/abprof.rb', line 133

def debug string
  STDERR.puts(string) if @debug && ABProf.debug
end

#killObject



146
147
148
# File 'lib/abprof.rb', line 146

def kill
  # No-op
end

#quitObject



142
143
144
# File 'lib/abprof.rb', line 142

def quit
  # No-op
end

#run_iters(n) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/abprof.rb', line 150

def run_iters(n)
  t_start = t_end = nil
  debug "Controller of #{@pid}: #{n} ITERS"

  state = :succeeded
  n.times do
    if @command.respond_to?(:call)
      t_start = Time.now
      @command.call
      t_end = Time.now
    elsif @command.respond_to?(:to_s)
      t_start = Time.now
      system(@command.to_s)
      t_end = Time.now
      unless $?.success?
        STDERR.puts "Failing process #{@pid} after failed iteration(s), error code #{state.inspect}"
        # How to handle error with no self.kill?
        raise "Failure from command #{@command.inspect}, dying!"
      end
    else
      raise "Don't know how to execute bare object: #{@command.inspect}!"
    end
  end
  @last_run = [(t_end - t_start).to_f]
  @last_iters = n

  @last_run
end