Read the entry at the given ring-buffer slot (0..255).
(&self, slot: usize)
| 214 | |
| 215 | /// Read the entry at the given ring-buffer slot (0..255). |
| 216 | pub fn entry(&self, slot: usize) -> Option<MonitorEntry> { |
| 217 | if slot >= RING_CAPACITY { |
| 218 | return None; |
| 219 | } |
| 220 | let off = HEADER_SIZE + slot * ENTRY_SIZE; |
| 221 | if self.mmap.len() < off + ENTRY_SIZE { |
| 222 | return None; |
| 223 | } |
| 224 | |
| 225 | let prefix = read_str(&self.mmap, off + EOFF_PREFIX); |
| 226 | let project = read_str(&self.mmap, off + EOFF_PROJECT); |
| 227 | let tool_name = read_str(&self.mmap, off + EOFF_TOOL); |
| 228 | |
| 229 | let delta = u64::from_le_bytes( |
| 230 | self.mmap[off + EOFF_DELTA..off + EOFF_DELTA + 8] |
| 231 | .try_into() |
| 232 | .unwrap_or([0; 8]), |
| 233 | ); |
| 234 | let before = u64::from_le_bytes( |
| 235 | self.mmap[off + EOFF_BEFORE..off + EOFF_BEFORE + 8] |
| 236 | .try_into() |
| 237 | .unwrap_or([0; 8]), |
| 238 | ); |
| 239 | let timestamp = u64::from_le_bytes( |
| 240 | self.mmap[off + EOFF_TIMESTAMP..off + EOFF_TIMESTAMP + 8] |
| 241 | .try_into() |
| 242 | .unwrap_or([0; 8]), |
| 243 | ); |
| 244 | |
| 245 | Some(MonitorEntry { |
| 246 | prefix, |
| 247 | project, |
| 248 | tool_name, |
| 249 | delta, |
| 250 | before, |
| 251 | timestamp, |
| 252 | }) |
| 253 | } |
| 254 | |
| 255 | /// Re-read the mmap to pick up new writes. |
| 256 | pub fn refresh(&mut self) -> std::io::Result<()> { |