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

metrics: fix the maxrss metrics on macOS #30937

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/metrics/src/rusage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,33 @@ impl Unit for Unitless {
}
}

/// Unit for converting KiB values to bytes expressed i64.
struct KilobytesToBytes;
impl Unit for KilobytesToBytes {
/// Unit for converting maxrss values to bytes expressed as i64.
///
/// The maxrss unit depends on the OS:
/// * Linux: KiB
/// * macOS: bytes
struct MaxrssToBytes;
impl Unit for MaxrssToBytes {
type Gauge = IntGauge;
type From = libc::c_long;
type To = i64;

#[cfg(not(target_os = "macos"))]
fn from(value: Self::From) -> Self::To {
value.saturating_mul(1024)
}

#[cfg(target_os = "macos")]
fn from(value: Self::From) -> Self::To {
value
}
}

metrics! {
mz_metrics_libc
(ru_utime, "user CPU time used", "_seconds_total", Timeval),
(ru_stime, "system CPU time used", "_seconds_total", Timeval),
(ru_maxrss, "maximum resident set size", "_bytes", KilobytesToBytes),
(ru_maxrss, "maximum resident set size", "_bytes", MaxrssToBytes),
(ru_minflt, "page reclaims (soft page faults)", "_total", Unitless),
(ru_majflt, "page faults (hard page faults)", "_total", Unitless),
(ru_inblock, "block input operations", "_total", Unitless),
Expand Down
Loading