Skip to content

Commit

Permalink
bpflbr: Output verbose log
Browse files Browse the repository at this point in the history
Signed-off-by: Leon Hwang <[email protected]>
  • Loading branch information
Asphaltt committed Dec 5, 2024
1 parent 711d415 commit 3aaba01
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/bpflbr/bpf_tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package bpflbr

import (
"fmt"
"log"
"sync"

"github.com/cilium/ebpf"
Expand Down Expand Up @@ -96,6 +97,10 @@ func (t *bpfTracing) traceProg(spec *ebpf.CollectionSpec, reusedMaps map[string]
return fmt.Errorf("failed to attach tracing: %w", err)
}

if verbose {
log.Printf("Tracing %s of prog %v", info.funcName, info.prog)
}

t.llock.Lock()
t.progs = append(t.progs, cloned)
t.links = append(t.links, l)
Expand Down
3 changes: 3 additions & 0 deletions internal/bpflbr/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
progFlagDescriptorName = "name"
)

var verbose bool

type ProgFlag struct {
progID uint32
pinned string
Expand Down Expand Up @@ -109,6 +111,7 @@ func ParseFlags() (*Flags, error) {
f.StringSliceVarP(&flags.progs, "prog", "p", nil, "bpf prog info for bpflbr in format PROG[,PROG,..], PROG: PROGID[:<prog function name>], PROGID: <prog ID> or 'i/id:<prog ID>' or 'p/pinned:<pinned file>' or 't/tag:<prog tag>' or 'n/name:<prog full name>'; all bpf progs will be traced by default")
f.StringVarP(&flags.outputFile, "output", "o", "", "output file for the result, default is stdout")
f.BoolVar(&flags.dumpProg, "dump-jited", false, "dump native insn info of bpf prog, the one bpf prog must be provided by --prog (its function name will be ignored)")
f.BoolVarP(&verbose, "verbose", "v", false, "output verbose log")

return &flags, f.Parse(os.Args)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/bpflbr/lbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Run(reader *ringbuf.Reader, progs *bpfProgs, addr2line *Addr2Line, ksyms *K
continue
}

foundEntries := false
foundEntries := verbose
nrEntries := event.NrBytes / int64(8*3)
lbrEntries := make([]branchEntry, 0, nrEntries)
for i := 0; i < int(nrEntries); i++ {
Expand Down

0 comments on commit 3aaba01

Please sign in to comment.