ebpfbench

package module
v0.0.0-...-0df55b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2023 License: BSD-3-Clause Imports: 12 Imported by: 1

README

ebpfbench

profile eBPF programs from Go. Requires Linux kernel 5.1 or greater.

Examples

cd examples/bench
go run -exec sudo ./bench

Usage

ebpfbench augments the standard testing.B object.

func BenchmarkExample(b *testing.B) {
    eb := ebpfbench.NewEBPFBenchmark(b)
    defer eb.Close()

    // setup eBPF programs using cilium/ebpf, gobpf, or other libraries.

    fd := prog.FD()
    eb.ProfileProgram(fd, "")
    eb.Run(func(b *testing.B) {
        // exercise programs here
    })
}

The results per program will be output in the standard go benchmark format.

goos: linux
goarch: amd64
pkg: github.com/DataDog/bench-example
BenchmarkExample/eBPF-4         	                   66741	     20344 ns/op
BenchmarkExample/eBPF/kprobe/sys_bind           	       1	       568 ns/op
BenchmarkExample/eBPF/kprobe/sys_socket         	       3	      1110 ns/op
BenchmarkExample/eBPF/kprobe/tcp_cleanup_rbuf   	  266952	       295 ns/op

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportsStatsSyscall = supportsBpfEnableStats()()

Functions

func KprobeAttach

func KprobeAttach(retprobe bool, name string, progFd int) (int, error)

func KprobeDetach

func KprobeDetach(efd int) error

func NewWrappedFD

func NewWrappedFD(raw int) *wrappedFD

Types

type BpfProgramStatsEvent

type BpfProgramStatsEvent struct {
	BpfProgramStats   map[int]*bpfProgramStats
	TimestampInSecond int64
}

type EBPFBenchmark

type EBPFBenchmark struct {
	// contains filtered or unexported fields
}

func NewEBPFBenchmark

func NewEBPFBenchmark(b *testing.B) *EBPFBenchmark

func NewEBPFBenchmarkWithBpfStatsEnabledFile

func NewEBPFBenchmarkWithBpfStatsEnabledFile(b *testing.B, bpfStatsEnabledFile string) *EBPFBenchmark

create new ebpf benchmark with sysctl proc file

func (*EBPFBenchmark) Close

func (e *EBPFBenchmark) Close()

func (*EBPFBenchmark) ProfileProgram

func (e *EBPFBenchmark) ProfileProgram(fd int, name string)

func (*EBPFBenchmark) Run

func (e *EBPFBenchmark) Run(fn func(*testing.B))

func (*EBPFBenchmark) Start

func (e *EBPFBenchmark) Start(ctx context.Context) (<-chan *BpfProgramStatsEvent, <-chan error, error)

Directories

Path Synopsis
examples module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL