Monday, January 1, 2018

Batterygate: Kind of Fishy

If you must use iOS 10.2.1+ in your iPhone 6/6+/6s/6s+/SE or iOS 11.2+ on your iPhone 7/7+ and are concerned about its performance, then get a new battery from Apple if needed, and in the meantime, probably keep it charged or plugged in when you can.

John Poole, the founder and president of Primate Labs that makes Geekbench, had reported on 2017-12-17 that there were changes in the distribution of reported Single-Core Score values reported for the iPhone 6s between iOS 10.2.0 and 10.2.1 (with 11.2.1 still being affected), along with differences in the iPhone 7 showing similar changes in the distribution of reported Single-Core Score values starting in 11.2.0.

Key parts of response from Apple:

With a low battery state of charge, a higher chemical age, or colder temperatures, users are more likely to experience unexpected shutdowns. In extreme cases, shutdowns can occur more frequently, thereby rendering the device unreliable or unusable. iOS 10.2.1 (released January 2017) includes updates for previous models of iPhone to prevent them from unexpectedly shutting down. This includes a feature for iPhone 6, iPhone 6 Plus, iPhone 6s, iPhone 6s Plus, and iPhone SE to dynamically manage the instantaneous performance peaks, only when needed, to prevent the device from unexpectedly shutting down. This capability was also extended to iPhone 7 and iPhone 7 Plus with iOS 11.2, and we will continue improving our power management feature in the future. This feature’s only intent is to prevent unexpected shutdowns so that the iPhone can still be used.

This power management works by looking at a combination of the device temperature, battery state of charge, and battery impedance. Only if these variables require it, iOS will dynamically manage the maximum performance of some system components, such as the CPU and GPU, in order to prevent unexpected shutdowns. As a result, the device workloads will self-balance, allowing a smoother distribution of system tasks, rather than larger, quick spikes of performance all at once. In some cases, a user may not notice any differences in daily device performance. The level of perceived change depends on how much power management is required for a particular device.

In cases that require more extreme forms of this power management, the user may notice effects such as:

  • Longer app launch times
  • Lower frame rates while scrolling
  • Backlight dimming (which can be overridden in Control Center)
  • Lower speaker volume by up to -3dB
  • Gradual frame rate reductions in some apps
  • During the most extreme cases, the camera flash will be disabled as visible in the camera UI
  • Apps refreshing in background may require reloading upon launch

Many key areas are not impacted by this power management feature. Some of these include:

  • Cellular call quality and networking throughput performance
  • Captured photo and video quality
  • GPS performance
  • Location accuracy
  • Sensors like gyroscope, accelerometer, barometer
  • Apple Pay

  • Apple is reducing the price of an out-of-warranty iPhone battery replacement by $50 — from $79 to $29 — for anyone with an iPhone 6 or later whose battery needs to be replaced, available worldwide through December 2018. Details will be provided soon on
  • Early in 2018, we will issue an iOS software update with new features that give users more visibility into the health of their iPhone’s battery, so they can see for themselves if its condition is affecting performance.

Info from a popular Reddit topic on the subject:

Am I affected? Depending on the age of your phone and the amount of battery wear, maybe. You can check this for sure by using an app called CPUdasher X that is no longer free, now being $0.99. You can check this by scrolling down to CPU Frequency. The 6 is supposed to be 1400, the 6S 1848, and the 7 2350. As far as I know, there is NO OTHER ALTERNATIVE to this. You can, however, do a geek bench or Antutu test to tell you what your CPU score is compared to what it should be, but it won’t tell you your clock speed.

However, note that if you run Geekbench 4, you can email the results to yourself and view the attached gb4 file that contains frequency measurements.

My Geekbench 4.2.0 iPhone 6s results:

  • At 100% battery charge: CPU Single-Core Score: 1430, Multi-Core Score: 2493, Min/max/median/mean processor frequency: 583/595/593/592
  • At close to 100% battery charge: CPU Single-Core Score: 1459, Multi-Core Score: 2500, Min/max/median/mean processor frequency: 803,894,880,870
  • At 93% battery charge: CPU Single-Core Score: 1440, Multi-Core Score: 1839, Min/max/median/mean processor frequency: 295/892/713/667
  • At ~93% battery charge: CPU Single-Core Score: 1453, Multi-Core Score: 2113
  • At ~88% battery charge: Single-Core Score: 1460, Multi-Core Score: 2505, Min/max/median/mean processor frequency: 323/844/781/729
  • At ~87% battery charge: CPU Single-Core Score: 1063, Multi-Core Score: 1785, Min/max/median/mean processor frequency: 578/596/592/591
  • At ~84% battery charge: CPU Single-Core Score: 1065, Multi-Core Score: 1778, Min/max/median/mean processor frequency: 571/595/592/589
  • At ~77% battery charge: CPU Single-Core Score: 1064, Multi-Core Score: 1782, Min/max/median/mean processor frequency: 559/594/590/586

