BBPAppSpeedMonitor.h
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// BBPAppSpeedMonitor.h
// Pyramid
//
// Created by jilutao on 2017/8/18.
// Copyright © 2017年 Baidu. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, BBPEventTimeStatus) {
BBPEventTimeStart = 0,
BBPEventTimeEnd
};
__used extern void BBPSpeedEventTimeProfile(NSString *component, NSString *event, NSString *selector, BBPEventTimeStatus status);
#define BBPStartSpeedEventTime(component, event, selector) (BBPSpeedEventTimeProfile(component, event, selector, BBPEventTimeStart))
#define BBPEndSpeedEventTime(component, event) (BBPSpeedEventTimeProfile(component, event, nil, BBPEventTimeEnd))
// !!!block需要单独一个变量提出来,要不然无法调试
// 如:void (^speedBlock)(void) = ^{ }; BBPSpeedEventTime(@"component", @"event", @"selector", speedBlock);
#define BBPSpeedEventTime(component, event, selector, block) BBPStartSpeedEventTime(component, event, selector);block(); BBPEndSpeedEventTime(component, event)
@class BBPEventInfo;
@interface BBPAppSpeedMonitor : NSObject
+ (BBPAppSpeedMonitor *)sharedInstance;
/**
应用启动时调用该方法,最好在main.m中调用
*/
- (void)appStartLaunch;
/**
环境搭建完成
*/
- (void)appEnvironmentDidSetup;
/**
记录事件时间
@param eventName 事件名称
@param component 组件
@param selector 选择子
@param status 事件状态,开始或者结束
*/
- (void)recordEvent:(NSString *)eventName
component:(NSString *)component
selector:(NSString *)selector
status:(BBPEventTimeStatus)status;
/**
记录事件时间
@param eventName 事件名称
@param component 组件
@param selector 选择子
@param status 事件状态,开始或者结束
@param onEvent 事件回调
*/
- (void)recordEvent:(NSString *)eventName
component:(NSString *)component
selector:(NSString *)selector
status:(BBPEventTimeStatus)status
onEvent:(void(^)(BBPEventInfo *info))onEvent;
/**
监控到的节点数据
*/
- (NSArray <BBPEventInfo *>*)recordedEventDataArray;
/**
停止监控
*/
- (void)stopRecord;
#ifdef DEBUG
- (void)printOutTimeProfileResult;
- (void)saveTimeProfileDataIntoFile:(NSString *)filePath;
#endif
@end
// 速度打点节点
/**
事件信息
*/
@interface BBPEventInfo : NSObject
/**
组件
*/
@property (nonatomic, readonly, copy) NSString *component;
/**
事件
*/
@property (nonatomic, readonly, copy) NSString *event;
/**
方法名
*/
@property (nonatomic, readonly, copy) NSString *selector;
/**
时长 (s)
*/
@property (nonatomic, readonly, assign) CFTimeInterval duration;
/**
时间戳 (s)
*/
@property (nonatomic, readonly, assign) CFTimeInterval timestamp;
@end