From 6d0ca913080494e381c5092cf10ac7fa89212868 Mon Sep 17 00:00:00 2001 From: Leon Hwang Date: Fri, 6 Dec 2024 21:26:16 +0800 Subject: [PATCH] bpflbr: Reduce output when not verbose 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 --- internal/bpflbr/lbr.go | 23 +++++++++++++++-------- internal/bpflbr/lbr_stack.go | 14 +++++++++----- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/internal/bpflbr/lbr.go b/internal/bpflbr/lbr.go index 029bedb..1f2f2c6 100644 --- a/internal/bpflbr/lbr.go +++ b/internal/bpflbr/lbr.go @@ -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) { @@ -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 { @@ -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) } diff --git a/internal/bpflbr/lbr_stack.go b/internal/bpflbr/lbr_stack.go index 80712c8..aaa5145 100644 --- a/internal/bpflbr/lbr_stack.go +++ b/internal/bpflbr/lbr_stack.go @@ -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) }