Profiling with Signposts
Signposts provide a powerful option for logging your app’s runtime resource usage. When viewed in Xcode’s Instruments, signpost logs allow you to model your app’s performance over time. These profiles help you find bottlenecks and other anomalies in your code. Beginning in version 7.1, Mobile SDK add signposts in heavily used portions of its code so you can profile its performance in your app. Mobile SDK signposts are available for Swift and Objective-C apps.
In debug profiles, enabling signposts requires a single flip of an Xcode switch. For production profiles in apps that use CocoaPods, you make a few changes to the Podfile and then rebuild.
In Mobile SDK libraries, signposts are pre-configured for Debug builds. However, Xcode profile schemes default to Release builds. Let’s change that.
To profile a debug build:
- In the Xcode taskbar, click the scheme name and select Edit Scheme.
- Select Profile.
- Set Build Configuration to Debug.
To profile a production build with Mobile SDK signposts, you don’t edit the default profile scheme. If you’ve already tinkered with default settings, however, verify them as follows:
- In the Xcode taskbar, click the scheme name and select Edit Scheme.
- Select Profile.
- Make sure that Build Configuration is set to Release.
If you created your project “manually”, without using forceios or CocoaPods, your configuration is ready to run. Skip to Running a Signpost Profile Build.
If you used forceios to create your app, CocoaPods controls the settings for Mobile SDK pods. To profile a production build of a Mobile SDK app that uses CocoaPods:
-
Edit the following section of your app’s Podfile.
- Change
if config.name == 'Debug'
(as shown here) toif config.name == 'Release'
. - Remove the
'$(inherited)'
,'DEBUG=1'
and'-DDEBUG'
settings. Here’s the intended result.
- Change
-
Important: Close your workspace.
-
In the Terminal app, switch to your workspace directory and run:
pod update
-
Reopen your workspace in Xcode.
To run a signpost build:
- In the Xcode menu, click Product | Profile
- When prompted, select a Profiling Template—for example, “Blank”—and click Choose.
- In the Instruments panel, click + and find “os_signposts”.
- Double-click os_signposts.
- Click Record. Enjoy the show!