Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bpf/php.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ int BPF_USDT(compile_file_return, char *arg0, char *arg1)
{
u64 ts = bpf_ktime_get_ns();

debug_printk("compile file return: %s, %s\n", arg0, arg1);
char comm[16];
bpf_get_current_comm(&comm, sizeof(comm));
debug_printk("compile file return: comm=%s, %s, %s\n", comm, arg0, arg1);


bpf_probe_read_user_str(&filename, sizeof(filename), arg0);
Expand Down
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
_ "embed"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/http"
Expand Down Expand Up @@ -534,16 +535,31 @@ func displayMapContents(ctx context.Context, bpfMap *bpf.BPFMap) {
fmt.Printf("%-60s %s\n", "Filename", "Count")
fmt.Println("-----------------------------------------------------------")

// Cap iteration well below the BPF map's max_entries (see bpf/php.bpf.c).
// Under heavy concurrent inserts, bpf_map_get_next_key on an LRU hash
// can keep returning newly inserted keys and never terminate.
// Remaining entries are picked up on the next tick.
const maxIter = 10000

iter := bpfMap.Iterator()
count := 0
iterated := 0
var keysToDelete [][]byte

for iter.Next() {
if iterated >= maxIter {
slog.Warn("Reached BPF map iteration cap; remaining entries will be read on next tick", "cap", maxIter)
break
}
iterated++
keyBytes := iter.Key()

v, err := bpfMap.GetValue(unsafe.Pointer(&keyBytes[0]))
if err != nil {
slog.Warn("Failed to get value from BPF map", "error", err)
// ENOENT is expected under LRU eviction between Next() and GetValue().
if !errors.Is(err, syscall.ENOENT) {
slog.Warn("Failed to get value from BPF map", "error", err)
}
continue
}

Expand Down
Loading