-
Notifications
You must be signed in to change notification settings - Fork 10
/
tracepoint.go
38 lines (34 loc) · 1.16 KB
/
tracepoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package manager
import (
"fmt"
"strings"
)
// attachTracepoint - Attaches the probe to its tracepoint
func (p *Probe) attachTracepoint() error {
// Parse section
if len(p.TracepointCategory) == 0 || len(p.TracepointName) == 0 {
traceGroup := strings.SplitN(p.programSpec.SectionName, "/", 3)
if len(traceGroup) != 3 {
return fmt.Errorf("expected SEC(\"tracepoint/[category]/[name]\") got %s: %w", p.programSpec.SectionName, ErrSectionFormat)
}
p.TracepointCategory = traceGroup[1]
p.TracepointName = traceGroup[2]
}
// Get the ID of the tracepoint to activate
tracepointID, err := GetTracepointID(p.TracepointCategory, p.TracepointName)
if err != nil {
return fmt.Errorf("couldn't activate tracepoint %s: %w", p.ProbeIdentificationPair, err)
}
// Hook the eBPF program to the tracepoint
fd, err := perfEventOpenTracingEvent(tracepointID, -1)
if err != nil {
return fmt.Errorf("couldn't enable tracepoint %s: %w", p.ProbeIdentificationPair, err)
}
pe := newPerfEventLink(fd)
if err := attachPerfEvent(pe, p.program); err != nil {
_ = pe.Close()
return fmt.Errorf("attach %s: %w", p.ProbeIdentificationPair, err)
}
p.progLink = pe
return nil
}