-
Notifications
You must be signed in to change notification settings - Fork 3
/
probes.go
67 lines (53 loc) · 1.59 KB
/
probes.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package skbtrace
import (
"errors"
"strings"
)
func newProbeBuildError(probeName string, err error) *errorImpl {
return newErrorf(ErrLevelProbe, probeName, err, "error building probe")
}
type Probe struct {
// Name of the probe in BPFTrace format of "provider:name"
Name string
// ReturnName contains explicit name that denotes end of the context probe execution
ReturnName string
// List of aliases which could be used in command line
Aliases []string
// Context contains initial mapping untyped variable names to probe raw arguments
Args map[string]string
// Help string dumped by probes command
Help string
}
func (b *Builder) addProbeBlock(
prog *Program, probeName string, isReturn bool, filters [][]*ProcessedFilter,
) (*Block, *Block, error) {
if probeName == "" {
return nil, nil, newCommonError(ErrLevelProbe, "", ErrMsgNotSpecified)
}
probe, ok := b.probeMap[probeName]
if !ok {
return nil, nil, newCommonError(ErrLevelProbe, probeName, ErrMsgNotFound)
}
name := probe.Name
if isReturn {
retName, err := probe.ReturnProbe()
if err != nil {
return nil, nil, err
}
name = retName
}
probeBlock := prog.AddProbeBlock(name, probe)
block, err := b.wrapFilters(probeBlock, filters)
return probeBlock, block, err
}
func (p *Probe) ReturnProbe() (string, error) {
if p.ReturnName != "" {
return p.ReturnName, nil
}
if strings.HasPrefix(p.Name, "k:") {
return "kr:" + p.Name[2:], nil
} else if strings.HasPrefix(p.Name, "kprobe:") {
return "kretprobe:" + p.Name[7:], nil
}
return "", newProbeBuildError(p.Name, errors.New("can't deduce return probe name"))
}