mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 13:21:01 +00:00
Use MaybeUninit when calling getrusage (musl compatibility) (#7086)
This commit is contained in:
@@ -197,33 +197,21 @@ pub mod memory_tracker {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub mod max_rss_stat {
|
pub mod max_rss_stat {
|
||||||
use crate::LOG_TARGET;
|
use crate::LOG_TARGET;
|
||||||
use libc::{getrusage, rusage, timeval, RUSAGE_THREAD};
|
use core::mem::MaybeUninit;
|
||||||
|
use libc::{getrusage, rusage, RUSAGE_THREAD};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
/// Get the rusage stats for the current thread.
|
/// Get the rusage stats for the current thread.
|
||||||
fn getrusage_thread() -> io::Result<rusage> {
|
fn getrusage_thread() -> io::Result<rusage> {
|
||||||
let mut result = rusage {
|
let mut result: MaybeUninit<rusage> = MaybeUninit::zeroed();
|
||||||
ru_utime: timeval { tv_sec: 0, tv_usec: 0 },
|
|
||||||
ru_stime: timeval { tv_sec: 0, tv_usec: 0 },
|
// SAFETY: `result` is a valid pointer, so calling this is safe.
|
||||||
ru_maxrss: 0,
|
if unsafe { getrusage(RUSAGE_THREAD, result.as_mut_ptr()) } == -1 {
|
||||||
ru_ixrss: 0,
|
|
||||||
ru_idrss: 0,
|
|
||||||
ru_isrss: 0,
|
|
||||||
ru_minflt: 0,
|
|
||||||
ru_majflt: 0,
|
|
||||||
ru_nswap: 0,
|
|
||||||
ru_inblock: 0,
|
|
||||||
ru_oublock: 0,
|
|
||||||
ru_msgsnd: 0,
|
|
||||||
ru_msgrcv: 0,
|
|
||||||
ru_nsignals: 0,
|
|
||||||
ru_nvcsw: 0,
|
|
||||||
ru_nivcsw: 0,
|
|
||||||
};
|
|
||||||
if unsafe { getrusage(RUSAGE_THREAD, &mut result) } == -1 {
|
|
||||||
return Err(io::Error::last_os_error())
|
return Err(io::Error::last_os_error())
|
||||||
}
|
}
|
||||||
Ok(result)
|
|
||||||
|
// SAFETY: `result` was successfully initialized by `getrusage`.
|
||||||
|
unsafe { Ok(result.assume_init()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the `ru_maxrss` for the current thread.
|
/// Gets the `ru_maxrss` for the current thread.
|
||||||
|
|||||||
Reference in New Issue
Block a user