Class: RunLoop::Instruments
- Inherits:
-
Object
- Object
- RunLoop::Instruments
- Defined in:
- lib/run_loop/instruments.rb
Overview
Detect Instruments.app is running and pop an alert.
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_app_running? ⇒ Boolean
Is the Instruments.app running?.
-
#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_app_running? ⇒ Boolean
Is the Instruments.app running?
If the Instruments.app is running, the instruments command line tool cannot take control of applications.
74 75 76 77 78 79 80 81 |
# File 'lib/run_loop/instruments.rb', line 74 def instruments_app_running? ps_output = `ps x -o pid,comm | grep Instruments.app | grep -v grep`.strip if ps_output[/Instruments\.app/, 0] true else false end end |
#instruments_pids(&block) ⇒ Array<Integer>
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 68 |
# 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' or ENV['DEBUG_UNIX_CALLS'] == '1' puts "Sending '#{kill_signal}' to instruments process '#{pid}'" end Process.kill(kill_signal, pid.to_i) Process.wait(pid, Process::WNOHANG) rescue Exception => e if ENV['DEBUG'] == '1' or ENV['DEBUG_UNIX'] == '1' puts "Could not kill and wait for process '#{pid.to_i}' - ignoring exception '#{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' or ENV['DEBUG_UNIX_CALLS'] == '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' or ENV['DEBUG_UNIX_CALLS'] == '1' puts "Ignoring #{e.}" end end end end |