RCTProfile.h
7.09 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <Foundation/Foundation.h>
#import <React/RCTAssert.h>
#import <React/RCTDefines.h>
/**
* RCTProfile
*
* This file provides a set of functions and macros for performance profiling
*
* NOTE: This API is a work in progress, please consider carefully before
* using it.
*/
RCT_EXTERN NSString *const RCTProfileDidStartProfiling;
RCT_EXTERN NSString *const RCTProfileDidEndProfiling;
RCT_EXTERN const uint64_t RCTProfileTagAlways;
#if RCT_PROFILE
@class RCTBridge;
#define RCTProfileBeginFlowEvent() \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
NSUInteger __rct_profile_flow_id = _RCTProfileBeginFlowEvent(); \
_Pragma("clang diagnostic pop")
#define RCTProfileEndFlowEvent() \
_RCTProfileEndFlowEvent(__rct_profile_flow_id)
RCT_EXTERN dispatch_queue_t RCTProfileGetQueue(void);
RCT_EXTERN NSUInteger _RCTProfileBeginFlowEvent(void);
RCT_EXTERN void _RCTProfileEndFlowEvent(NSUInteger);
/**
* Returns YES if the profiling information is currently being collected
*/
RCT_EXTERN BOOL RCTProfileIsProfiling(void);
/**
* Start collecting profiling information
*/
RCT_EXTERN void RCTProfileInit(RCTBridge *);
/**
* Stop profiling and return a JSON string of the collected data - The data
* returned is compliant with google's trace event format - the format used
* as input to trace-viewer
*/
RCT_EXTERN void RCTProfileEnd(RCTBridge *, void (^)(NSString *));
/**
* Collects the initial event information for the event and returns a reference ID
*/
RCT_EXTERN void _RCTProfileBeginEvent(NSThread *calleeThread,
NSTimeInterval time,
uint64_t tag,
NSString *name,
NSDictionary<NSString *, NSString *> *args);
#define RCT_PROFILE_BEGIN_EVENT(tag, name, args) \
do { \
if (RCTProfileIsProfiling()) { \
NSThread *__calleeThread = [NSThread currentThread]; \
NSTimeInterval __time = CACurrentMediaTime(); \
_RCTProfileBeginEvent(__calleeThread, __time, tag, name, args); \
} \
} while(0)
/**
* The ID returned by BeginEvent should then be passed into EndEvent, with the
* rest of the event information. Just at this point the event will actually be
* registered
*/
RCT_EXTERN void _RCTProfileEndEvent(NSThread *calleeThread,
NSString *threadName,
NSTimeInterval time,
uint64_t tag,
NSString *category);
#define RCT_PROFILE_END_EVENT(tag, category) \
do { \
if (RCTProfileIsProfiling()) { \
NSThread *__calleeThread = [NSThread currentThread]; \
NSString *__threadName = RCTCurrentThreadName(); \
NSTimeInterval __time = CACurrentMediaTime(); \
_RCTProfileEndEvent(__calleeThread, __threadName, __time, tag, category); \
} \
} while(0)
/**
* Collects the initial event information for the event and returns a reference ID
*/
RCT_EXTERN NSUInteger RCTProfileBeginAsyncEvent(uint64_t tag,
NSString *name,
NSDictionary<NSString *, NSString *> *args);
/**
* The ID returned by BeginEvent should then be passed into EndEvent, with the
* rest of the event information. Just at this point the event will actually be
* registered
*/
RCT_EXTERN void RCTProfileEndAsyncEvent(uint64_t tag,
NSString *category,
NSUInteger cookie,
NSString *name,
NSString *threadName);
/**
* An event that doesn't have a duration (i.e. Notification, VSync, etc)
*/
RCT_EXTERN void RCTProfileImmediateEvent(uint64_t tag,
NSString *name,
NSTimeInterval time,
char scope);
/**
* Helper to profile the duration of the execution of a block. This method uses
* self and _cmd to name this event for simplicity sake.
*
* NOTE: The block can't expect any argument
*
* DEPRECATED: this approach breaks debugging and stepping through instrumented block functions
*/
#define RCTProfileBlock(block, tag, category, arguments) \
^{ \
RCT_PROFILE_BEGIN_EVENT(tag, @(__PRETTY_FUNCTION__), nil); \
block(); \
RCT_PROFILE_END_EVENT(tag, category, arguments); \
}
/**
* Hook into a bridge instance to log all bridge module's method calls
*/
RCT_EXTERN void RCTProfileHookModules(RCTBridge *);
/**
* Unhook from a given bridge instance's modules
*/
RCT_EXTERN void RCTProfileUnhookModules(RCTBridge *);
/**
* Hook into all of a module's methods
*/
RCT_EXTERN void RCTProfileHookInstance(id instance);
/**
* Send systrace or cpu profiling information to the packager
* to present to the user
*/
RCT_EXTERN void RCTProfileSendResult(RCTBridge *bridge, NSString *route, NSData *profileData);
/**
* Systrace gluecode
*
* allow to use systrace to back RCTProfile
*/
typedef struct {
const char *key;
int key_len;
const char *value;
int value_len;
} systrace_arg_t;
typedef struct {
char *(*start)(void);
void (*stop)(void);
void (*begin_section)(uint64_t tag, const char *name, size_t numArgs, systrace_arg_t *args);
void (*end_section)(uint64_t tag, size_t numArgs, systrace_arg_t *args);
void (*begin_async_section)(uint64_t tag, const char *name, int cookie, size_t numArgs, systrace_arg_t *args);
void (*end_async_section)(uint64_t tag, const char *name, int cookie, size_t numArgs, systrace_arg_t *args);
void (*instant_section)(uint64_t tag, const char *name, char scope);
void (*begin_async_flow)(uint64_t tag, const char *name, int cookie);
void (*end_async_flow)(uint64_t tag, const char *name, int cookie);
} RCTProfileCallbacks;
RCT_EXTERN void RCTProfileRegisterCallbacks(RCTProfileCallbacks *);
/**
* Systrace control window
*/
RCT_EXTERN void RCTProfileShowControls(void);
RCT_EXTERN void RCTProfileHideControls(void);
#else
#define RCTProfileBeginFlowEvent()
#define _RCTProfileBeginFlowEvent() @0
#define RCTProfileEndFlowEvent()
#define _RCTProfileEndFlowEvent(...)
#define RCTProfileIsProfiling(...) NO
#define RCTProfileInit(...)
#define RCTProfileEnd(...) @""
#define _RCTProfileBeginEvent(...)
#define _RCTProfileEndEvent(...)
#define RCT_PROFILE_BEGIN_EVENT(...)
#define RCT_PROFILE_END_EVENT(...)
#define RCTProfileBeginAsyncEvent(...) 0
#define RCTProfileEndAsyncEvent(...)
#define RCTProfileImmediateEvent(...)
#define RCTProfileBlock(block, ...) block
#define RCTProfileHookModules(...)
#define RCTProfileHookInstance(...)
#define RCTProfileUnhookModules(...)
#define RCTProfileSendResult(...)
#define RCTProfileShowControls(...)
#define RCTProfileHideControls(...)
#endif