Skip to content

Commit

Permalink
below: pid_cgroup: Avoid intermediate vector alloc
Browse files Browse the repository at this point in the history
Summary:
This is a small improvement, around 0.1% or so of CPU, but it's also
just cleaner.

Reviewed By: dschatzberg

Differential Revision: D58084032

fbshipit-source-id: 298baf1e37402bc4ddedfb23d0384f40b0f49afc
  • Loading branch information
cdown authored and facebook-github-bot committed Jun 4, 2024
1 parent 4622b69 commit 41bd1d8
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions below/procfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,14 +693,15 @@ impl ProcReader {
// A line starting with "0::" would be an entry for cgroup v2.
// Otherwise, the line containing "pids" controller is what we want
// for cgroup v1.
let parts: Vec<_> = line.splitn(3, ':').collect();
if parts.len() == 3 {
if parts[0] == "0" && parts[1] == "" {
cgroup_path = Some(parts[2].to_owned());
// cgroup v2 takes precedence
break;
} else if parts[1].split(',').any(|c| c == "pids") {
cgroup_path = Some(parts[2].to_owned());
let mut parts = line.splitn(3, ':');
if let (Some(hierarchy_id), Some(controller_list), Some(path)) =
(parts.next(), parts.next(), parts.next())
{
if hierarchy_id == "0" && controller_list.is_empty() {
return Ok(path.to_owned());
} else if controller_list.split(',').any(|c| c == "pids") {
// Not return, since if cgroup v2 is found it takes precedence
cgroup_path = Some(path.to_owned());
}
}
}
Expand Down

0 comments on commit 41bd1d8

Please sign in to comment.