Page analysis API

更新时间:
复制 MD 格式

The page analysis API of the mobile monitoring iOS SDK lets you control data collection and define custom page load stages.

1. Configure page data collection

Enables or disables page data collection. This feature is enabled by default.

API definition

+ (void)setDataCollectionEnabled:(BOOL)dataCollectionEnabled;
+ (BOOL)dataCollectionEnabled;
class var dataCollectionEnabled: Bool { get set }

Code example

#import "AlicloudApmPerformance/AlicloudApmPerformance.h"

// Enable page data collection.
[EAPMPageConfiguration setDataCollectionEnabled:YES];

// Get the status of the page data collection switch.
BOOL enabled = [EAPMPageConfiguration dataCollectionEnabled];
#import "AlicloudApmPerformance/AlicloudApmPerformance.h"

// Enable page data collection.
PageConfiguration.dataCollectionEnabled = true

// Get the status of the page data collection switch.
let enabled = PageConfiguration.dataCollectionEnabled

2. Start a custom page load stage

Starts a custom page load stage for a page, which automatically ends the previous one.

API definition

+ (void)startStageNamed:(NSString *)stageName
      forViewController:(UIViewController *)viewController;

+ (void)startStageNamed:(NSString *)stageName
              startTime:(NSDate *)startTime
      forViewController:(UIViewController *)viewController;
class func startStage(name stageName: String, forViewController viewController: UIViewController)

class func startStage(name stageName: String, startTime: Date, forViewController viewController: UIViewController)

Parameters

Parameter

Type

Required

Length

Description

stageName

NSString

Yes

1-128

The stage name.

viewController

UIViewController

Yes

The UIViewController instance.

startTime

NSDate

No

The stage start time.

Code example

#import "AlicloudApmPerformance/AlicloudApmPerformance.h"

// Start a custom page load stage for a specific page.
[EAPMPageMonitor startStageNamed:@"request_data" forViewController:self];

// Start a custom page load stage for a specific page with an app-provided start time.
[EAPMPageMonitor startStageNamed:@"render_template" startTime:[NSDate date] forViewController:self];
#import "AlicloudApmPerformance/AlicloudApmPerformance.h"

// Start a custom page load stage for a specific page.
PageMonitor.startStage(name: "request_data", forViewController: self)

// Start a custom page load stage for a specific page with an app-provided start time.
PageMonitor.startStage(name: "render_template", startTime: Date(), forViewController: self)

3. Backfill a page load stage

Adds a historical page load stage by providing its start and end times.

API definition

+ (void)addStageNamed:(NSString *)stageName
            startTime:(NSDate *)startTime
              endTime:(NSDate *)endTime
    forViewController:(UIViewController *)viewController;
class func addStage(name stageName: String, startTime: Date, endTime: Date, forViewController viewController: UIViewController)

Parameters

Parameter

Type

Required

Length

Description

stageName

NSString

Yes

1-128

The stage name.

startTime

NSDate

Yes

The stage start time.

endTime

NSDate

Yes

The stage end time.

viewController

UIViewController

Yes

The UIViewController instance.

Code example

#import "AlicloudApmPerformance/AlicloudApmPerformance.h"

NSDate *start = [NSDate dateWithTimeIntervalSinceNow:-0.1];
NSDate *end = [NSDate date];
[EAPMPageMonitor addStageNamed:@"parse_data" startTime:start endTime:end forViewController:self];
#import "AlicloudApmPerformance/AlicloudApmPerformance.h"

let start = Date(timeIntervalSinceNow: -0.1)
let end = Date()
PageMonitor.addStage(name: "parse_data", startTime: start, endTime: end, forViewController: self)