Remove our macOS-only task-info crate (#41132)

This crate is just using system APIs to get the resident and virtual
memory size of the current process. We can do this directly with
`mach2`, which also allows more flexibility if we want to fetch other
values in the future.

This does require duplicating `mach2` as the version used by `gilrs` is
older. Presumably, some future release of `gilrs` will upgrade soon.

Testing: There aren't really tests for this, but I tested it manually by
running the memory reporter and ensuring that both the old and new
values were
the same.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson
2025-12-08 13:04:26 +01:00
committed by GitHub
parent 6f62269c8c
commit 1e8d1cf081
10 changed files with 40 additions and 153 deletions

View File

@@ -1,12 +0,0 @@
[package]
name = "task_info"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
publish.workspace = true
rust-version.workspace = true
build = "build.rs"
[build-dependencies]
cc = "1.0"

View File

@@ -1,13 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
fn main() {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
if target_os == "macos" {
cc::Build::new()
.file("src/task_info.c")
.compile("libtask_info.a");
}
}

View File

@@ -1,12 +0,0 @@
// Copyright 2014 The Servo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! A helper crate to get task information on macos.
#[cfg(target_os = "macos")]
pub mod task_basic_info;

View File

@@ -1,58 +0,0 @@
// Copyright 2014 The Servo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Interface to the measurements in the task_basic_info struct, gathered by
//! invoking `task_info()` with the `TASK_BASIC_INFO` flavor.
use std::os::raw::c_int;
#[allow(non_camel_case_types)]
type size_t = usize;
/// Obtains task_basic_info::virtual_size.
pub fn virtual_size() -> Option<usize> {
let mut virtual_size: size_t = 0;
let rv = unsafe { TaskBasicInfoVirtualSize(&mut virtual_size) };
if rv == 0 {
Some(virtual_size as usize)
} else {
None
}
}
/// Obtains task_basic_info::resident_size.
pub fn resident_size() -> Option<usize> {
let mut resident_size: size_t = 0;
let rv = unsafe { TaskBasicInfoResidentSize(&mut resident_size) };
if rv == 0 {
Some(resident_size as usize)
} else {
None
}
}
unsafe extern "C" {
fn TaskBasicInfoVirtualSize(virtual_size: *mut size_t) -> c_int;
fn TaskBasicInfoResidentSize(resident_size: *mut size_t) -> c_int;
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_stuff() {
// In theory these can fail to return a value, but in practice they
// don't unless something really bizarre has happened with the OS. So
// assume they succeed. The returned values are non-deterministic, but
// check they're non-zero as a basic sanity test.
assert!(virtual_size().unwrap() > 0);
assert!(resident_size().unwrap() > 0);
}
}

View File

@@ -1,39 +0,0 @@
// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#include <mach/mach_init.h>
#include <mach/task.h>
static int
TaskBasicInfo(struct task_basic_info* info)
{
mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
kern_return_t kr = task_info(mach_task_self(), TASK_BASIC_INFO,
(task_info_t)info, &count);
return kr == KERN_SUCCESS ? 0 : -1;
}
int
TaskBasicInfoVirtualSize(size_t* virtualSize)
{
struct task_basic_info ti;
int rv = TaskBasicInfo(&ti);
*virtualSize = (rv == 0) ? ti.virtual_size : 0;
return rv;
}
int
TaskBasicInfoResidentSize(size_t* residentSize)
{
struct task_basic_info ti;
int rv = TaskBasicInfo(&ti);
*residentSize = (rv == 0) ? ti.resident_size : 0;
return rv;
}