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 to call the API in the-(void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method.If the startup time needs to be recorded, you only need to record the startup time and send a startup completion notification after the App is started.
// globalMonitorStartUpTime is a defined variable and can be used after being imported into the <mPaas/MPaaS+MonitorStartUpTime.h> header file.
double time = CFAbsoluteTimeGetCurrent() - globalMonitorStartUpTime;
[ [NSNotificationCenter defaultCenter] postNotificationName:@"APMonitor_Startup_Cost_Time" object:nil userInfo:@{@"CostTimeOnUserFeel": [NSString stringWithFormat:@"%f", time]}];
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