biscuitehh / yeetd

yeetd is a lil' daemon that watches for specific CPU-intensive Simulator processes and stops them in their tracks!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The prewarm simulators script depends on `jq` which is not available natively on macOS

rogerluan opened this issue · comments

Hi 👋

This is what I get when attempting to run the prewarm_simulators.sh script:

./prewarm_simulators.sh: line 4: jq: command not found
Process complete!

I decided to replace it with this Ruby code instead, as it's higher level (easier to work with) and solves the compatibility problem at question ☝️ (I didn't want to mess with grep/awk/cut/etc 😅 )

require "json"

# Run the command, capture its output, and map to an array of devices
simctl_output = `xcrun simctl list devices --json`
simulator_data = JSON.parse(simctl_output)
simulator_devices = simulator_data["devices"].values.flatten

simulator_devices.each do |device|
  udid = device["udid"]
  name = device["name"]
  puts "Ensuring that the Simulator '#{name}' is off…"
  `xcrun simctl shutdown #{udid}` unless device["state"] == "Shutdown"
  next if device["availabilityError"]
  puts "Booting the Simulator '#{name}'…"
  `xcrun simctl bootstatus #{udid} -b`
  puts "Migration complete! Now shutting down the Simulator '#{name}'…"
  `xcrun simctl shutdown #{udid}`
end

puts "Process complete!"

Feel free to incorporate this into the main repo if you wish 😄

This will produce an output like this, without any errors:

image

The previous script would produce errors when e.g. attempting to shut down a simulator that was already shutdown, or attempting to boot a simulator that can't be booted.

Warming up all simulators take too long and at least in my case I don't use all of them. So I adjusted the script:

require "json"

puts "This script will ensure all simulators are shutdown first, and then, if a simulator name is passed, it will only warm up that specific simulator. If none is passed, it will warmup all simulators."
puts

# Get the device name to warmup, if any
device_to_warmup = ARGV[0]

# Run the command, capture its output, and map to an array of devices
simctl_output = `xcrun simctl list devices --json`
simulator_data = JSON.parse(simctl_output)
simulator_devices = simulator_data["devices"].values.flatten

simulator_devices.each do |device|
  udid = device["udid"]
  name = device["name"]
  puts "Ensuring that the simulator '#{name}' is off…"
  `xcrun simctl shutdown #{udid}` unless device["state"] == "Shutdown"
  next if device["availabilityError"]
  if device_to_warmup
    next unless name == device_to_warmup
  end
  puts "Booting the simulator '#{name}'…"
  `xcrun simctl bootstatus #{udid} -b`
  puts "Migration complete! Now shutting down the simulator '#{name}'…"
  `xcrun simctl shutdown #{udid}`
end

puts
puts "Process complete!"