Dock ping is a line wave like the stats graph
Browse files at this commitd58406ac6a5fc85dc8840e1f20e7f308cb1e59e7Parent: 24aef4b- feat
- dock ping is a line wave like the stats graph
- fix
- usage drops its first sample (sysinfo's first per-process CPU on Windows is lifetime-vs-boot garbage)
3 changed files +19 -14
- crates/client/src/gui/dock.rs +8 -12
- crates/client/src/gui/wave.rs +6 -2
- crates/client/src/usage/mod.rs +5 -0
crates/client/src/gui/dock.rsmodified+8 -12
| @@ -14,7 +14,7 @@ use super::{ | ||
| 14 | 14 | hoverable_with, share_view::kind_icon, text, voice_stats, wave, widget::icon_button, |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | -const PING_BARS: usize = 12; | |
| 17 | +const PING_POINTS: usize = 12; | |
| 18 | 18 | |
| 19 | 19 | impl Yumush { |
| 20 | 20 | pub(super) fn dock(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> { |
| @@ -61,7 +61,7 @@ impl Yumush { | ||
| 61 | 61 | .voice_samples |
| 62 | 62 | .back() |
| 63 | 63 | .map_or(0., |sample| sample.ping_ms); |
| 64 | - let start = self.chat.voice_samples.len().saturating_sub(PING_BARS); | |
| 64 | + let start = self.chat.voice_samples.len().saturating_sub(PING_POINTS); | |
| 65 | 65 | let pings: Vec<f32> = self |
| 66 | 66 | .chat |
| 67 | 67 | .voice_samples |
| @@ -71,17 +71,13 @@ impl Yumush { | ||
| 71 | 71 | .collect(); |
| 72 | 72 | let peak = pings.iter().copied().fold(1., f32::max); |
| 73 | 73 | let bars = div() |
| 74 | - .flex() | |
| 75 | - .items_end() | |
| 76 | - .gap(px(1.)) | |
| 74 | + .w(px(PING_POINTS as f32 * 3.)) | |
| 77 | 75 | .h(px(12.)) |
| 78 | - .children(pings.iter().map(|ping| { | |
| 79 | - div() | |
| 80 | - .w(px(2.)) | |
| 81 | - .h(px((12. * ping / peak).max(1.))) | |
| 82 | - .rounded(px(1.)) | |
| 83 | - .bg(tone) | |
| 84 | - })); | |
| 76 | + .child(wave::line_of( | |
| 77 | + pings.iter().map(|ping| ping / peak * 0.9).collect(), | |
| 78 | + PING_POINTS, | |
| 79 | + tone, | |
| 80 | + )); | |
| 85 | 81 | |
| 86 | 82 | div() |
| 87 | 83 | .flex() |
crates/client/src/gui/wave.rsmodified+6 -2
| @@ -193,13 +193,17 @@ fn wave(bars: &[f32], size: f32, color: Hsla) -> Div { | ||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | pub fn line(levels: Vec<f32>, color: Hsla) -> impl IntoElement { |
| 196 | + line_of(levels, SAMPLE_HISTORY, color) | |
| 197 | +} | |
| 198 | + | |
| 199 | +pub fn line_of(levels: Vec<f32>, slots: usize, color: Hsla) -> impl IntoElement { | |
| 196 | 200 | canvas( |
| 197 | 201 | |_, _, _| {}, |
| 198 | 202 | move |bounds, _, window, _| { |
| 199 | - let first = SAMPLE_HISTORY.saturating_sub(levels.len()); | |
| 203 | + let first = slots.saturating_sub(levels.len()); | |
| 200 | 204 | let mut path = PathBuilder::stroke(px(1.5)); |
| 201 | 205 | for (index, &level) in levels.iter().enumerate() { |
| 202 | - let step = (first + index) as f32 / (SAMPLE_HISTORY - 1) as f32; | |
| 206 | + let step = (first + index) as f32 / slots.saturating_sub(1).max(1) as f32; | |
| 203 | 207 | let x = bounds.origin.x + bounds.size.width * step; |
| 204 | 208 | let y = bounds.origin.y + bounds.size.height * (1. - level); |
| 205 | 209 | if index == 0 { |
crates/client/src/usage/mod.rsmodified+5 -0
| @@ -124,6 +124,7 @@ struct Sampler { | ||
| 124 | 124 | pid: Pid, |
| 125 | 125 | cores: f32, |
| 126 | 126 | cpu_model: Arc<str>, |
| 127 | + primed: bool, | |
| 127 | 128 | gpu: GpuSampler, |
| 128 | 129 | #[cfg(target_os = "linux")] |
| 129 | 130 | threads: threads::Sampler, |
| @@ -146,6 +147,7 @@ impl Sampler { | ||
| 146 | 147 | system, |
| 147 | 148 | pid: Pid::from_u32(std::process::id()), |
| 148 | 149 | cpu_model, |
| 150 | + primed: false, | |
| 149 | 151 | gpu: GpuSampler::default(), |
| 150 | 152 | #[cfg(target_os = "linux")] |
| 151 | 153 | threads: threads::Sampler::default(), |
| @@ -161,6 +163,9 @@ impl Sampler { | ||
| 161 | 163 | true, |
| 162 | 164 | ProcessRefreshKind::nothing().with_cpu().with_memory(), |
| 163 | 165 | ); |
| 166 | + if !std::mem::replace(&mut self.primed, true) { | |
| 167 | + return None; | |
| 168 | + } | |
| 164 | 169 | let process = self.system.process(self.pid)?; |
| 165 | 170 | let mb = |bytes: u64| (bytes / (1024 * 1024)) as u32; |
| 166 | 171 | let total = self.system.total_memory(); |