Skip to content

Commit

Permalink
bpflbr: Reduce output when not verbose
Browse files Browse the repository at this point in the history
Adjust some behaviours aboud verbose:

1. Skip 14 LBR entries when not verbose.
2. Skip 3 stack entries when verbose.
3. Do not show addrs of LBR entries when not verbose.
4. Show addrs of stack entries when verbose.

Signed-off-by: Leon Hwang <[email protected]>
  • Loading branch information
Asphaltt committed Dec 6, 2024
1 parent 9fa8b11 commit 6d0ca91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
23 changes: 15 additions & 8 deletions internal/bpflbr/lbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ func getLbrStack(event *Event, progs *bpfProgs, addr2line *Addr2Line, ksyms *Kal
nrEntries := event.NrBytes / int64(8*3)
entries := event.Entries[:nrEntries]
if !verbose {
// Skip the first 14 entries as they are entries for fexit_fn
// and bpf_get_branch_snapshot helper.
const nrSkip = 14

entries = entries[nrSkip:]

if isProg {
for i := range entries {
if progInfo.contains(entries[i].From) || progInfo.contains(entries[i].To) {
Expand All @@ -180,12 +186,6 @@ func getLbrStack(event *Event, progs *bpfProgs, addr2line *Addr2Line, ksyms *Kal
break
}
}
} else {
// Skip the first 14 entries as they are entries for fexit_fn
// and bpf_get_branch_snapshot helper.
const nrSkip = 14

entries = entries[nrSkip:]
}

if len(entries) == 0 {
Expand Down Expand Up @@ -222,13 +222,20 @@ func getFuncStack(event *Event, progs *bpfProgs, addr2line *Addr2Line, ksym *Kal
}
_ = funcStacks.Delete(id)

ips := data.IPs[3:] // Skip the first 3 entries as they are entries for fentry/fexit and its trampoline.
ips := data.IPs[:]
if !verbose {
ips = ips[3:] // Skip the first 3 entries as they are entries for fentry/fexit and its trampoline.
}
for _, ip := range ips {
if ip != 0 {
li := getLineInfo(uintptr(ip), progs, addr2line, ksym)

var sb strings.Builder
fmt.Fprintf(&sb, " %-50s", fmt.Sprintf("%s+%#x", li.funcName, li.offset))
fmt.Fprint(&sb, " ")
if verbose {
fmt.Fprintf(&sb, "0x%x:", ip)
}
fmt.Fprintf(&sb, "%-50s", fmt.Sprintf("%s+%#x", li.funcName, li.offset))
if li.fileName != "" {
fmt.Fprintf(&sb, "\t; %s:%d", li.fileName, li.fileLine)
}
Expand Down
14 changes: 9 additions & 5 deletions internal/bpflbr/lbr_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ type branchEndpoint struct {
offset uintptr
endpointName string // ${funcName}+${offset}

fileName string
fileLine uint32
lineInfo string // (${fileName}:${fileLine})
isProg bool
fileName string
fileLine uint32
lineInfo string // (${fileName}:${fileLine})
isProg bool
fromVmlinux bool
}

func (b *branchEndpoint) updateInfo() {
b.endpointName = fmt.Sprintf("%#x:%s+%#x", b.addr, b.funcName, b.offset)
if verbose {
b.endpointName = fmt.Sprintf("%#x:%s+%#x", b.addr, b.funcName, b.offset)
} else {
b.endpointName = fmt.Sprintf("%s+%#x", b.funcName, b.offset)
}
if b.fileName != "" {
b.lineInfo = fmt.Sprintf("(%s:%d)", b.fileName, b.fileLine)
}
Expand Down

0 comments on commit 6d0ca91

Please sign in to comment.