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>
|
|
|
|
|
2015-04-21 12:26:51 +00:00
|
|
|
#import "RCTDefines.h"
|
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
/**
|
|
|
|
* RCTProfile
|
|
|
|
*
|
|
|
|
* This file provides a set of functions and macros for performance profiling
|
|
|
|
*
|
2015-04-21 12:26:51 +00:00
|
|
|
* NOTE: This API is a work in a work in progress, please consider carefully
|
|
|
|
* before 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
|
|
|
|
2015-04-21 12:26:51 +00:00
|
|
|
#if RCT_DEV
|
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\"") \
|
|
|
|
NSNumber *__rct_profile_flow_id = _RCTProfileBeginFlowEvent(); \
|
|
|
|
_Pragma("clang diagnostic pop")
|
|
|
|
|
|
|
|
#define RCTProfileEndFlowEvent() \
|
|
|
|
_RCTProfileEndFlowEvent(__rct_profile_flow_id)
|
|
|
|
|
|
|
|
RCT_EXTERN NSNumber *_RCTProfileBeginFlowEvent(void);
|
|
|
|
RCT_EXTERN void _RCTProfileEndFlowEvent(NSNumber *);
|
|
|
|
|
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-06-05 11:23:51 +00:00
|
|
|
RCT_EXTERN NSString *RCTProfileEnd(RCTBridge *);
|
2015-04-20 11:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Collects the initial event information for the event and returns a reference ID
|
|
|
|
*/
|
2015-08-20 06:36:11 +00:00
|
|
|
RCT_EXTERN void RCTProfileBeginEvent(uint64_t tag,
|
|
|
|
NSString *name,
|
|
|
|
NSDictionary *args);
|
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-08-20 06:36:11 +00:00
|
|
|
RCT_EXTERN void RCTProfileEndEvent(uint64_t tag,
|
|
|
|
NSString *category,
|
|
|
|
NSDictionary *args);
|
2015-04-20 11:55:05 +00:00
|
|
|
|
|
|
|
/**
|
2015-08-20 06:36:11 +00:00
|
|
|
* Collects the initial event information for the event and returns a reference ID
|
2015-04-20 11:55:05 +00:00
|
|
|
*/
|
2015-08-20 06:36:11 +00:00
|
|
|
RCT_EXTERN int 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,
|
|
|
|
int cookie,
|
|
|
|
NSString *name,
|
|
|
|
NSDictionary *args);
|
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,
|
|
|
|
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
|
|
|
|
*/
|
2015-08-20 06:36:11 +00:00
|
|
|
#define RCTProfileBlock(block, tag, category, arguments) \
|
2015-04-20 11:55:05 +00:00
|
|
|
^{ \
|
2015-08-20 06:36:11 +00:00
|
|
|
RCTProfileBeginEvent(tag, @(__PRETTY_FUNCTION__), nil); \
|
2015-04-20 11:55:05 +00:00
|
|
|
block(); \
|
2015-08-20 06:36:11 +00:00
|
|
|
RCTProfileEndEvent(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 *);
|
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
#else
|
|
|
|
|
2015-06-03 12:38:21 +00:00
|
|
|
#define RCTProfileBeginFlowEvent()
|
|
|
|
#define _RCTProfileBeginFlowEvent() @0
|
|
|
|
|
|
|
|
#define RCTProfileEndFlowEvent()
|
|
|
|
#define _RCTProfileEndFlowEvent()
|
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
#define RCTProfileIsProfiling(...) NO
|
|
|
|
#define RCTProfileInit(...)
|
|
|
|
#define RCTProfileEnd(...) @""
|
|
|
|
|
|
|
|
#define RCTProfileBeginEvent(...)
|
|
|
|
#define RCTProfileEndEvent(...)
|
|
|
|
|
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(...)
|
|
|
|
#define RCTProfileUnhookModules(...)
|
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
#endif
|