21.2 · Instruments templates, signposts and XCTMetric
Instruments is a set of microscopes. The skill is not clicking record; it is picking the microscope that fits the symptom and marking your own code so the trace says what your app was doing.
Mental model. Match symptom to template, then add signposts so the timeline shows your intervals instead of anonymous stacks.
Choosing the instrument
Which template answers which question, and how sampling can mislead.
- Which Instruments templates do you reach for, how do you read a Time Profiler trace, and where can a sampling profiler mislead you?
Pick the template from the symptom. Time Profiler answers “where is the CPU time going”: it samples every thread’s call stack at a fixed interval (about a…
Marking and testing
Signposts, Points of Interest and performance tests with XCTMetric.
- How do signposts and Points of Interest work, and how do you turn a measurement into an XCTest performance test with metrics and baselines?
A signpost is a cheap, named mark in your code that Instruments draws on its timeline. Create an OSSignposter(subsystem:category:) (the category…
More in Performance & energy
- 21.1 · Measure first: the method, the metrics and the noise
- 21.3 · MetricKit, Organizer and a performance culture
- 21.4 · SwiftUI invalidation and long lists
- 21.5 · The costs that show up in profiles: collections, strings, formatters, JSON, images and disk
- 21.6 · Energy: CPU wake-ups, timers, radios, location and thermal state
- 21.7 · App size: thinning, on-demand resources and the binary
- 21.8 · Writing benchmarks you can believe: the optimiser, build settings and growth tests
- 21.9 · Memory you can count: allocations, dirty versus clean pages and decoded images
- 21.10 · The main thread in code: hang watchdogs, actor hops and quality of service
- 21.11 · Launch: lazy initialisation and measuring from process start
- 21.12 · Counting wake-ups: why polling costs energy even when the work is tiny