Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

perf map fixes #37

Merged
merged 2 commits into from
May 10, 2017
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
28 changes: 18 additions & 10 deletions pkg/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TracerAsset() ([]byte, error) {
return buf, nil
}

func NewTracer(tcpEventCbV4 func(TcpV4), tcpEventCbV6 func(TcpV6)) (*Tracer, error) {
func NewTracer(tcpEventCbV4 func(TcpV4), tcpEventCbV6 func(TcpV6), lostCb func(lost uint64)) (*Tracer, error) {
buf, err := Asset("tcptracer-ebpf.o")
if err != nil {
return nil, fmt.Errorf("couldn't find asset: %s", err)
Expand All @@ -42,7 +42,9 @@ func NewTracer(tcpEventCbV4 func(TcpV4), tcpEventCbV6 func(TcpV6)) (*Tracer, err
return nil, fmt.Errorf("BPF not supported")
}

err = m.Load()
sectionParams := make(map[string]bpflib.SectionParams)
sectionParams["maps/tcp_event_ipv4"] = bpflib.SectionParams{PerfRingBufferPageCount: 256}
err = m.Load(sectionParams)
if err != nil {
return nil, err
}
Expand All @@ -54,13 +56,15 @@ func NewTracer(tcpEventCbV4 func(TcpV4), tcpEventCbV6 func(TcpV6)) (*Tracer, err

channelV4 := make(chan []byte)
channelV6 := make(chan []byte)
lostChanV4 := make(chan uint64)
lostChanV6 := make(chan uint64)

perfMapIPV4, err := initializeIPv4(m, channelV4)
perfMapIPV4, err := initializeIPv4(m, channelV4, lostChanV4)
if err != nil {
return nil, fmt.Errorf("failed to init perf map for IPv4 events: %s", err)
}

perfMapIPV6, err := initializeIPv6(m, channelV6)
perfMapIPV6, err := initializeIPv6(m, channelV6, lostChanV6)
if err != nil {
return nil, fmt.Errorf("failed to init perf map for IPv6 events: %s", err)
}
Expand All @@ -77,6 +81,8 @@ func NewTracer(tcpEventCbV4 func(TcpV4), tcpEventCbV6 func(TcpV6)) (*Tracer, err
return
case data := <-channelV4:
tcpEventCbV4(tcpV4ToGo(&data))
case lost := <-lostChanV4:
lostCb(lost)
}
}
}()
Expand All @@ -88,6 +94,8 @@ func NewTracer(tcpEventCbV4 func(TcpV4), tcpEventCbV6 func(TcpV6)) (*Tracer, err
return
case data := <-channelV6:
tcpEventCbV6(tcpV6ToGo(&data))
case lost := <-lostChanV6:
lostCb(lost)
}
}
}()
Expand All @@ -109,12 +117,12 @@ func (t *Tracer) Stop() {
t.perfMapIPV6.PollStop()
}

func initialize(module *bpflib.Module, eventMapName string, eventChan chan []byte) (*bpflib.PerfMap, error) {
func initialize(module *bpflib.Module, eventMapName string, eventChan chan []byte, lostChan chan uint64) (*bpflib.PerfMap, error) {
if err := guess(module); err != nil {
return nil, fmt.Errorf("error guessing offsets: %v", err)
}

pm, err := bpflib.InitPerfMap(module, eventMapName, eventChan)
pm, err := bpflib.InitPerfMap(module, eventMapName, eventChan, lostChan)
if err != nil {
return nil, fmt.Errorf("error initializing perf map for %q: %v", eventMapName, err)
}
Expand All @@ -123,10 +131,10 @@ func initialize(module *bpflib.Module, eventMapName string, eventChan chan []byt

}

func initializeIPv4(module *bpflib.Module, eventChan chan []byte) (*bpflib.PerfMap, error) {
return initialize(module, "tcp_event_ipv4", eventChan)
func initializeIPv4(module *bpflib.Module, eventChan chan []byte, lostChan chan uint64) (*bpflib.PerfMap, error) {
return initialize(module, "tcp_event_ipv4", eventChan, lostChan)
}

func initializeIPv6(module *bpflib.Module, eventChan chan []byte) (*bpflib.PerfMap, error) {
return initialize(module, "tcp_event_ipv6", eventChan)
func initializeIPv6(module *bpflib.Module, eventChan chan []byte, lostChan chan uint64) (*bpflib.PerfMap, error) {
return initialize(module, "tcp_event_ipv6", eventChan, lostChan)
}
2 changes: 1 addition & 1 deletion pkg/tracer/tracer_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TracerAsset() ([]byte, error) {
return nil, fmt.Errorf("not supported on non-Linux systems")
}

func NewTracer(tcpEventCbV4 func(TcpV4), tcpEventCbV6 func(TcpV6)) (*Tracer, error) {
func NewTracer(tcpEventCbV4 func(TcpV4), tcpEventCbV6 func(TcpV6), lostCb func(lost uint64)) (*Tracer, error) {
return nil, fmt.Errorf("not supported on non-Linux systems")
}

Expand Down
7 changes: 6 additions & 1 deletion tests/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ func tcpEventCbV6(e tracer.TcpV6) {
lastTimestampV6 = e.Timestamp
}

func lostCb(count uint64) {
fmt.Printf("ERROR: lost %d events!\n", count)
os.Exit(1)
}

func main() {
if len(os.Args) != 1 {
fmt.Fprintf(os.Stderr, "Usage: %s\n", os.Args[0])
os.Exit(1)
}

t, err := tracer.NewTracer(tcpEventCbV4, tcpEventCbV6)
t, err := tracer.NewTracer(tcpEventCbV4, tcpEventCbV6, lostCb)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
Expand Down
38 changes: 30 additions & 8 deletions vendor/github.com/iovisor/gobpf/elf/elf.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions vendor/github.com/iovisor/gobpf/elf/elf_unsupported.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 20 additions & 15 deletions vendor/github.com/iovisor/gobpf/elf/perf.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/iovisor/gobpf/elf/table.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"importpath": "github.com/iovisor/gobpf/elf",
"repository": "https://github.com/iovisor/gobpf",
"vcs": "git",
"revision": "65e4048660d6c4339ebae113ac55b1af6f01305d",
"revision": "23f7ee81c1cc244d16ddc8110c2ec8b8a09d0448",
"branch": "master",
"path": "/elf",
"notests": true
Expand Down