Class: RunLoop::Instruments
- Inherits:
-
Object
- Object
- RunLoop::Instruments
- Defined in:
- lib/run_loop/instruments.rb
Overview
TODO:
Detect Instruments.app is running and pop an alert.
Note:
All instruments commands are run in the context of ‘xcrun`.
A class for interacting with the instruments command-line tool
Instance Method Summary collapse
-
#instruments_pids(&block) ⇒ Array<Integer>
Returns an Array of instruments process ids.
-
#instruments_running? ⇒ Boolean
Are there any instruments processes running?.
-
#kill_instruments(xcode_tools = RunLoop::XCTools.new) ⇒ Object
Send a kill signal to any running ‘instruments` processes.
Instance Method Details
#instruments_pids(&block) ⇒ Array<Integer>
Note:
The ‘block` parameter is included for legacy API and will be deprecated. Replace your existing calls with with .each or .map. The block argument makes this method hard to mock.
Returns an Array of instruments process ids.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/run_loop/instruments.rb', line 16 def instruments_pids(&block) pids = pids_from_ps_output if block_given? pids.each do |pid| block.call(pid) end else pids end end |
#instruments_running? ⇒ Boolean
Are there any instruments processes running?
29 30 31 |
# File 'lib/run_loop/instruments.rb', line 29 def instruments_running? instruments_pids.count > 0 end |
#kill_instruments(xcode_tools = RunLoop::XCTools.new) ⇒ Object
Send a kill signal to any running ‘instruments` processes.
Only one instruments process can be running at any one time.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/run_loop/instruments.rb', line 39 def kill_instruments(xcode_tools = RunLoop::XCTools.new) kill_signal = kill_signal xcode_tools # It is difficult to test using a block. instruments_pids.each do |pid| begin if ENV['DEBUG'] == '1' puts "Sending '#{kill_signal}' to instruments process '#{pid}'" end Process.kill(kill_signal, pid.to_i) rescue Exception => e if ENV['DEBUG'] == '1' puts "Could not kill process '#{pid.to_i}' - ignoring #{e}" end end # Process.wait or `wait` here is pointless. The pid may or may not be # a child of this Process. begin if ENV['DEBUG'] == '1' puts "Waiting for instruments '#{pid}' to terminate" end wait_for_process_to_terminate(pid, {:timeout => 2.0}) rescue Exception => e if ENV['DEBUG'] == '1' puts "Ignoring #{e.}" end end end end |