Skip to main content
On this page

Performance profiling

Profile without Instruments. kxdevice records CPU, memory allocations, network, energy, dropped frames and call stacks straight from your iPhone, from the command line or a web UI.

Get ready

1

Install a Release build

Debug builds aren't optimized and carry assertions and debug info, so what you measure won't match what your users see.

> kxbuild build .\MyApp.xcodeproj -c Release --install
2

Launch the app and get its PID

Most sampling commands filter by process ID. Launching with kxdevice prints the PID. If the app is already running, find it with ps.

> kxdevice apps launch com.example.myapp
> kxdevice apps ps
3

Pick a sampler

The table below maps each kind of problem to a command. energy takes a single reading. The other commands sample until you press Ctrl-C. Add -n to limit the number of samples, and --udid when several iPhones are connected.


Instruments templates and their commands

ProblemInstruments templateCommand
High CPU, battery drainActivity Monitorinstruments sysmon -i 1
Hot functions, where it stallsTime Profilerinstruments stackshot
Growing memory, suspected leaksAllocations / Leaksinstruments allocations --pid <pid> --backtrace
Dropped frames when scrolling, choppy animationCore Animation / Animation Hitchesinstruments fluidity --pid <pid>
Slow requests, heavy trafficNetworkinstruments netmon / instruments har --pid <pid> -o a.har
Energy useEnergy Loginstruments energy <pid>
os_log / signpost markersos_signpost / Logginginstruments activitytrace --pid <pid>
System calls, thread schedulingSystem Traceinstruments coreprofile
Poor network, high temperatureCondition inducerinstruments condition list, then enable …

Prefix every command with kxdevice. For example, to record one process's memory allocations with backtraces

> kxdevice instruments allocations --pid 1234 --backtrace -n 20

Tracking down common problems

Janky list scrolling

Watch for dropped frames with fluidity while you reproduce the scroll, then use stackshot to see which function the main thread is stuck in during those frames. Release builds strip symbols by default. If stackshot shows only addresses, build with -D STRIP_INSTALLED_PRODUCT=NO.

Memory keeps growing

Record for a while with allocations --backtrace while you enter and leave the same screen a few times. Look for allocations that only ever grow and which class their backtraces point to. Watch the overall memory trend in the memory graph of the web interface below.

Slow loading on a poor network

Run condition enable SlowNetworkCondition SlowNetwork3GGood to simulate 3G on the iPhone, then capture requests with har. See which endpoint is slowest, whether requests wait on each other, and whether any are duplicated. Open the exported .har in your browser's developer tools. Run condition disable when you're done.

Get crash logs

Pull crash reports straight from a test device.

> kxdevice crash pull .\crashes

Web interface

If you'd rather not remember commands, start the local web interface. It has CPU and memory graphs, the process list, network monitor, crash reports and system log. Open http://localhost:8780 in your browser.

> kxdevice web

Next steps