in netbench-collector/src/bpftrace.rs [48:147]
fn push(&mut self, line: &str) {
let line = line.trim();
if let Some(id) = self.pending_profile {
if let Some(bucket) = parse_hist_line(line) {
self.profiles.entry(id).or_default().buckets.push(bucket);
return;
} else {
self.pending_profile = None;
}
}
if line.is_empty() {
return;
}
if line == "===" {
self.dump();
return;
}
if let Some(count) = line.strip_prefix("@: ") {
self.count = count.parse().unwrap();
return;
}
if let Some(trace) = line.strip_prefix("@P[") {
let trace = trace.trim_end_matches("]:");
if let Ok(trace) = trace.parse() {
self.pending_profile = Some(trace);
return;
}
}
if let Some(line) = line.strip_prefix("@p[") {
let (id, line) = line.split_once("]: ").unwrap();
let id = id.parse().unwrap();
let stat = BpfParse::parse(line).unwrap();
self.profiles.entry(id).or_default().stat = stat;
return;
}
macro_rules! stat {
($prefix:literal, $name:ident) => {
if let Some(value) = line.strip_prefix(concat!("@", $prefix, ": ")) {
self.current.$name = BpfParse::parse(value).unwrap();
return;
}
};
}
stat!("c", cycles);
stat!("i", instructions);
stat!("b", branches);
stat!("C", context_switches);
stat!("a", allocs);
stat!("R", reallocs);
stat!("d", deallocs);
stat!("S", syscalls);
stat!("O", connections);
stat!("A", accept);
stat!("h", connect_time);
macro_rules! try_map {
($prefix:literal, $on_value:expr) => {
if let Some(line) = line.strip_prefix(concat!("@", $prefix, "[")) {
let mut on_value = $on_value;
let (id, line) = line.split_once("]: ").unwrap();
let (conn, id) = id.split_once(", ").unwrap();
let connection_id = conn.parse().unwrap();
let id = id.parse().unwrap();
let id = StreamId { connection_id, id };
let value = BpfParse::parse(line).unwrap();
on_value(id, value);
return;
}
};
}
macro_rules! stream_stat {
($prefix:literal, $name:ident) => {
try_map!($prefix, |id, value| self.$name.insert(id, value));
};
}
stream_stat!("s", send);
stream_stat!("r", receive);
if let Some(pid) = line.strip_prefix("cpid=") {
let pid = pid.parse().unwrap();
self.proc = Some(Proc::new(pid));
// dump the initial numbers
self.dump();
return;
}
eprintln!("> {line}");
}