Instruments Basics: Time Profiler
Recording CPU usage, reading call trees and finding hot spots in your code.
Instruments Basics: Time Profiler is a free Swift Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, and your progress syncs across the web and the CoddyKit app. The Swift Academy course includes 4 lessons in total.
Why Instruments?
Xcode Instruments is a performance analysis suite. Time Profiler shows you where CPU time is being spent so you can find hot spots.
// Launch: Xcode → Product → Profile (Cmd+I)
// Choose "Time Profiler" template
// Run your app and exercise the slow pathRecording a Trace
Click the record button in Instruments, exercise the feature you want to profile, then stop recording.
// 1. Connect device or use simulator
// 2. Launch with Profile (Cmd+I)
// 3. Select Time Profiler
// 4. Record for 5-30 seconds
// 5. Stop and analyzeCall Tree View
The Call Tree shows functions by CPU time consumed. The heaviest call paths appear at the top of the hierarchy.
// Call Tree columns:
// Self %: time spent in this function exclusively
// Symbol Name: function or method name
// Expand to see callers/calleesHeaviest Stack Trace
The Heaviest Stack Trace panel shows the single most sampled call path — often the best place to start optimizing.
// In Time Profiler:
// View → Heaviest Stack Trace
// Pinpoints the exact line consuming the most CPUFiltering Samples
Enable "Hide System Libraries" and "Invert Call Tree" to focus on your own code rather than Apple frameworks.
// Call Tree options (bottom of Instruments):
// ☑ Invert Call Tree – shows leaf functions first
// ☑ Hide System Libraries – filters out OS internalsNavigating to Source
Double-click a symbol in the call tree to jump directly to the offending line in Xcode.
// Double-click → opens file in Xcode at the hot line
// Red/orange annotation shows time spent per lineTime Profiler + SwiftUI
In SwiftUI apps, look for unexpected calls to body — excessive redraws show up as repeated View.body entries in the call tree.
// Common SwiftUI hot spots:
// - body called 100+ times per second
// - Equatable not implemented, causing unnecessary diffs
// - Heavy computation in body instead of a modelInspecting Main Thread vs Background
The thread lane at the top shows activity per thread. CPU spikes on background threads may indicate excessive work off the main thread.
// Thread lanes: Main Thread, Thread 2, Thread 3...
// Select a thread to see its call tree in isolationTime Profiler for Startup
Measure app launch time by profiling from launch and looking at the first seconds of the trace.
// Instruments → File → Launch Profile
// Measures time from process start to first frame renderSetting a Baseline
Record a baseline trace before optimizing. After changes, re-profile and compare to confirm improvement.
// Baseline: 45ms for imageLoad()
// After optimization: 8ms for imageLoad()
// Confirm: 5.6x speedup verified in InstrumentsTips for Accurate Profiling
Profile on a physical device in Release build. Simulators and Debug builds skew performance measurements.
// Always:
// 1. Use physical device
// 2. Build with Release configuration (Product → Scheme → Edit → Build → Release)
// 3. Repeat measurement 3+ times for consistencyQuick Check
Which Instruments call tree option shows the leaf (most time-consuming) functions at the top of the list?
Lesson Recap
Profile with Cmd+I → Time Profiler. Use Invert Call Tree + Hide System Libraries to see your code first. Double-click symbols to navigate to source. Profile on device in Release mode. Establish baselines before and after optimizations to confirm improvement.
Learn Swift with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 122
- Lessons
- 409
Frequently Asked Questions
Is the “Instruments Basics: Time Profiler” lesson free?
Yes — any 3 lessons of the Swift Academy learning path, including “Instruments Basics: Time Profiler”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Swift Academy course includes 4 lessons in total.
What will I learn in “Instruments Basics: Time Profiler”?
Recording CPU usage, reading call trees and finding hot spots in your code. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Swift Academy?
No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
How long does the “Instruments Basics: Time Profiler” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Swift Academy lesson?
Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Instruments Basics: Time Profiler
- Allocations and Leaks Instruments
- Main Thread Checker and Hangs
- Optimising Hot Paths: COW, Inlining and Specialisation