Skip to content

Commit

Permalink
rss, pss, size, swap non-optional
Browse files Browse the repository at this point in the history
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
  • Loading branch information
blt committed Dec 6, 2024
1 parent 5d6d31d commit 5b37782
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
17 changes: 5 additions & 12 deletions lading/src/observer/linux/procfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,11 @@ impl Sampler {
("comm", comm.clone()),
("pathname", pathname),
];
if let Some(m) = measures.rss {
gauge!("smaps.rss.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.pss {
gauge!("smaps.pss.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.size {
gauge!("smaps.size.by_pathname", &labels).set(m as f64);
}
if let Some(m) = measures.swap {
gauge!("smaps.swap.by_pathname", &labels).set(m as f64);
}
gauge!("smaps.rss.by_pathname", &labels).set(measures.rss as f64);
gauge!("smaps.pss.by_pathname", &labels).set(measures.pss as f64);
gauge!("smaps.swap.by_pathname", &labels).set(measures.swap as f64);
gauge!("smaps.size.by_pathname", &labels).set(measures.size as f64);

if let Some(m) = measures.private_clean {
gauge!("smaps.private_clean.by_pathname", &labels).set(m as f64);
}
Expand Down
33 changes: 19 additions & 14 deletions lading/src/observer/linux/procfs/memory/smaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ struct Region {
// empty string indicates no pathname
pub(crate) pathname: String,

// Values (all in bytes) - Made Optional
pub(crate) size: Option<u64>,
pub(crate) pss: Option<u64>,
pub(crate) swap: Option<u64>,
pub(crate) rss: Option<u64>,
// Values (all in bytes)
pub(crate) size: u64,
pub(crate) pss: u64,
pub(crate) swap: u64,
pub(crate) rss: u64,
pub(crate) pss_dirty: Option<u64>, // only present in 6.0+
pub(crate) shared_clean: Option<u64>,
pub(crate) shared_dirty: Option<u64>,
Expand Down Expand Up @@ -103,7 +103,6 @@ impl Region {
pathname
};

// Initialize optional fields
let mut size: Option<u64> = None;
let mut pss: Option<u64> = None;
let mut rss: Option<u64> = None;
Expand Down Expand Up @@ -210,6 +209,12 @@ impl Region {
}
}

let (Some(size), Some(pss), Some(rss), Some(swap)) = (size, pss, rss, swap) else {
return Err(Error::Parsing(format!(
"Could not parse all value fields from region: '{contents}'"
)));
};

Ok(Region {
pathname: pathname.unwrap_or_default(),
size,
Expand Down Expand Up @@ -237,10 +242,10 @@ impl Region {

#[derive(Default)]
pub(crate) struct AggrMeasure {
pub(crate) size: Option<u64>,
pub(crate) pss: Option<u64>,
pub(crate) swap: Option<u64>,
pub(crate) rss: Option<u64>,
pub(crate) size: u64,
pub(crate) pss: u64,
pub(crate) swap: u64,
pub(crate) rss: u64,
pub(crate) pss_dirty: Option<u64>,
pub(crate) shared_clean: Option<u64>,
pub(crate) shared_dirty: Option<u64>,
Expand Down Expand Up @@ -288,10 +293,10 @@ impl Regions {
let pathname = region.pathname.clone();

let entry = map.entry(pathname).or_default();
aggregate_option(&mut entry.size, region.size);
aggregate_option(&mut entry.pss, region.pss);
aggregate_option(&mut entry.swap, region.swap);
aggregate_option(&mut entry.rss, region.rss);
entry.size += region.size;
entry.pss += region.pss;
entry.swap += region.swap;
entry.rss += region.rss;
aggregate_option(&mut entry.pss_dirty, region.pss_dirty);
aggregate_option(&mut entry.shared_clean, region.shared_clean);
aggregate_option(&mut entry.shared_dirty, region.shared_dirty);
Expand Down

0 comments on commit 5b37782

Please sign in to comment.