diff options
Diffstat (limited to 'vendor/github.com/hodgesds/perf-utils/events.go')
-rw-r--r-- | vendor/github.com/hodgesds/perf-utils/events.go | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/vendor/github.com/hodgesds/perf-utils/events.go b/vendor/github.com/hodgesds/perf-utils/events.go index 851be8c..33d2492 100644 --- a/vendor/github.com/hodgesds/perf-utils/events.go +++ b/vendor/github.com/hodgesds/perf-utils/events.go | |||
@@ -16,9 +16,11 @@ const ( | |||
16 | PERF_TYPE_TRACEPOINT = 2 | 16 | PERF_TYPE_TRACEPOINT = 2 |
17 | ) | 17 | ) |
18 | 18 | ||
19 | // AvailableEvents returns the list of available events. | 19 | // AvailableEvents returns a mapping of available subsystems and their |
20 | // corresponding list of available events. | ||
20 | func AvailableEvents() (map[string][]string, error) { | 21 | func AvailableEvents() (map[string][]string, error) { |
21 | events := map[string][]string{} | 22 | events := map[string][]string{} |
23 | // BUG(hodgesds): this should ideally check mounts for debugfs | ||
22 | rawEvents, err := fileToStrings(TracingDir + "/available_events") | 24 | rawEvents, err := fileToStrings(TracingDir + "/available_events") |
23 | // Events are colon delimited by type so parse the type and add sub | 25 | // Events are colon delimited by type so parse the type and add sub |
24 | // events appropriately. | 26 | // events appropriately. |
@@ -40,6 +42,26 @@ func AvailableEvents() (map[string][]string, error) { | |||
40 | return events, err | 42 | return events, err |
41 | } | 43 | } |
42 | 44 | ||
45 | // AvailableSubsystems returns a slice of available subsystems. | ||
46 | func AvailableSubsystems() ([]string, error) { | ||
47 | subsystems := []string{} | ||
48 | // BUG(hodgesds): this should ideally check mounts for debugfs | ||
49 | rawEvents, err := fileToStrings(TracingDir + "/available_events") | ||
50 | // Events are colon delimited by type so parse the type and add sub | ||
51 | // events appropriately. | ||
52 | if err != nil { | ||
53 | return subsystems, err | ||
54 | } | ||
55 | for _, rawEvent := range rawEvents { | ||
56 | splits := strings.Split(rawEvent, ":") | ||
57 | if len(splits) <= 1 { | ||
58 | continue | ||
59 | } | ||
60 | subsystems = append(subsystems, splits[0]) | ||
61 | } | ||
62 | return subsystems, nil | ||
63 | } | ||
64 | |||
43 | // AvailableTracers returns the list of available tracers. | 65 | // AvailableTracers returns the list of available tracers. |
44 | func AvailableTracers() ([]string, error) { | 66 | func AvailableTracers() ([]string, error) { |
45 | return fileToStrings(TracingDir + "/available_tracers") | 67 | return fileToStrings(TracingDir + "/available_tracers") |
@@ -51,21 +73,22 @@ func CurrentTracer() (string, error) { | |||
51 | return res[0], err | 73 | return res[0], err |
52 | } | 74 | } |
53 | 75 | ||
54 | // getTracepointConfig is used to get the configuration for a trace event. | 76 | // GetTracepointConfig is used to get the configuration for a trace event. |
55 | func getTracepointConfig(kind, event string) (uint64, error) { | 77 | func GetTracepointConfig(subsystem, event string) (uint64, error) { |
56 | res, err := fileToStrings(TracingDir + fmt.Sprintf("/events/%s/%s/id", kind, event)) | 78 | res, err := fileToStrings( |
79 | TracingDir + fmt.Sprintf("/events/%s/%s/id", subsystem, event)) | ||
57 | if err != nil { | 80 | if err != nil { |
58 | return 0, err | 81 | return 0, err |
59 | } | 82 | } |
60 | return strconv.ParseUint(res[0], 10, 64) | 83 | return strconv.ParseUint(res[0], 10, 64) |
61 | } | 84 | } |
62 | 85 | ||
63 | // ProfileTracepoint is used to profile a kernel tracepoint event. Events can | 86 | // ProfileTracepoint is used to profile a kernel tracepoint event for a |
64 | // be listed with `perf list` for Tracepoint Events or in the | 87 | // specific PID. Events can be listed with `perf list` for Tracepoint Events or |
65 | // /sys/kernel/debug/tracing/events directory with the kind being the directory | 88 | // in the /sys/kernel/debug/tracing/events directory with the kind being the |
66 | // and the event being the subdirectory. | 89 | // directory and the event being the subdirectory. |
67 | func ProfileTracepoint(kind, event string, pid, cpu int, opts ...int) (BPFProfiler, error) { | 90 | func ProfileTracepoint(subsystem, event string, pid, cpu int, opts ...int) (BPFProfiler, error) { |
68 | config, err := getTracepointConfig(kind, event) | 91 | config, err := GetTracepointConfig(subsystem, event) |
69 | if err != nil { | 92 | if err != nil { |
70 | return nil, err | 93 | return nil, err |
71 | } | 94 | } |
@@ -96,3 +119,19 @@ func ProfileTracepoint(kind, event string, pid, cpu int, opts ...int) (BPFProfil | |||
96 | fd: fd, | 119 | fd: fd, |
97 | }, nil | 120 | }, nil |
98 | } | 121 | } |
122 | |||
123 | // TracepointEventAttr is used to return an PerfEventAttr for a trace event. | ||
124 | func TracepointEventAttr(subsystem, event string) (*unix.PerfEventAttr, error) { | ||
125 | config, err := GetTracepointConfig(subsystem, event) | ||
126 | if err != nil { | ||
127 | return nil, err | ||
128 | } | ||
129 | return &unix.PerfEventAttr{ | ||
130 | Type: PERF_TYPE_TRACEPOINT, | ||
131 | Config: config, | ||
132 | Size: uint32(unsafe.Sizeof(unix.PerfEventAttr{})), | ||
133 | Bits: unix.PerfBitDisabled | unix.PerfBitExcludeHv, | ||
134 | Read_format: unix.PERF_FORMAT_TOTAL_TIME_RUNNING | unix.PERF_FORMAT_TOTAL_TIME_ENABLED, | ||
135 | Sample_type: PERF_SAMPLE_IDENTIFIER, | ||
136 | }, nil | ||
137 | } | ||