`clear(..)` supports a sync mode
Author: sugarraysamCreated Oct 28, 2024Updated Sep 4, 2026
Labelsgood first issue
I have a map, which I want to delete immediately. The context is I use two maps @curr and @prev, and I am always writing to @curr, and at set intervals, I take the data in @curr and put it in @prev. For this to happen, I want to be able to clear(@curr), but this creates issues as clear(...) only supports async deletion.
#!/usr/bin/bpftrace
// write some data to current
usdt:/some/probe {
@curr[arg1, arg2]++;
}
// at set interval we rotate buckets
interval:s:10 {
// we are force to iterate through @curr to delete every entry manually
// this is the only way to do sync deletion
for (kv : @curr) {
delete(@curr[$kv.0]);
}
<...>
}Source: bpftrace/bpftrace