Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions crates/memtrack/src/ebpf/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ pub struct TrackerOptions {
/// exec-mapping watcher.
#[builder(default = true)]
pub allocators: bool,
/// Reconstruct per-process RSS from the folio rmap fentry hooks.
/// Track physical (resident) memory precisely by reconstructing per-process
/// RSS from the folio rmap fentry hooks. Off by default: the hooks target
/// folio rmap functions whose full set only exists on newer kernels, so
/// tracking is opt-in and `RmapSupport::detect` gates what actually attaches.
#[builder(default = false)]
pub rmap: bool,
pub physical: bool,
}

impl TrackerOptions {
Expand All @@ -28,7 +31,7 @@ impl TrackerOptions {
std::env::var("CODSPEED_MEMTRACK_TRACK_ALLOCATORS").as_deref(),
Ok("0") | Ok("false")
))
.rmap(std::env::var("CODSPEED_MEMTRACK_TRACK_RMAP").is_ok_and(|v| v == "1"))
.physical(std::env::var("CODSPEED_MEMTRACK_TRACK_PHYSICAL").is_ok_and(|v| v == "1"))
.build()
}
}
Expand All @@ -49,16 +52,16 @@ impl Tracker {
/// Create a tracker from an explicit probe selection rather than the environment.
pub fn with_options(options: TrackerOptions) -> Result<Self> {
Self::build(
MemtrackBpf::new_with_rmap(options.rmap)?,
MemtrackBpf::new_with_rmap(options.physical)?,
options.allocators,
)
}

/// Like [`Tracker::new`], but pinned to a specific BPF variant instead of
/// the detected one.
pub fn with_variant(variant: BpfVariant) -> Result<Self> {
let track_rmap = TrackerOptions::from_env().rmap;
Self::build(MemtrackBpf::with_variant(variant, track_rmap)?, true)
let physical = TrackerOptions::from_env().physical;
Self::build(MemtrackBpf::with_variant(variant, physical)?, true)
}

/// Build a tracker: attach lifetime tracepoints (and rmap fentries when the
Expand Down
2 changes: 1 addition & 1 deletion crates/memtrack/tests/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub fn track_command_with_variant(command: Command, variant: BpfVariant) -> Trac
fn rmap_only_options() -> TrackerOptions {
TrackerOptions::builder()
.allocators(false)
.rmap(true)
.physical(true)
.build()
}

Expand Down