Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/backends/qemu/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::{
},
},
instance::{InstanceClient, ThreadPoolSnapshot},
util::Path,
};

/// Wire client for an QEMU-managed VM.
Expand Down Expand Up @@ -261,7 +262,7 @@ impl InstanceClient for QemuInstanceClient {
"qemu topology reported no iothread TIDs".into(),
));
}
let pid = Process::new(first_tid)?
let pid = Process::new_with_root(Path::proc_pid(first_tid))?
.status()
.map_err(|e| BackendClientError::InvalidState(format!("pid resolution: {e}")))?
.tgid;
Expand Down
7 changes: 5 additions & 2 deletions src/backends/qemu/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use regex::Regex;
use rustix::param;
use thiserror::Error;

use crate::backends::{BackendClientError, VqMapping};
use crate::{
backends::{BackendClientError, VqMapping},
util::Path,
};

/// Errors produced while querying or reconfiguring a QEMU vm.
#[derive(Debug, Error)]
Expand Down Expand Up @@ -229,7 +232,7 @@ impl CpuSample {
wall: Instant::now(),
};

let p = Process::new(pid)?;
let p = Process::new_with_root(Path::proc_pid(pid))?;
for &tid in iothread_tids.values() {
let stat = p.task_from_tid(tid)?.stat()?;
out.jiffies.insert(tid, stat.utime + stat.stime);
Expand Down
6 changes: 4 additions & 2 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
};

use futures_util::future::join_all;
use procfs::{CpuPressure, Current, CurrentSI, IoPressure, MemoryPressure, ProcError};
use procfs::{CpuPressure, Current, FromReadSI, IoPressure, MemoryPressure, ProcError};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this change about?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to build KernelStats from a file and current_system_info and that needed different traits.

use serde::{Deserialize, Serialize};
use statistical::median;
use thiserror::Error;
Expand Down Expand Up @@ -1127,7 +1127,9 @@ fn read_psi_sample() -> PsiSample {

/// Read aggregate host CPU counters.
fn read_host_cpu_sample() -> Result<HostCpuSample, ControllerError> {
let total = procfs::KernelStats::current()?.total;
let total =
procfs::KernelStats::from_file(Path::new("/proc/stat"), procfs::current_system_info())?
.total;
let idle_ticks = total.idle.saturating_add(total.iowait.unwrap_or(0));
let total_ticks = total
.user
Expand Down
4 changes: 2 additions & 2 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ fn read_cpu_sample(
pid: i32,
filter: &crate::instance::ThreadNameFilter,
) -> Result<CpuSample, CpuSampleError> {
let process = Process::new(pid)?;
let process = Process::new_with_root(Path::proc_pid(pid))?;
let tasks = process.tasks()?;
let mut cpu_ticks = 0u64;
let mut thread_count = 0u32;
Expand Down Expand Up @@ -698,7 +698,7 @@ fn read_cpu_sample(

/// Read cgroup v2 CPU quota and throttle counters for `pid`.
fn read_cgroup_sample(pid: i32) -> Result<CgroupSample, CgroupError> {
let process = Process::new(pid)?;
let process = Process::new_with_root(Path::proc_pid(pid))?;
let cgroups = process.cgroups()?;
let path = cgroups
.0
Expand Down
10 changes: 10 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ impl Path {
pub fn glob(&self) -> glob::Paths {
glob::glob(&self.path.to_string_lossy()).expect("valid glob pattern")
}

/// `/proc/<pid>` after applying [`IO_THREAD_CONTROLLER_ROOT_PATH`].
///
/// `procfs::process::Process::new` always opens the real `/proc`. Callers
/// that should honor the mock root pass this path to
/// `Process::new_with_root`.
pub fn proc_pid(pid: i32) -> std::path::PathBuf {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this function belongs here, I don't feel too strongly though.

let path = Self::new(&format!("/proc/{pid}"));
std::path::PathBuf::from(std::path::Path::as_os_str(&path))
}
}

impl From<&str> for Path {
Expand Down
Loading