Skip to content

Commit ce4fe14

Browse files
committed
total_rss_bytes and total_pss_bytes from smaps_rollup
This commit adds collection of total PSS bytes for all processes from smaps_rollup, adjusting total_rss_bytes to also be from the same source. Signed-off-by: Brian L. Troutwine <[email protected]>
1 parent e7ffc27 commit ce4fe14

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lading/src/observer/linux/procfs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Sampler {
9191
let mut total_processes: u64 = 0;
9292
// We maintain a tally of the total RSS and PSS consumed by the parent
9393
// process and its children.
94-
let mut total_rss: u64 = 0;
94+
let mut aggr = memory::smaps_rollup::Aggregator::default();
9595

9696
// Calculate the ticks since machine uptime. This will be important
9797
// later for calculating per-process uptime. Because we capture this one
@@ -270,7 +270,6 @@ impl Sampler {
270270
// Number of threads this process has active.
271271
gauge!("num_threads", &labels).set(stats.num_threads as f64);
272272

273-
total_rss += rss;
274273
total_processes += 1;
275274

276275
// Also report memory data from `proc/status` as a reference point
@@ -358,7 +357,7 @@ impl Sampler {
358357
}
359358

360359
// `/proc/{pid}/smaps_rollup`
361-
if let Err(err) = memory::smaps_rollup::poll(pid, &labels).await {
360+
if let Err(err) = memory::smaps_rollup::poll(pid, &labels, &mut aggr).await {
362361
// We don't want to bail out entirely if we can't read smap rollup
363362
// which will happen if we don't have permissions or, more
364363
// likely, the process has exited.
@@ -420,7 +419,8 @@ impl Sampler {
420419

421420
let totals = calculate_cpu_percentage(&total_sample, &self.previous_totals, self.num_cores);
422421

423-
gauge!("total_rss_bytes").set(total_rss as f64);
422+
gauge!("total_rss_bytes").set(aggr.rss as f64);
423+
gauge!("total_pss_bytes").set(aggr.pss as f64);
424424
gauge!("total_utime").set(total_sample.utime as f64);
425425
gauge!("total_stime").set(total_sample.stime as f64);
426426

lading/src/observer/linux/procfs/memory/smaps_rollup.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ pub(crate) enum Error {
1616
Parsing(String),
1717
}
1818

19+
#[derive(Debug, Clone, Copy, Default)]
20+
pub(crate) struct Aggregator {
21+
pub(crate) rss: u64,
22+
pub(crate) pss: u64,
23+
}
24+
1925
// Read `/proc/{pid}/smaps_rollup` and parse it directly into metrics.
20-
pub(crate) async fn poll(pid: i32, labels: &[(String, String)]) -> Result<(), Error> {
26+
pub(crate) async fn poll(
27+
pid: i32,
28+
labels: &[(String, String)],
29+
aggr: &mut Aggregator,
30+
) -> Result<(), Error> {
2131
let path = format!("/proc/{pid}/smaps_rollup");
2232
// NOTE `read_to_string` uses as few IO operations as possible in its
2333
// implementation, so we might get the contents here in one go.
@@ -55,6 +65,11 @@ pub(crate) async fn poll(pid: i32, labels: &[(String, String)]) -> Result<(), Er
5565
let name_len = name.len();
5666
// Last character is a :, skip it.
5767
let field = name[..name_len - 1].to_snake_case();
68+
match field.as_str() {
69+
"rss" => aggr.rss += value_kb,
70+
"pss" => aggr.pss += value_kb,
71+
_ => { /* ignore other fields */ }
72+
}
5873
let metric_name = format!("smaps_rollup.{field}");
5974
gauge!(metric_name, labels).set(value_kb as f64);
6075
}

0 commit comments

Comments
 (0)