mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
[ReactNative] Unbreak debugger
This commit is contained in:
@@ -73,24 +73,7 @@ RCT_EXTERN void RCTProfileEndEvent(uint64_t tag,
|
||||
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.
|
||||
* Collects the initial event information for the event and returns a reference ID
|
||||
*/
|
||||
RCT_EXTERN int RCTProfileBeginAsyncEvent(uint64_t tag,
|
||||
NSString *name,
|
||||
@@ -156,9 +139,6 @@ RCT_EXTERN void RCTProfileUnhookModules(RCTBridge *);
|
||||
|
||||
#define RCTProfileImmediateEvent(...)
|
||||
|
||||
#define RCTProfileGetMemoryUsage(...)
|
||||
#define RCTProfileGetCPUUsage(...)
|
||||
|
||||
#define RCTProfileBlock(block, ...) block
|
||||
|
||||
#define RCTProfileHookModules(...)
|
||||
|
||||
@@ -72,7 +72,7 @@ static NSString *RCTProfileMemory(vm_size_t memory)
|
||||
return [NSString stringWithFormat:@"%.2lfmb", mem];
|
||||
}
|
||||
|
||||
NSDictionary *RCTProfileGetMemoryUsage(BOOL raw)
|
||||
static NSDictionary *RCTProfileGetMemoryUsage(void)
|
||||
{
|
||||
struct task_basic_info info;
|
||||
mach_msg_type_number_t size = sizeof(info);
|
||||
@@ -81,76 +81,14 @@ NSDictionary *RCTProfileGetMemoryUsage(BOOL raw)
|
||||
(task_info_t)&info,
|
||||
&size);
|
||||
if( kerr == KERN_SUCCESS ) {
|
||||
vm_size_t vs = info.virtual_size;
|
||||
vm_size_t rs = info.resident_size;
|
||||
return @{
|
||||
@"suspend_count": @(info.suspend_count),
|
||||
@"virtual_size": raw ? @(vs) : RCTProfileMemory(vs),
|
||||
@"resident_size": raw ? @(rs) : RCTProfileMemory(rs),
|
||||
@"virtual_size": RCTProfileMemory(info.virtual_size),
|
||||
@"resident_size": RCTProfileMemory(info.resident_size),
|
||||
};
|
||||
} else {
|
||||
return @{};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NSNumber *RCTProfileGetCPUUsage(void)
|
||||
{
|
||||
kern_return_t kr;
|
||||
task_info_data_t tinfo;
|
||||
mach_msg_type_number_t task_info_count;
|
||||
|
||||
task_info_count = TASK_INFO_MAX;
|
||||
kr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)tinfo, &task_info_count);
|
||||
if (kr != KERN_SUCCESS) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
thread_array_t thread_list;
|
||||
mach_msg_type_number_t thread_count;
|
||||
|
||||
thread_info_data_t thinfo;
|
||||
mach_msg_type_number_t thread_info_count;
|
||||
|
||||
thread_basic_info_t basic_info_th;
|
||||
|
||||
// get threads in the task
|
||||
kr = task_threads(mach_task_self(), &thread_list, &thread_count);
|
||||
if (kr != KERN_SUCCESS) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
long tot_sec = 0;
|
||||
long tot_usec = 0;
|
||||
float tot_cpu = 0;
|
||||
unsigned j;
|
||||
|
||||
for (j = 0; j < thread_count; j++) {
|
||||
thread_info_count = THREAD_INFO_MAX;
|
||||
kr = thread_info(thread_list[j], THREAD_BASIC_INFO,
|
||||
(thread_info_t)thinfo, &thread_info_count);
|
||||
if (kr != KERN_SUCCESS) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
basic_info_th = (thread_basic_info_t)thinfo;
|
||||
|
||||
if (!(basic_info_th->flags & TH_FLAGS_IDLE)) {
|
||||
tot_sec = tot_sec + basic_info_th->user_time.seconds + basic_info_th->system_time.seconds;
|
||||
tot_usec = tot_usec + basic_info_th->system_time.microseconds + basic_info_th->system_time.microseconds;
|
||||
tot_cpu = tot_cpu + basic_info_th->cpu_usage / (float)TH_USAGE_SCALE * 100.0;
|
||||
}
|
||||
|
||||
} // for each thread
|
||||
|
||||
kr = vm_deallocate(mach_task_self(), (vm_offset_t)thread_list, thread_count * sizeof(thread_t));
|
||||
|
||||
if( kr == KERN_SUCCESS ) {
|
||||
return @(tot_cpu);
|
||||
} else {
|
||||
return nil;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static NSDictionary *RCTProfileMergeArgs(NSDictionary *args0, NSDictionary *args1)
|
||||
@@ -431,7 +369,7 @@ void RCTProfileImmediateEvent(
|
||||
@"ts": RCTProfileTimestamp(CACurrentMediaTime()),
|
||||
@"scope": @(scope),
|
||||
@"ph": @"i",
|
||||
@"args": RCTProfileGetMemoryUsage(NO),
|
||||
@"args": RCTProfileGetMemoryUsage(),
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user