New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kretprobes: set maxactive #39

Merged
merged 4 commits into from Apr 5, 2017
Jump to file or symbol
Failed to load files and symbols.
+18 −7
Diff settings

Always

Just for now

Next

kretprobes: set maxactive

We are discussing adding a way to specify the maxactive field of a
kretprobe in the kernel:
iovisor/bcc#1072 (comment)
  • Loading branch information...
alban committed Mar 27, 2017
commit 5f20e2781bbe279f4d8f9f425799d836786d9077
Copy path View file
@@ -117,17 +117,21 @@ func NewModuleFromReader(fileReader io.ReaderAt) *Module {
}
}
func (b *Module) EnableKprobe(secName string) error {
func (b *Module) EnableKprobe(secName string, maxactive int) error {
var probeType, funcName string
isKretprobe := strings.HasPrefix(secName, "kretprobe/")
probe, ok := b.probes[secName]
if !ok {
return fmt.Errorf("no such kprobe %q", secName)
}
progFd := probe.fd
var maxactiveStr string
if isKretprobe {
probeType = "r"
funcName = strings.TrimPrefix(secName, "kretprobe/")
if maxactive > 0 {
maxactiveStr = fmt.Sprintf("%d", maxactive)
}
} else {
probeType = "p"
funcName = strings.TrimPrefix(secName, "kprobe/")
@@ -141,10 +145,17 @@ func (b *Module) EnableKprobe(secName string) error {
}
defer f.Close()
cmd := fmt.Sprintf("%s:%s %s\n", probeType, eventName, funcName)
cmd := fmt.Sprintf("%s%d:%s %s\n", probeType, maxactiveStr, eventName, funcName)
_, err = f.WriteString(cmd)
if err != nil {
return fmt.Errorf("cannot write %q to kprobe_events: %v\n", cmd, err)
// fallback without maxactive for kretprobes
if isKretprobe {
cmd = fmt.Sprintf("%s:%s %s\n", probeType, eventName, funcName)
_, err = f.WriteString(cmd)
}
if err != nil {
return fmt.Errorf("cannot write %q to kprobe_events: %v\n", cmd, err)
}
}
kprobeIdFile := fmt.Sprintf("/sys/kernel/debug/tracing/events/kprobes/%s/id", eventName)
@@ -186,10 +197,10 @@ func (b *Module) IterKprobes() <-chan *Kprobe {
return ch
}
func (b *Module) EnableKprobes() error {
func (b *Module) EnableKprobes(maxactive int) error {
var err error
for _, kprobe := range b.probes {
err = b.EnableKprobe(kprobe.Name)
err = b.EnableKprobe(kprobe.Name, maxactive)
if err != nil {
return err
}
Copy path View file
@@ -18,15 +18,15 @@ func NewModuleFromReader(fileReader io.ReaderAt) *Module {
return nil
}
func (b *Module) EnableKprobe(secName string) error {
func (b *Module) EnableKprobe(secName string, maxactive int) error {
return fmt.Errorf("not supported")
}
func (b *Module) IterKprobes() <-chan *Kprobe {
return nil
}
func (b *Module) EnableKprobes() error {
func (b *Module) EnableKprobes(maxactive int) error {
return fmt.Errorf("not supported")
}
ProTip! Use n and p to navigate between commits in a pull request.