From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- toolkit/components/processtools/ProcInfo.mm | 45 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'toolkit/components/processtools/ProcInfo.mm') diff --git a/toolkit/components/processtools/ProcInfo.mm b/toolkit/components/processtools/ProcInfo.mm index 6c98ce81f5..68edeef81b 100644 --- a/toolkit/components/processtools/ProcInfo.mm +++ b/toolkit/components/processtools/ProcInfo.mm @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -30,18 +29,19 @@ static void GetTimeBase(mach_timebase_info_data_t* timebase) { namespace mozilla { nsresult GetCpuTimeSinceProcessStartInMs(uint64_t* aResult) { - struct proc_taskinfo pti; - if ((unsigned long)proc_pidinfo(getpid(), PROC_PIDTASKINFO, 0, &pti, - PROC_PIDTASKINFO_SIZE) < - PROC_PIDTASKINFO_SIZE) { + task_power_info_data_t task_power_info; + mach_msg_type_number_t count = TASK_POWER_INFO_COUNT; + kern_return_t kr = task_info(mach_task_self(), TASK_POWER_INFO, + (task_info_t)&task_power_info, &count); + if (kr != KERN_SUCCESS) { return NS_ERROR_FAILURE; } mach_timebase_info_data_t timebase; GetTimeBase(&timebase); - *aResult = (pti.pti_total_user + pti.pti_total_system) * timebase.numer / - timebase.denom / PR_NSEC_PER_MSEC; + *aResult = (task_power_info.total_user + task_power_info.total_system) * + timebase.numer / timebase.denom / PR_NSEC_PER_MSEC; return NS_OK; } @@ -82,18 +82,6 @@ ProcInfoPromise::ResolveOrRejectValue GetProcInfoSync( info.windows = std::move(request.windowInfo); info.utilityActors = std::move(request.utilityInfo); - struct proc_taskinfo pti; - if ((unsigned long)proc_pidinfo(request.pid, PROC_PIDTASKINFO, 0, &pti, - PROC_PIDTASKINFO_SIZE) < - PROC_PIDTASKINFO_SIZE) { - // Can't read data for this process. - // Probably either a sandboxing issue or a race condition, e.g. - // the process has been just been killed. Regardless, skip process. - continue; - } - info.cpuTime = (pti.pti_total_user + pti.pti_total_system) * - timebase.numer / timebase.denom; - mach_port_t selectedTask; // If we did not get a task from a child process, we use mach_task_self() if (request.childTask == MACH_PORT_NULL) { @@ -102,12 +90,25 @@ ProcInfoPromise::ResolveOrRejectValue GetProcInfoSync( selectedTask = request.childTask; } + task_power_info_data_t task_power_info; + mach_msg_type_number_t count = TASK_POWER_INFO_COUNT; + kern_return_t kr = task_info(selectedTask, TASK_POWER_INFO, + (task_info_t)&task_power_info, &count); + if (kr != KERN_SUCCESS) { + // Can't read data for this process. + // Probably either a sandboxing issue or a race condition, e.g. + // the process has been just been killed. Regardless, skip process. + continue; + } + info.cpuTime = (task_power_info.total_user + task_power_info.total_system) * + timebase.numer / timebase.denom; + // The phys_footprint value (introduced in 10.11) of the TASK_VM_INFO data // matches the value in the 'Memory' column of the Activity Monitor. task_vm_info_data_t task_vm_info; - mach_msg_type_number_t count = TASK_VM_INFO_COUNT; - kern_return_t kr = task_info(selectedTask, TASK_VM_INFO, - (task_info_t)&task_vm_info, &count); + count = TASK_VM_INFO_COUNT; + kr = task_info(selectedTask, TASK_VM_INFO, (task_info_t)&task_vm_info, + &count); info.memory = kr == KERN_SUCCESS ? task_vm_info.phys_footprint : 0; // Now getting threads info -- cgit v1.2.3