[profiler] Make it a bit more readable.

This commit is contained in:
Eloy Durán
2013-10-28 20:36:17 +01:00
parent 9508d0942a
commit afe932b2ab

View File

@@ -177,15 +177,19 @@ task :profile do
unless template = ENV['template']
App.fail "Specify the path to a template with the `template' environment variable. For a list of templates, use: $ xcrun instruments -s"
end
sim_home = File.expand_path('~/Library/Application Support/iPhone Simulator')
app_name = App.config.bundle_name + '.app'
processes = `ps -x -o 'pid,command'`.split("\n")
if pid_line = processes.find { |line| line.include?(sim_home) && line.include?(app_name) }
pid, path = pid_line.match(/^(\d+)\s(.+)$/)[1..2]
App.info 'Profile', path
doc_name = "Beers-#{File.basename(template, File.extname(template))}"
doc_path = File.join(App.config.versionized_build_dir('iPhoneSimulator'), doc_name)
App.info 'Profile', path
sh "xcrun instruments -p #{pid} -t '#{template}' -D '#{doc_path}'"
if pid_line = processes.find { |line| line.include?('Instruments.app') }
pid = pid_line.match(/^(\d+)\s/)[1]
open_files = `lsof -a -p #{pid} | grep '#{doc_path}'`