Skip to content

Commit

Permalink
Expand smaps / smaps_rollup parsing (#1130)
Browse files Browse the repository at this point in the history
### What does this PR do?

This commit expands the number of fields we parse from the smaps/smaps_rollup
files. I have not hooked these up yet to metrics emission but will in a follow-up
commit to this PR.
  • Loading branch information
blt authored Dec 6, 2024
1 parent 47ff608 commit d767aa4
Show file tree
Hide file tree
Showing 7 changed files with 508 additions and 490 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## Added
- Parse nearly the complete field list of smaps/smaps_rollup in the Linux observer.
## Removed
- Removed the unused target-rss-byte-limit from the command line, internal stub of.
## Changed
Expand Down
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lading/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ flate2 = { version = "1.0.34", default-features = false, features = [
] }
futures = "0.3.31"
fuser = { version = "0.15", optional = true }
heck = { version = "0.5", default-features = false }
http = "0.2"
http-serde = "1.1"
hyper = { workspace = true, features = ["backports", "client", "deprecated", "http1", "http2", "server"] }
Expand Down
1 change: 0 additions & 1 deletion lading/src/captures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ impl CaptureManager {
.ok_or(Error::CapturePath)?
);
for line in lines.drain(..) {
info!("encoding: {line:?}");
let pyld = serde_json::to_string(&line)?;
self.capture_fp
.write_all(pyld.as_bytes())
Expand Down
89 changes: 50 additions & 39 deletions lading/src/observer/linux/procfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl Sampler {
// then we assume smaps operations will fail as well.
if has_ptrace_perm {
joinset.spawn(async move {
// TODO this code reads smaps
// `/proc/{pid}/smaps`
let memory_regions = match memory::smaps::Regions::from_pid(pid) {
Ok(memory_regions) => memory_regions,
Err(e) => {
Expand All @@ -313,48 +313,59 @@ impl Sampler {
];
gauge!("smaps.rss.by_pathname", &labels).set(measures.rss as f64);
gauge!("smaps.pss.by_pathname", &labels).set(measures.pss as f64);
gauge!("smaps.size.by_pathname", &labels).set(measures.size as f64);
gauge!("smaps.swap.by_pathname", &labels).set(measures.swap as f64);
}
gauge!("smaps.size.by_pathname", &labels).set(measures.size as f64);

let measures = memory_regions.aggregate();
let labels = [
("pid", format!("{pid}")),
("exe", basename.clone()),
("cmdline", cmdline.clone()),
("comm", comm.clone()),
];

gauge!("smaps.rss.sum", &labels).set(measures.rss as f64);
gauge!("smaps.pss.sum", &labels).set(measures.pss as f64);
gauge!("smaps.size.sum", &labels).set(measures.size as f64);
gauge!("smaps.swap.sum", &labels).set(measures.swap as f64);

// This code reads smaps_rollup
let rollup = match memory::smaps_rollup::Rollup::from_pid(pid) {
Ok(rollup) => rollup,
Err(e) => {
// We don't want to bail out entirely if we can't read smap rollup
// which will happen if we don't have permissions or, more
// likely, the process has exited.
warn!("Couldn't process `/proc/{pid}/smaps_rollup`: {}", e);
return;
if let Some(m) = measures.private_clean {
gauge!("smaps.private_clean.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.private_dirty {
gauge!("smaps.private_dirty.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.shared_clean {
gauge!("smaps.shared_clean.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.shared_dirty {
gauge!("smaps.shared_dirty.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.referenced {
gauge!("smaps.referenced.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.anonymous {
gauge!("smaps.anonymous.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.lazy_free {
gauge!("smaps.lazy_free.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.anon_huge_pages {
gauge!("smaps.anon_huge_pages.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.shmem_pmd_mapped {
gauge!("smaps.shmem_pmd_mapped.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.shared_hugetlb {
gauge!("smaps.shared_hugetlb.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.private_hugetlb {
gauge!("smaps.private_hugetlb.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.file_pmd_mapped {
gauge!("smaps.file_pmd_mapped.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.locked {
gauge!("smaps.locked.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.swap_pss {
gauge!("smaps.swap_pss.by_pathname", &labels).set(m as f64);
}
};

gauge!("smaps_rollup.rss", &labels).set(rollup.rss as f64);
gauge!("smaps_rollup.pss", &labels).set(rollup.pss as f64);
if let Some(v) = rollup.pss_dirty {
gauge!("smaps_rollup.pss_dirty", &labels).set(v as f64);
}
if let Some(v) = rollup.pss_anon {
gauge!("smaps_rollup.pss_anon", &labels).set(v as f64);
}
if let Some(v) = rollup.pss_file {
gauge!("smaps_rollup.pss_file", &labels).set(v as f64);
}
if let Some(v) = rollup.pss_shmem {
gauge!("smaps_rollup.pss_shmem", &labels).set(v as f64);

// `/proc/{pid}/smaps_rollup`
if let Err(err) = memory::smaps_rollup::poll(pid, &labels).await {
// We don't want to bail out entirely if we can't read smap rollup
// which will happen if we don't have permissions or, more
// likely, the process has exited.
warn!("Couldn't process `/proc/{pid}/smaps_rollup`: {err}");
}
});
}
Expand Down
Loading

0 comments on commit d767aa4

Please sign in to comment.