Class: RunLoop::Instruments
- Inherits:
-
Object
- Object
- RunLoop::Instruments
- Defined in:
- lib/run_loop/instruments.rb
Overview
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.
-
#spawn(automation_template, options, log_file) ⇒ Integer
Spawn a new instruments process in the context of ‘xcrun` and detach.
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.
52 53 54 55 56 57 58 59 |
# File 'lib/run_loop/instruments.rb', line 52 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.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/run_loop/instruments.rb', line 14 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?
27 28 29 |
# File 'lib/run_loop/instruments.rb', line 27 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.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/run_loop/instruments.rb', line 37 def kill_instruments(xcode_tools = RunLoop::XCTools.new) kill_signal = kill_signal xcode_tools instruments_pids.each do |pid| terminator = RunLoop::ProcessTerminator.new(pid, kill_signal, 'instruments') unless terminator.kill_process terminator = RunLoop::ProcessTerminator.new(pid, 'KILL', 'instruments') terminator.kill_process end end end |
#spawn(automation_template, options, log_file) ⇒ Integer
Do I need to enumerate the launch options in the docs?
Should this raise errors?
Is this jruby compatible?
Spawn a new instruments process in the context of ‘xcrun` and detach.
71 72 73 74 75 76 77 78 |
# File 'lib/run_loop/instruments.rb', line 71 def spawn(automation_template, , log_file) splat_args = spawn_arguments(automation_template, ) logger = [:logger] RunLoop::Logging.log_debug(logger, "xcrun #{splat_args.join(' ')} >& #{log_file}") pid = Process.spawn('xcrun', *splat_args, {:out => log_file, :err => log_file}) Process.detach(pid) pid.to_i end |