更新时间:2020-11-26 17:36
性能日志用于统计应用的启动速度、卡顿与卡死等情况。您可以在 控制台 > 基础分析 中查看启动速度指标,在 性能分析 中查看卡顿与卡死报告。
[MPAnalysisHelper setLagMonitorPercent: 100]; // 100% 监控,需要在 startPerformanceMonitor 调用之前设置
在启动时调用 [MPAnalysisHelper startPerformanceMonitor]
,推荐在 -(void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法中调用。
// globalMonitorStartUpTime 是已定义的变量,导入 <mPaas/MPaaS+MonitorStartUpTime.h> 头文件后即可使用
double time = CFAbsoluteTimeGetCurrent() - globalMonitorStartUpTime;
[ [NSNotificationCenter defaultCenter] postNotificationName:@"APMonitor_Startup_Cost_Time" object:nil userInfo:@{@"CostTimeOnUserFeel": [NSString stringWithFormat:@"%f", time]}];
SDK 封装了性能监控接口,推荐您在 AppDelegate 的 - (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
方法中调用 [PerformanceHelper performanceMonitor]
。
#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]; // 100% 监控,需要在 startPerformanceMonitor 调用之前设置
[MPAnalysisHelper startPerformanceMonitor];
//record the time interval used for the app startup
NSTimeInterval time = CFAbsoluteTimeGetCurrent() - __start_timestamp;
[[MPAnalysisHelper sharedInstance] writeLogForStartupWithTime:time];
}
@end
在文档使用中是否遇到以下问题
更多建议
匿名提交