iOS Mobile APM

 

How Can I...

Overview

Site24x7 Mobile APM for iOS lets you track the performance of your native mobile applications on actual end-user devices. For example, a news reader application may perform the following operations internally:

  • Navigate to a table view to show a list of articles
  • Load the list of articles using a REST API call
  • Cache the list of articles in an SQLite database
  • Download a thumbnail for each article
  • Cache the thumbnails to the filesystem
  • Build a complex UI such as a custom table view cell style

All of the above are potentially long-running operations that impact user experience so it's important to benchmark and optimize them across various devices. Site24x7 Mobile APM gathers and aggregates metrics from all your users across the globe by embedding an APM agent in your applications in the form of a library.

The APM agent measures the execution time of your code using transactions and components. In the previous example, the entire sequence of operations from starting navigation to rendering the final UI can be considered a transaction. The individual operations can be grouped into different component types such as HTTP, SQLite, filesystem, UI etc. Simple operations can be measured using just transactions, while complex operations can be measured using transactions with components.

Add Mobile APM

1.Login to Site24x7 and go to iOS section under APM tab.

2.Click on Add Application button.

3.Enter the application name and Apdex threshold.

4.On successful addition, you will be provided with an application key and a link to download the library files (Mobile_APM_iOS.zip). The same application key must be used for all versions of your application.

Usage

Start by logging in to the Site24x7 website and creating a new Mobile APM application. You will be provided with an application key and a link to download the library files. The same application key must be used for all versions of your application.

There are two versions of the library - development and release. The development version works on both device and simulator, while the release version works only on device and must be used for submission to the App Store. It is recommended to delete Xcode's DerivedData folder and clean your project when switching between the development and release version. To begin, add the development version of APM.framework to your Xcode project as an Embedded Binary.

Your application should target iOS 8.0 or above in order to use the APM framework.

Initialization

First import the APM framework.

@import APM;

Initialize the APM agent in main.m with the application key you obtained earlier. The APM agent uploads data to Site24x7 every 60 seconds by default. You can customize the upload interval if desired. If no data has been recorded, the APM agent will not make unnecessary network connections regardless of the interval.

int main(int argc, char * argv[]) {
        [S24APM startWithAppKey:@"0123456789abcdef0123456789abcdef"];
        @autoreleasepool {
                 return UIApplicationMain(argc, argv, nilNSStringFromClass([AppDelegateclass]));
    }
}

Using Transactions

You should typically start a transaction before a long-running operation and stop it when the operation is complete. Transactions are thread-safe and can be started and stopped from different threads. A transaction object can only be started and stopped once. Transactions with the same name are averaged across the application. Thus, when the same operation is executed multiple times using the same transaction name, the average execution time is recorded.

- (void)listArticles {
    S24Transaction *transaction = [S24APM startTransactionWithName:@"List Articles"];/
    // Perform long-running operation./
    [S24APM stopTransaction:transaction];
}

Using Components

You can group operations within a transaction into different types of components. You can use one of the predefined types such as S24HttpComponent.TYPE_HTTP, Component.TYPE_SQLITE, Component.TYPE_UI etc., or specify your own type. Components are thread-safe and can be started and stopped from different threads. A component object can only be started and stopped once. A component object cannot be stopped after its parent transaction has already been stopped. Multiple components in a transaction can overlap and run in parallel. Components with the same name within a transaction are averaged.

- (void)listArticles {
    S24Transaction *transaction = [S24APM startTransactionWithName:@"List Articles"];
    S24Component *httpComponent = [transaction startComponentWithType:S24HttpComponent];
    S24Component *articlesComponent = [transaction startComponentWithType:@"Download Articles"];
    // Download articles.
    [transaction stopComponent:articlesComponent];
    for (Article *article in articles) {
          S24Component *thumbnailComponent = [transaction startComponentWithType:@"Download Thumbnail"];
         // Download thumbnail.
         [transaction stopComponent:thumbnailComponent];
    }
       [transaction stopComponent:httpComponent];
       [S24APM stopTransaction:transaction];
}

In the above example, the total time taken by HTTP operations (downloading articles and thumbnails) are measured by S24HttpComponent and the time taken for just the articles is measured by "Download Articles". The time taken for each thumbnail is averaged and recorded by "Download Thumbnail" since it executes multiple times within a loop.

Flushing Data

Sometimes it's desirable to manually flush recently recorded data to Site24x7's servers. You may want to do this if you record transactions just before your application is terminated. If you've set a large upload interval (the default is 60 seconds), you should manually flush data whenever appropriate in case the application is terminated before the next upload interval.

[S24APM flush]

Was this document helpful?
Thanks for taking the time to share your feedback. We’ll use your feedback to improve our online help resources.