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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 28 additions & 5 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ pub enum ControllerError {
VmError(String),
}

/// Return queue count, total, fixed-point average, and median depth.
fn summarize_vq_depths(
depths: Option<&[u64]>,
) -> (Option<u32>, Option<u64>, Option<u64>, Option<u64>) {
let Some(depths) = depths.filter(|depths| !depths.is_empty()) else {
return (None, None, None, None);
};
let count = depths.len() as u32;
let total = depths.iter().copied().fold(0u64, u64::saturating_add);
let average_x100 = ((u128::from(total) * 100) / depths.len() as u128) as u64;
let median = median(
&depths
.iter()
.copied()
.map(|depth| depth as f64)
.collect::<Vec<_>>(),
)
.floor() as u64;
(Some(count), Some(total), Some(average_x100), Some(median))
}

/// Construct a [`Duration`] from whole minutes.
const fn from_mins(minutes: u64) -> Duration {
Duration::from_secs(minutes * 60)
Expand Down Expand Up @@ -481,6 +502,8 @@ impl Controller {
let instance = &self.instances[id];
let s = instance.status.read().await;
let cpu_stats = compute_cpu_stats(&s);
let (num_queues, derived_qd_total, qd_avg_x100, qd_median) =
summarize_vq_depths(s.per_vq_depth.as_deref());
payload.vms.push(SnapshotVm {
id: id.clone(),
vcpu_count: s.vcpu_count,
Expand Down Expand Up @@ -512,11 +535,11 @@ impl Controller {
p99: latency.p99,
avg: latency.avg,
}),
num_queues: None,
per_vq_depth: None,
qd_total: None,
qd_avg_x100: None,
qd_median: None,
num_queues,
per_vq_depth: s.per_vq_depth.clone(),
qd_total: s.vq_depth_total.or(derived_qd_total),
qd_avg_x100,
qd_median,
cpu_pct_avg: Some(cpu_stats.avg_pct),
cpu_pct_median: Some(cpu_stats.median_pct),
cpu_pct_total: Some(cpu_stats.total_pct),
Expand Down
13 changes: 13 additions & 0 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ impl Instance {
.perf
.as_ref()
.and_then(|perf| perf.write_latency_us);
status.per_vq_depth = snapshot
.perf
.as_ref()
.and_then(|perf| perf.per_vq_depth.clone());
status.vq_depth_total = snapshot.perf.as_ref().and_then(|perf| perf.vq_depth_total);
status.alive = true;
let backend_util = snapshot.per_thread_util.map(|util| util.clamp(0.0, 1.0));
if let Some(backend_util) = backend_util {
Expand Down Expand Up @@ -478,6 +483,10 @@ pub struct InstanceStatus {
pub read_latency_us: Option<LatencySummary>,
/// Latest write-latency histogram digest.
pub write_latency_us: Option<LatencySummary>,
/// Latest in-flight depth for each backend virtqueue.
pub per_vq_depth: Option<Vec<u64>>,
/// Latest sum of all virtqueue depths.
pub vq_depth_total: Option<u64>,
/// Latest read bandwidth in bytes per second.
pub read_bytes_per_second: u64,
/// Latest write bandwidth in bytes per second.
Expand Down Expand Up @@ -556,6 +565,10 @@ pub struct InstancePerfSample {
pub read_latency_us: Option<LatencySummary>,
/// Write-latency digest, when the backend has write samples.
pub write_latency_us: Option<LatencySummary>,
/// In-flight depth for each backend virtqueue.
pub per_vq_depth: Option<Vec<u64>>,
/// Sum of all virtqueue depths.
pub vq_depth_total: Option<u64>,
}

impl InstancePerfSample {
Expand Down
Loading