All Products
Search
Document Center

Mobile Platform as a Service:Add performance log

Last Updated:Nov 20, 2024

Performance logs record the startup time, lag, and stuck information about apps. You can view the startup time under Mobile Analysis Service > Basic analysis, and view the lag and stuck reports under Performance analysis.

Supports log tracking based on the mPaaS framework and native projects.

Based on the mPaaS framework

  1. Lag monitoring is enabled for 10% devices by default. You can set the percentage through the following API:

     [MPAnalysisHelper setLagMonitorPercent: 100]; // Lag monitoring is enabled for all devices. The percentage needs to be set before the startPerformanceMonitor API is called.

    Lag monitoring is enabled only on a real device not in the Xcode debug state.

  2. You need to call [MPAnalysisHelper startPerformanceMonitor] during App startup. It is recommended that this API be called in the-(void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions launchOptions method.

    image

Based on a native project

A performance monitoring API is encapsulated in the SDK. We recommend that you call the [PerformanceHelper performanceMonitor] API in the - (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions method of AppDelegate.

#import "PerformanceHelper.h"
    #import <MPAnalysis/MPAnalysisHelper.h>

    static NSTimeInterval __start_timestamp = 0;

    @implementation PerformanceHelper

    + (void)load
    {
        __start_timestamp = CFAbsoluteTimeGetCurrent();
    }

    + (void)performanceMonitor
    {
        //start performance monitor

       [MPAnalysisHelper setLagMonitorPercent: 100]; // Lag monitoring is enabled for all devices. The percentage needs to be set before the startPerformanceMonitor API is called.
        [MPAnalysisHelper startPerformanceMonitor];

        //record the time interval used for the app startup
        NSTimeInterval time = CFAbsoluteTimeGetCurrent() - __start_timestamp;
        [[MPAnalysisHelper sharedInstance] writeLogForStartupWithTime:time];

    }

    @end
Note

Lag monitoring is enabled only on a real device not in the Xcode debug state.

Customize performance monitoring thresholds

When the default performance monitoring thresholds cannot meet your needs, you can customize relevant thresholds.

Set lag threshold

#Introduce header files
#import <MPMasAdapter/MPAnalysisHelper.h>

/**
 Set the threshold for main thread lag monitoring, in seconds, optional. The default value is 2 seconds.
 */
+ (void)setLagTimeThreshold:(NSUInteger)threshold;

/**
 Set the interval between lag detection. It is recommended that lagTimeThreshold / lagCheckInterval be equal to an integer
 */
+ (void)setLagCheckInterval:(NSTimeInterval)interval;

Set stuck threshold

#import <MPMasAdapter/MPMasSettings.h>

#Create the MPMasSettings category and customize it as follows


/**
 Get the stuck duration threshold. If it needs to be customized, rewrite it in Category. It is recommended that anrTimeThreshold / anrCheckInterval be equal to an integer.
 */
- (NSUInteger)anrTimeThreshold
{
    return customized duration;
}


/**
 Get the stuck detection interval. If it needs to be customized, rewrite it in Category. It is recommended that anrTimeThreshold / anrCheckInterval be equal to an integer.
 */
- (NSTimeInterval)anrCheckInterval
{
    return customized detection interval length;
}

Set the startup stuck time threshold

#import <MPMasAdapter/MPMasSettings.h>

#Create the MPMasSettings category and rewrite the following method to customize it


/**
 Get the startup stuck time threshold. If it needs to be customized, rewrite it in Category.
 */
- (NSUInteger)startupAnrTimeThreshold
{
    return customized duration;
}