2015-04-20 11:55:05 +00:00
|
|
|
/**
|
|
|
|
* 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>
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTAssert.h>
|
|
|
|
#import <React/RCTDefines.h>
|
2015-04-21 12:26:51 +00:00
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
/**
|
|
|
|
* RCTProfile
|
|
|
|
*
|
|
|
|
* This file provides a set of functions and macros for performance profiling
|
|
|
|
*
|
2015-12-11 06:50:03 +00:00
|
|
|
* NOTE: This API is a work in progress, please consider carefully before
|
|
|
|
* using it.
|
2015-04-20 11:55:05 +00:00
|
|
|
*/
|
|
|
|
|
2015-06-17 12:56:46 +00:00
|
|
|
RCT_EXTERN NSString *const RCTProfileDidStartProfiling;
|
|
|
|
RCT_EXTERN NSString *const RCTProfileDidEndProfiling;
|
2015-06-02 13:15:53 +00:00
|
|
|
|
2016-05-14 00:14:59 +00:00
|
|
|
RCT_EXTERN const uint64_t RCTProfileTagAlways;
|
|
|
|
|
2016-06-13 11:16:19 +00:00
|
|
|
#if RCT_PROFILE
|
2015-04-20 11:55:05 +00:00
|
|
|
|
2015-06-05 11:23:51 +00:00
|
|
|
@class RCTBridge;
|
|
|
|
|
2015-06-03 12:38:21 +00:00
|
|
|
#define RCTProfileBeginFlowEvent() \
|
|
|
|
_Pragma("clang diagnostic push") \
|
|
|
|
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
|
2016-08-09 10:53:59 +00:00
|
|
|
NSUInteger __rct_profile_flow_id = _RCTProfileBeginFlowEvent(); \
|
2015-06-03 12:38:21 +00:00
|
|
|
_Pragma("clang diagnostic pop")
|
|
|
|
|
|
|
|
#define RCTProfileEndFlowEvent() \
|
|
|
|
_RCTProfileEndFlowEvent(__rct_profile_flow_id)
|
|
|
|
|
2015-11-04 17:00:01 +00:00
|
|
|
RCT_EXTERN dispatch_queue_t RCTProfileGetQueue(void);
|
|
|
|
|
2016-08-09 10:53:59 +00:00
|
|
|
RCT_EXTERN NSUInteger _RCTProfileBeginFlowEvent(void);
|
|
|
|
RCT_EXTERN void _RCTProfileEndFlowEvent(NSUInteger);
|
2015-06-03 12:38:21 +00:00
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
/**
|
|
|
|
* Returns YES if the profiling information is currently being collected
|
|
|
|
*/
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN BOOL RCTProfileIsProfiling(void);
|
2015-04-20 11:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Start collecting profiling information
|
|
|
|
*/
|
2015-06-05 11:23:51 +00:00
|
|
|
RCT_EXTERN void RCTProfileInit(RCTBridge *);
|
2015-04-20 11:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2015-11-04 17:00:01 +00:00
|
|
|
RCT_EXTERN void RCTProfileEnd(RCTBridge *, void (^)(NSString *));
|
2015-04-20 11:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Collects the initial event information for the event and returns a reference ID
|
|
|
|
*/
|
2015-11-04 17:00:01 +00:00
|
|
|
RCT_EXTERN void _RCTProfileBeginEvent(NSThread *calleeThread,
|
|
|
|
NSTimeInterval time,
|
|
|
|
uint64_t tag,
|
|
|
|
NSString *name,
|
|
|
|
NSDictionary *args);
|
2016-09-05 18:11:37 +00:00
|
|
|
#define RCT_PROFILE_BEGIN_EVENT(tag, name, args) \
|
2015-11-26 11:15:04 +00:00
|
|
|
do { \
|
|
|
|
if (RCTProfileIsProfiling()) { \
|
2016-02-03 15:10:52 +00:00
|
|
|
NSThread *__calleeThread = [NSThread currentThread]; \
|
|
|
|
NSTimeInterval __time = CACurrentMediaTime(); \
|
2016-09-05 18:11:37 +00:00
|
|
|
_RCTProfileBeginEvent(__calleeThread, __time, tag, name, args); \
|
2015-11-26 11:15:04 +00:00
|
|
|
} \
|
|
|
|
} while(0)
|
2015-04-20 11:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2015-11-04 17:00:01 +00:00
|
|
|
RCT_EXTERN void _RCTProfileEndEvent(NSThread *calleeThread,
|
|
|
|
NSString *threadName,
|
|
|
|
NSTimeInterval time,
|
|
|
|
uint64_t tag,
|
2016-09-05 18:11:37 +00:00
|
|
|
NSString *category);
|
2015-11-04 17:00:01 +00:00
|
|
|
|
2016-09-05 18:11:37 +00:00
|
|
|
#define RCT_PROFILE_END_EVENT(tag, category) \
|
2015-11-26 11:15:04 +00:00
|
|
|
do { \
|
|
|
|
if (RCTProfileIsProfiling()) { \
|
2016-02-03 15:10:52 +00:00
|
|
|
NSThread *__calleeThread = [NSThread currentThread]; \
|
|
|
|
NSString *__threadName = RCTCurrentThreadName(); \
|
|
|
|
NSTimeInterval __time = CACurrentMediaTime(); \
|
2016-09-05 18:11:37 +00:00
|
|
|
_RCTProfileEndEvent(__calleeThread, __threadName, __time, tag, category); \
|
2015-11-26 11:15:04 +00:00
|
|
|
} \
|
|
|
|
} while(0)
|
2015-04-20 11:55:05 +00:00
|
|
|
|
|
|
|
/**
|
2015-08-21 17:15:04 +00:00
|
|
|
* Collects the initial event information for the event and returns a reference ID
|
2015-04-20 11:55:05 +00:00
|
|
|
*/
|
2015-11-08 18:19:26 +00:00
|
|
|
RCT_EXTERN NSUInteger RCTProfileBeginAsyncEvent(uint64_t tag,
|
|
|
|
NSString *name,
|
|
|
|
NSDictionary *args);
|
2015-04-20 11:55:05 +00:00
|
|
|
|
2015-08-20 06:36:11 +00:00
|
|
|
/**
|
|
|
|
* 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,
|
2015-11-08 18:19:26 +00:00
|
|
|
NSUInteger cookie,
|
2015-08-20 06:36:11 +00:00
|
|
|
NSString *name,
|
2016-09-05 18:11:37 +00:00
|
|
|
NSString *threadName);
|
2015-11-04 17:00:01 +00:00
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
/**
|
|
|
|
* An event that doesn't have a duration (i.e. Notification, VSync, etc)
|
|
|
|
*/
|
2015-08-20 06:36:11 +00:00
|
|
|
RCT_EXTERN void RCTProfileImmediateEvent(uint64_t tag,
|
|
|
|
NSString *name,
|
2015-12-09 17:53:00 +00:00
|
|
|
NSTimeInterval time,
|
2015-08-20 06:36:11 +00:00
|
|
|
char scope);
|
2015-04-20 11:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2016-07-19 14:16:32 +00:00
|
|
|
*
|
|
|
|
* DEPRECATED: this approach breaks debugging and stepping through instrumented block functions
|
2015-04-20 11:55:05 +00:00
|
|
|
*/
|
2015-08-20 06:36:11 +00:00
|
|
|
#define RCTProfileBlock(block, tag, category, arguments) \
|
2015-04-20 11:55:05 +00:00
|
|
|
^{ \
|
2015-11-09 16:42:51 +00:00
|
|
|
RCT_PROFILE_BEGIN_EVENT(tag, @(__PRETTY_FUNCTION__), nil); \
|
2015-04-20 11:55:05 +00:00
|
|
|
block(); \
|
2015-11-09 16:42:51 +00:00
|
|
|
RCT_PROFILE_END_EVENT(tag, category, arguments); \
|
2015-04-20 11:55:05 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 17:54:45 +00:00
|
|
|
/**
|
|
|
|
* 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 *);
|
|
|
|
|
2016-05-04 13:54:12 +00:00
|
|
|
/**
|
|
|
|
* Hook into all of a module's methods
|
|
|
|
*/
|
|
|
|
RCT_EXTERN void RCTProfileHookInstance(id instance);
|
|
|
|
|
2015-09-11 13:35:25 +00:00
|
|
|
/**
|
|
|
|
* Send systrace or cpu profiling information to the packager
|
|
|
|
* to present to the user
|
|
|
|
*/
|
2015-11-04 17:00:01 +00:00
|
|
|
RCT_EXTERN void RCTProfileSendResult(RCTBridge *bridge, NSString *route, NSData *profileData);
|
2015-09-11 13:35:25 +00:00
|
|
|
|
2015-09-23 18:59:44 +00:00
|
|
|
/**
|
|
|
|
* 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 {
|
|
|
|
void (*start)(uint64_t enabledTags, char *buffer, size_t bufferSize);
|
|
|
|
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);
|
2016-05-14 00:14:55 +00:00
|
|
|
|
|
|
|
void (*begin_async_flow)(uint64_t tag, const char *name, int cookie);
|
|
|
|
void (*end_async_flow)(uint64_t tag, const char *name, int cookie);
|
2015-09-23 18:59:44 +00:00
|
|
|
} RCTProfileCallbacks;
|
|
|
|
|
|
|
|
RCT_EXTERN void RCTProfileRegisterCallbacks(RCTProfileCallbacks *);
|
|
|
|
|
2016-03-11 14:20:24 +00:00
|
|
|
/**
|
|
|
|
* Systrace control window
|
|
|
|
*/
|
|
|
|
RCT_EXTERN void RCTProfileShowControls(void);
|
|
|
|
RCT_EXTERN void RCTProfileHideControls(void);
|
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
#else
|
|
|
|
|
2015-06-03 12:38:21 +00:00
|
|
|
#define RCTProfileBeginFlowEvent()
|
|
|
|
#define _RCTProfileBeginFlowEvent() @0
|
|
|
|
|
|
|
|
#define RCTProfileEndFlowEvent()
|
2016-02-08 15:06:52 +00:00
|
|
|
#define _RCTProfileEndFlowEvent(...)
|
2015-06-03 12:38:21 +00:00
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
#define RCTProfileIsProfiling(...) NO
|
|
|
|
#define RCTProfileInit(...)
|
|
|
|
#define RCTProfileEnd(...) @""
|
|
|
|
|
2015-11-09 16:42:51 +00:00
|
|
|
#define _RCTProfileBeginEvent(...)
|
|
|
|
#define _RCTProfileEndEvent(...)
|
|
|
|
|
|
|
|
#define RCT_PROFILE_BEGIN_EVENT(...)
|
|
|
|
#define RCT_PROFILE_END_EVENT(...)
|
2015-04-20 11:55:05 +00:00
|
|
|
|
2015-08-20 06:36:11 +00:00
|
|
|
#define RCTProfileBeginAsyncEvent(...) 0
|
|
|
|
#define RCTProfileEndAsyncEvent(...)
|
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
#define RCTProfileImmediateEvent(...)
|
|
|
|
|
|
|
|
#define RCTProfileBlock(block, ...) block
|
|
|
|
|
2015-07-22 17:54:45 +00:00
|
|
|
#define RCTProfileHookModules(...)
|
2016-05-04 13:54:12 +00:00
|
|
|
#define RCTProfileHookInstance(...)
|
2015-07-22 17:54:45 +00:00
|
|
|
#define RCTProfileUnhookModules(...)
|
|
|
|
|
2015-09-11 13:35:25 +00:00
|
|
|
#define RCTProfileSendResult(...)
|
|
|
|
|
2016-03-11 14:20:24 +00:00
|
|
|
#define RCTProfileShowControls(...)
|
|
|
|
#define RCTProfileHideControls(...)
|
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
#endif
|