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
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 --installLaunch 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 psPick 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
| Problem | Instruments template | Command |
|---|---|---|
| High CPU, battery drain | Activity Monitor | instruments sysmon -i 1 |
| Hot functions, where it stalls | Time Profiler | instruments stackshot |
| Growing memory, suspected leaks | Allocations / Leaks | instruments allocations --pid <pid> --backtrace |
| Dropped frames when scrolling, choppy animation | Core Animation / Animation Hitches | instruments fluidity --pid <pid> |
| Slow requests, heavy traffic | Network | instruments netmon / instruments har --pid <pid> -o a.har |
| Energy use | Energy Log | instruments energy <pid> |
| os_log / signpost markers | os_signpost / Logging | instruments activitytrace --pid <pid> |
| System calls, thread scheduling | System Trace | instruments coreprofile |
| Poor network, high temperature | Condition inducer | instruments 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 20Tracking 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 .\crashesWeb 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 webNext steps
kxdevice command reference
Every kxdevice subcommand and option, grouped into devices and pairing, installing and apps, launching and screenshots, debugging and symbols, logs and crashes, files and sandboxes, packet capture and location, backup and diagnostics, and the web UI.
Run and debug
Three ways to start (Build & Run, Run and Attach), what you see if a step fails after F5, panels and output during a debug session, launch.json fields and Dart debugging for Flutter.