Before you begin
If you haven't already, add Firebase to your Apple project.
Step 1: Add Performance Monitoring to your app
After you've added the Performance Monitoring SDK, Firebase automatically starts collecting data for your app's screen rendering, data related to your app's lifecycle (like app start time), and data for HTTP/S network requests.
Use Swift Package Manager to install and manage Firebase dependencies.
- In Xcode, with your app project open, navigate to File > Add Packages.
- When prompted, add the Firebase Apple platforms SDK repository:
- Choose the Performance Monitoring library.
- When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.
Next, configure the Firebase module:
- Import the
FirebaseCoremodule in your
UIApplicationDelegate, as well as any other Firebase modules your app delegate uses. For example, to use Cloud Firestore and Authentication:
import FirebaseCore import FirebaseFirestore import FirebaseAuth // ...
@import FirebaseCore; @import FirebaseFirestore; @import FirebaseAuth; // ...
- Configure a
FirebaseAppshared instance, typically in your app's
// Use Firebase library to configure APIs FirebaseApp.configure()
// Use Firebase library to configure APIs [FIRApp configure];
- Recompile your app.
Step 2: Generate performance events for initial data display
Firebase starts processing the events when you successfully add the SDK to your app. If you're still developing locally, interact with your app to generate events for initial data collection and processing.
Continue to develop your app using a simulator or test device.
Generate events by switching your app between background and foreground several times, interacting with your app by navigating across screens, and/or triggering network requests.
Go to the Performance dashboard of the Firebase console. You should see your initial data display within a few minutes.
If you don't see a display of your initial data, review the troubleshooting tips.
Step 3: (Optional) View log messages for performance events
Enable debug logging, as follows:
- In Xcode (minimum v13.3.1), select Product > Scheme > Edit scheme.
- Select Run from the left menu, then select the Arguments tab.
- In the Arguments Passed on Launch section, add
Check your log messages for any error messages.
Performance Monitoring tags its log messages with
Firebase/Performanceso that you can filter your log messages.
Check for the following types of logs which indicate that Performance Monitoring is logging performance events:
Logging trace metric: TRACE_NAME, FIREBASE_PERFORMANCE_CONSOLE_URL
Logging network request trace: URL
Click on the URL to view your data in the Firebase console. It may take a few moments for the data to update in the dashboard.
If your app isn't logging performance events, review the troubleshooting tips.
Step 4: (Optional) Add custom monitoring for specific code
To monitor performance data associated with specific code in your app, you can instrument custom code traces.
With a custom code trace, you can measure how long it takes your app to complete a specific task or set of tasks, such as loading a set of images or querying your database. The default metric for a custom code trace is its duration, but you can also add custom metrics, such as cache hits and memory warnings.
In your code, you define the beginning and the end of a custom code trace (and add any desired custom metrics) using the API provided by the Performance Monitoring SDK.
Visit Add monitoring for specific code to learn more about these features and how to add them to your app.
Step 5: Deploy your app then review results
After you've validated Performance Monitoring using the Xcode simulator and one or more test devices, you can deploy the updated version of your app to your users.
You can monitor performance data in the Performance dashboard of the Firebase console.
- Performance Monitoring has known compatibility issues with GTMSQLite. We recommend not using Performance Monitoring with apps that use GTMSQLite.
- Method swizzling after calling
FirebaseApp.configure()might interfere with the Performance Monitoring SDK.
- Known issues with the iOS 8.0-8.2 Simulator prevent Performance Monitoring from capturing performance events. These issues are fixed in the iOS 8.3 Simulator and later versions.
- Connections established using NSURLSession's
backgroundSessionConfigurationwill exhibit longer than expected connection times. These connections are executed out-of-process and the timings reflect in-process callback events.
Review and run the Performance Monitoring iOS code sample on GitHub.
Learn more about data automatically collected by Performance Monitoring:
View, track, and filter your performance data in the Firebase console.
Add monitoring for specific tasks or workflows in your app by instrumenting custom code traces.