Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RSS reporting on macOS #98384

Merged
merged 1 commit into from Jun 28, 2022
Merged

Conversation

rdzhaafar
Copy link
Contributor

NOTE: This is a duplicate of #98164, which I closed because I borked my rustc fork

Currently, rustc_data_structures::profiling::get_resident_set_size() always returns None on macOS. This is because
macOS does not implement procfs used in the unix version of the function:

...
else if #[cfg(unix)] {
        pub fn get_resident_set_size() -> Option<usize> {
            let field = 1;
            let contents = fs::read("/proc/self/statm").ok()?;
            let contents = String::from_utf8(contents).ok()?;
            let s = contents.split_whitespace().nth(field)?;
            let npages = s.parse::<usize>().ok()?;
            Some(npages * 4096)
        }
...

The proposed solution uses libproc, and more specifically proc_pidinfo, which has been available on macOS since 10.5 if the function signature inside libproc.h is to be believed:

int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 22, 2022
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2022
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me but I'm not familiar with this API so I'll get a second opinion.

@davidtwco
Copy link
Member

r? @michaelwoerister

@michaelwoerister
Copy link
Member

Looks good to me. Thanks, @rdzhaafar!

@bors r=davidtwco,michaelwoerister

@bors
Copy link
Contributor

bors commented Jun 27, 2022

📌 Commit c416307 has been approved by davidtwco,michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 27, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 28, 2022
…r=davidtwco,michaelwoerister

Fix RSS reporting on macOS

> NOTE: This is a duplicate of rust-lang#98164, which I closed because I borked my rustc fork

Currently, `rustc_data_structures::profiling::get_resident_set_size()` always returns `None` on macOS. This is because
macOS does not implement procfs used in the unix version of the function:

```rust
...
else if #[cfg(unix)] {
        pub fn get_resident_set_size() -> Option<usize> {
            let field = 1;
            let contents = fs::read("/proc/self/statm").ok()?;
            let contents = String::from_utf8(contents).ok()?;
            let s = contents.split_whitespace().nth(field)?;
            let npages = s.parse::<usize>().ok()?;
            Some(npages * 4096)
        }
...
```

The proposed solution uses libproc, and more specifically `proc_pidinfo`, which has been available on macOS since 10.5 if the function signature inside libproc.h is to be believed:

```c
int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 28, 2022
Rollup of 9 pull requests

Successful merges:

 - rust-lang#97346 (Remove a back-compat hack on lazy TAIT)
 - rust-lang#98261 (Remove `MAX_SUGGESTION_HIGHLIGHT_LINES`)
 - rust-lang#98337 ([RFC 2011] Optimize non-consuming operators)
 - rust-lang#98384 (Fix RSS reporting on macOS)
 - rust-lang#98420 (translation: lint fix + more migration)
 - rust-lang#98430 (Refactor iter adapters with less macros)
 - rust-lang#98555 (Hermit: Fix initializing lazy locks)
 - rust-lang#98595 (Implement `Send` and `Sync` for `ThinBox<T>`)
 - rust-lang#98597 (Remove unstable CStr/CString change from 1.62 release note)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 56b7786 into rust-lang:master Jun 28, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants