Class: ProcessMuncher
- Inherits:
-
Object
- Object
- ProcessMuncher
- Defined in:
- lib/replicant/process_muncher.rb
Instance Method Summary collapse
- #find_pid ⇒ Object
-
#initialize(repl) ⇒ ProcessMuncher
constructor
A new instance of ProcessMuncher.
- #process_table ⇒ Object
- #scan_pid ⇒ Object
Constructor Details
#initialize(repl) ⇒ ProcessMuncher
Returns a new instance of ProcessMuncher.
3 4 5 |
# File 'lib/replicant/process_muncher.rb', line 3 def initialize(repl) @repl = repl end |
Instance Method Details
#find_pid ⇒ Object
23 24 25 |
# File 'lib/replicant/process_muncher.rb', line 23 def find_pid process_table.invert[@repl.default_package] end |
#process_table ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/replicant/process_muncher.rb', line 7 def process_table result = AdbCommand.new(@repl, "shell ps", :silent => true).execute if result.code > 0 @signal_exit = true {} else processes = result.output # Parses something like: # u0_a27 1333 123 517564 18668 ffffffff b75a59eb S com.android.musicfx processes.lines.map do |pid_line| columns = pid_line.split [columns[1], columns[-1]] end.to_h end end |
#scan_pid ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/replicant/process_muncher.rb', line 27 def scan_pid @last_pid = nil t = Thread.new do begin while @repl.default_package pid = find_pid t.exit if @signal_exit pid_changed = (pid && pid != @last_pid) || (pid.nil? && @last_pid) yield pid if block_given? && pid_changed @last_pid = pid sleep 2 end rescue Exception => e puts e.inspect puts e.backtrace.join("\n") raise e end end end |