All Products
Search
Document Center

Add performance log

Last Updated: Jan 19, 2021

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

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

       
    1. [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.
  2. 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.

     Start performance monitoring

  3. 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.

       
    1. // globalMonitorStartUpTime is a defined variable and can be used after being imported into the <mPaas/MPaaS+MonitorStartUpTime.h> header file.
    2. double time = CFAbsoluteTimeGetCurrent() - globalMonitorStartUpTime;
    3. [ [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.

 
  1. #import "PerformanceHelper.h"
  2. #import <MPAnalysis/MPAnalysisHelper.h>
  3. static NSTimeInterval __start_timestamp = 0;
  4. @implementation PerformanceHelper
  5. + (void)load
  6. {
  7. __start_timestamp = CFAbsoluteTimeGetCurrent();
  8. }
  9. + (void)performanceMonitor
  10. {
  11. //start performance monitor
  12. [MPAnalysisHelper setLagMonitorPercent: 100]; // Lag monitoring is enabled for all devices. The percentage needs to be set before the startPerformanceMonitor API is called.
  13. [MPAnalysisHelper startPerformanceMonitor];
  14. //record the time interval used for the app startup
  15. NSTimeInterval time = CFAbsoluteTimeGetCurrent() - __start_timestamp;
  16. [[MPAnalysisHelper sharedInstance] writeLogForStartupWithTime:time];
  17. }
  18. @end
Note: Lag monitoring is enabled only on a real device not in the Xcode debug state.