Skip to content

Commit

Permalink
ui/profiler: Track the last non-empty measurement
Browse files Browse the repository at this point in the history
So that the Client knows when it has no statistics to be shown
  • Loading branch information
dimtpap committed Aug 25, 2023
1 parent 7c2c013 commit 047c6ce
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/ui/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@ mod data {
pub struct Client {
title: String,
measurements: VecDeque<ClientMeasurement>,

// Position of last non-empty profiling that was added.
// When this reaches 0 every profiling is empty indicating
// that this follower has no statistics to show
last_non_empty_pos: usize,
}

impl Client {
fn new(title: String, max_profilings: usize) -> Self {
Self {
title,
measurements: VecDeque::with_capacity(max_profilings),

last_non_empty_pos: max_profilings,
}
}

Expand All @@ -100,6 +107,8 @@ mod data {
max_profilings,
ClientMeasurement::new(follower, driver),
);

self.last_non_empty_pos = self.measurements.len();
}

fn add_empty_measurement(&mut self, max_profilings: usize) {
Expand All @@ -108,6 +117,12 @@ mod data {
max_profilings,
ClientMeasurement::empty(),
);

self.last_non_empty_pos -= 1;
}

fn is_empty(&self) -> bool {
self.last_non_empty_pos == 0
}

pub fn end_date(&self) -> PlotPoints {
Expand Down Expand Up @@ -178,14 +193,16 @@ mod data {
DriverMeasurement::from(&profiling),
);

// Add measurements to registered followers
for (id, follower) in &mut self.followers {
// Add measurements to registered followers and delete those that have no non-empty measurements
self.followers.retain(|id, follower| {
if let Some(f) = profiling.followers.iter().find(|nb| nb.id == *id) {
follower.add_measurement(f, &profiling.driver, max_profilings)
follower.add_measurement(f, &profiling.driver, max_profilings);
} else {
follower.add_empty_measurement(max_profilings)
follower.add_empty_measurement(max_profilings);
}
}

!follower.is_empty()
});

// Add new followers
for follower in &profiling.followers {
Expand Down

0 comments on commit 047c6ce

Please sign in to comment.