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

Ignore processes that exit mid poll #1175

Closed
wants to merge 2 commits into from
Closed
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
48 changes: 32 additions & 16 deletions lading/src/observer/linux/procfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@
}
}
}
// Update the process_info map to only hold processes seen by the current poll call.
self.process_info.retain(|pid, _| pids.contains(pid));

let pid = process.pid();

// `/proc/{pid}/status`
let status = match process.status() {
Ok(status) => status,
Err(e) => {
warn!("Couldn't read status: {:?}", e);
warn!("Couldn't read status: {:?}, reading next process", e);
// The pid may have exited since we scanned it or we may not
// have sufficient permission.
continue;
Expand All @@ -140,19 +142,31 @@
match self.process_info.entry(pid) {
Entry::Occupied(_) => { /* Already initialized */ }
Entry::Vacant(entry) => {
let exe = proc_exe(pid).await?;
let comm = proc_comm(pid).await?;
let cmdline = proc_cmdline(pid).await?;
let pid_s = format!("{pid}");
let stat_sampler = stat::Sampler::new();
let process_info = {

Check failure on line 145 in lading/src/observer/linux/procfs.rs

View workflow job for this annotation

GitHub Actions / Rust Actions (Check/Fmt/Clippy) (ubuntu-latest)

type annotations needed for `std::result::Result<observer::linux::procfs::ProcessInfo, _>`

Check failure on line 145 in lading/src/observer/linux/procfs.rs

View workflow job for this annotation

GitHub Actions / Test Suite

type annotations needed for `Result<ProcessInfo, _>`
let exe = proc_exe(pid).await?;
let comm = proc_comm(pid).await?;
let cmdline = proc_cmdline(pid).await?;
let pid_s = format!("{pid}");
let stat_sampler = stat::Sampler::new();

entry.insert(ProcessInfo {
cmdline,
exe,
comm,
pid_s,
stat_sampler,
});
Ok(ProcessInfo {
cmdline,
exe,
comm,
pid_s,
stat_sampler,
})
};

match process_info {
Ok(info) => {
entry.insert(info);
}
Err(e) => {
warn!("Couldn't create process_info entry for `/proc/{pid}`, reading next process: {e}");
continue;
}
}
}
}

Expand Down Expand Up @@ -186,7 +200,7 @@
// We don't want to bail out entirely if we can't read stats
// which will happen if we don't have permissions or, more
// likely, the process has exited.
warn!("Couldn't process `/proc/{pid}/stat`: {e}");
warn!("Couldn't process `/proc/{pid}/stat`, reading next process: {e}");
continue;
}

Expand Down Expand Up @@ -254,7 +268,8 @@
// We don't want to bail out entirely if we can't read stats
// which will happen if we don't have permissions or, more
// likely, the process has exited.
warn!("Couldn't process `/proc/{pid}/smaps`: {err}");
warn!("Couldn't process `/proc/{pid}/smaps`, reading next process: {err}");
continue;
}
}

Expand All @@ -263,7 +278,8 @@
// 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}");
warn!("Couldn't process `/proc/{pid}/smaps_rollup`, reading next process: {err}");
continue;
}
}
// END pid loop
Expand Down
Loading