CPU DasherX (lists max frequency for the iPhone 6s as 1850 MHz; it wasn't in low power mode, and it's in nominal thermal state):

  • Running at 89% battery charge: CPU current frequency 600 MHz
  • Running at 86% battery charge: CPU current frequency 600 MHz
  • Running at 78% battery charge: CPU current frequency 600 MHz

Wednesday, November 29, 2017

Collecting Unique Destination Hosts with Tcpdump

Simple solution to collecting all destination hosts for IP traffic. Just start it and when you ctrl-C, you'll have a nice sorted list of unique hosts and the port or assumed protocol based on the port:

sudo tcpdump 'ip' | cut -d " " -f 5 > /tmp/ipout.tmp || cat /tmp/ipout.tmp | sort | uniq && rm /tmp/ipout.tmp

Note: this assumes you're just doing it in a single macOS terminal window at a time.

Monday, November 20, 2017

Docker compose healthcheck

Running too many docker containers on limited hardware might not work well with Docker's native healthcheck defaults.

If using healthcheck, it's probably best to supply additional configuration. Specifically, v2.3 and v3.4 now have start_period in milliseconds. Also, consider changing the startup order. Use 'docker ps' to check the healthcheck status, which is listed by the STATUS value in parentheses.

Sunday, June 18, 2017

Manually Removing GoogleSoftwareUpdate in macOS

Wrapped it in a basic check for it's existence to avoid having to sudo if not necessary:

if [ -d "/Library/Google/GoogleSoftwareUpdate/" ]; then
  echo "sudo'ing to remove GoogleSoftwareUpdate. Might need to enter your password."
  sudo rm -rf /Library/Google/GoogleSoftwareUpdate/
  sudo rm -rf /Users/**/Library/Google/GoogleSoftwareUpdate
  sudo rm -f /Users/**/Library/Logs/GoogleSoftwareUpdateAgent.log
  sudo rm -f /Users/**/Library/LaunchAgents/

Reboot to avoid a bunch of errors in your system log. Have to keep the software up to date on your own after removing it. Do it at your own risk.

Monday, May 22, 2017

Crystal GC and "Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS Program received and didn't handle signal IOT (6)"

Using Crystal 0.22.0, sometimes the GC seems like it is slowing things down a bit or getting hung up, but it turns out that collecting more frequently doesn't seem to help much, and slows it down more overall.

When you eventually run out of memory, you'll hit (or at least I did in macOS):

Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS
Program received and didn't handle signal IOT (6)

The impact of those hangs is not remedied by doing forced cleanup, e.g.:

if GC.stats.free_bytes < 90000

I tried that in various ways, but you can't squeeze more memory out or trick GC into running more to run faster, at least not in my testing.

I noticed in this StackOverflow answer, Mono: Too many heap sections Increase MAXHINCR or MAX_HEAP_SECTS when app takes more than 4 GB in memory, that Mono also has a problem with the Boehm GC. Perhaps the two are similar and there's a fix for Crystal or it's compilation that would help with this.

Friday, May 19, 2017

CRLF will be replaced by LF in db/structure.sql.

$ git add db/structure.sql
warning: CRLF will be replaced by LF in db/structure.sql.
The file will have its original line endings in your working directory.

Thought we had all our line-ending nonsense straightened out, but could see that structure.sql before being updated by rake db:migrate just had \n and after had some \r\n:

$ file structure.sql.before_db_migrate
before.txt: ASCII text, with very long lines
$ file structure.sql.after_db_migrate 
after.txt: ASCII text, with very long lines, with CRLF, LF line terminators
$ cat -v structure.sql.after_db_migrate
CREATE FUNCTION some_function_name() RETURNS void
    LANGUAGE ...
    AS $$^M
  REFRESH ...;^M
END; $$;

So, it was in a single function of the schema. Not Rails's/ActiveRecord's fault and not a git config problem.

Friday, May 12, 2017

List Terminal Commands and Utilities and Listing All Text Editors in Posix and Linux

This is a neat command I've not used before in bash:

compgen -c | sort | uniq

That lists all of the commands available.

Getting an (incomplete) list of available text editors is a bit tougher, but we can build on the command above and guess:

compgen -c | sort | uniq | grep '^dit$\|^emacs$\|^uemacs$\|^vi$\|^vim$\|^mu$\|^nano$\|^rnano$\|^pico$\|^jed$\|^joe$'