MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / process_batch

Method process_batch

crates/memtrack/src/ebpf/attach_worker.rs:187–232  ·  view source on GitHub ↗

Stop every producing pid (fixpoint, draining until no new pid appears), then classify + attach for each unique `(dev, ino)`. `holds` release every stopped pid exactly once when this returns, including the error path.

(
        &self,
        batch: &mut Vec<AttachRequest>,
        known: &mut HashSet<(u64, u64)>,
    )

Source from the content-addressed store, hash-verified

185 /// then classify + attach for each unique `(dev, ino)`. `holds` release
186 /// every stopped pid exactly once when this returns, including the error path.
187 fn process_batch(
188 &self,
189 batch: &mut Vec<AttachRequest>,
190 known: &mut HashSet<(u64, u64)>,
191 ) -> Result<()> {
192 let mut holds: Vec<AttachHold> = Vec::new();
193 let mut stopped: HashSet<u32> = HashSet::new();
194
195 loop {
196 let new_pids: HashSet<u32> = batch
197 .iter()
198 .map(|r| r.pid)
199 .filter(|pid| !stopped.contains(pid))
200 .collect();
201
202 if new_pids.is_empty() {
203 break;
204 }
205
206 for pid in new_pids {
207 stopped.insert(pid);
208 holds.push(AttachHold::new(self.stops.clone(), pid));
209 wait_all_stopped(pid, STOP_DEADLINE)?;
210 debug!("Stopped pid {pid} for attach");
211 }
212
213 // Every producer is stopped, so a synchronous drain is complete.
214 self.poller.drain()?;
215 batch.extend(self.rx.try_iter().flatten());
216 }
217
218 let mut seen: HashSet<(u64, u64)> = HashSet::new();
219 for req in batch.iter() {
220 let key = (req.dev, req.ino);
221 if !seen.insert(key) || known.contains(&key) {
222 continue;
223 }
224
225 if self.handle_request(req)? {
226 self.bpf.lock().insert_known_inode(req.dev, req.ino)?;
227 known.insert(key);
228 }
229 }
230
231 Ok(())
232 }
233
234 /// Returns `Ok(true)` when the inode should be marked known (attached, or
235 /// definitively not an allocator), `Ok(false)` when the process exited

Callers 1

runMethod · 0.80

Calls 5

wait_all_stoppedFunction · 0.85
handle_requestMethod · 0.80
insert_known_inodeMethod · 0.80
is_emptyMethod · 0.45
drainMethod · 0.45

Tested by

no test coverage detected