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.
Tracking
Based on the mPaaS framework
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.
Note: Lag monitoring is enabled only on a real device not in the Xcode debug state.
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 method.
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
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;
}