mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 23:28:12 +00:00
Summary: Chrome debugging UI is currently only showing connection state and logs in the console, leaving room for plenty of interesting information. I've pushed the UI (using the same convention set by FPS -- UI/JS) CPU and memory utilization data over the debug Websocket and tapped into the existing stream of JS calls that get ran in V8. The number of JS calls in a time interval is counted for all sub calls in a batch https://github.com/hharnisc/react-native/blob/master/packager/debugger.html#L150 The last 5 batches of JS calls are displayed in a list format. <img width="951" alt="screen shot 2015-07-19 at 7 34 00 pm" src="https://cloud.githubusercontent.com/assets/1388079/8769257/edc42f70-2e4d-11e5-8813-e86ef530a446.png"> Charts are created with [Chart.JS](https://github.com/nnnick/Chart.js) (MIT licensed). Closes https://github.com/facebook/react-native/pull/2050 Github Author: Harrison Harnisch <hharnisc@gmail.com>
168 lines
4.8 KiB
Objective-C
168 lines
4.8 KiB
Objective-C
/**
|
|
* 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 "RCTDefines.h"
|
|
|
|
/**
|
|
* RCTProfile
|
|
*
|
|
* This file provides a set of functions and macros for performance profiling
|
|
*
|
|
* NOTE: This API is a work in a work in progress, please consider carefully
|
|
* before before using it.
|
|
*/
|
|
|
|
RCT_EXTERN NSString *const RCTProfileDidStartProfiling;
|
|
RCT_EXTERN NSString *const RCTProfileDidEndProfiling;
|
|
|
|
#if RCT_DEV
|
|
|
|
@class RCTBridge;
|
|
|
|
#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 *);
|
|
|
|
/**
|
|
* 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 NSString *RCTProfileEnd(RCTBridge *);
|
|
|
|
/**
|
|
* Collects the initial event information for the event and returns a reference ID
|
|
*/
|
|
RCT_EXTERN void RCTProfileBeginEvent(uint64_t tag,
|
|
NSString *name,
|
|
NSDictionary *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 RCTProfileEndEvent(uint64_t tag,
|
|
NSString *category,
|
|
NSDictionary *args);
|
|
|
|
/**
|
|
* Exposes memory usage metrics
|
|
*/
|
|
|
|
NSDictionary *RCTProfileGetMemoryUsage(BOOL);
|
|
|
|
/**
|
|
* Exposes device cpu usage metrics - Note this does not include JS Runtime CPU usage
|
|
*/
|
|
|
|
NSNumber *RCTProfileGetCPUUsage(void);
|
|
|
|
/**
|
|
* This pair of macros implicitly handle the event ID when beginning and ending
|
|
* an event, for both simplicity and performance reasons, this method is preferred
|
|
*
|
|
* NOTE: The EndEvent call has to be either, in the same scope of BeginEvent,
|
|
* or in a sub-scope, otherwise the ID stored by BeginEvent won't be accessible
|
|
* for EndEvent, in this case you may want to use the actual C functions.
|
|
*/
|
|
RCT_EXTERN int RCTProfileBeginAsyncEvent(uint64_t tag,
|
|
NSString *name,
|
|
NSDictionary *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,
|
|
int cookie,
|
|
NSString *name,
|
|
NSDictionary *args);
|
|
/**
|
|
* An event that doesn't have a duration (i.e. Notification, VSync, etc)
|
|
*/
|
|
RCT_EXTERN void RCTProfileImmediateEvent(uint64_t tag,
|
|
NSString *name,
|
|
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
|
|
*/
|
|
#define RCTProfileBlock(block, tag, category, arguments) \
|
|
^{ \
|
|
RCTProfileBeginEvent(tag, @(__PRETTY_FUNCTION__), nil); \
|
|
block(); \
|
|
RCTProfileEndEvent(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 *);
|
|
|
|
#else
|
|
|
|
#define RCTProfileBeginFlowEvent()
|
|
#define _RCTProfileBeginFlowEvent() @0
|
|
|
|
#define RCTProfileEndFlowEvent()
|
|
#define _RCTProfileEndFlowEvent()
|
|
|
|
#define RCTProfileIsProfiling(...) NO
|
|
#define RCTProfileInit(...)
|
|
#define RCTProfileEnd(...) @""
|
|
|
|
#define RCTProfileBeginEvent(...)
|
|
#define RCTProfileEndEvent(...)
|
|
|
|
#define RCTProfileBeginAsyncEvent(...) 0
|
|
#define RCTProfileEndAsyncEvent(...)
|
|
|
|
#define RCTProfileImmediateEvent(...)
|
|
|
|
#define RCTProfileGetMemoryUsage(...)
|
|
#define RCTProfileGetCPUUsage(...)
|
|
|
|
#define RCTProfileBlock(block, ...) block
|
|
|
|
#define RCTProfileHookModules(...)
|
|
#define RCTProfileUnhookModules(...)
|
|
|
|
#endif
|