@@ -21,13 +21,16 @@ const (
2121// corresponding list of available events.
2222func AvailableEvents () (map [string ][]string , error ) {
2323 events := map [string ][]string {}
24- // BUG(hodgesds): this should ideally check mounts for debugfs
25- rawEvents , err := fileToStrings (TracingDir + "/available_events" )
26- // Events are colon delimited by type so parse the type and add sub
27- // events appropriately.
24+ tracefsMount , err := TraceFSMount ()
25+ if err != nil {
26+ return events , err
27+ }
28+ rawEvents , err := fileToStrings (tracefsMount + "/available_events" )
2829 if err != nil {
2930 return events , err
3031 }
32+ // Events are colon delimited by type so parse the type and add sub
33+ // events appropriately.
3134 for _ , rawEvent := range rawEvents {
3235 splits := strings .Split (rawEvent , ":" )
3336 if len (splits ) <= 1 {
@@ -46,13 +49,16 @@ func AvailableEvents() (map[string][]string, error) {
4649// AvailableSubsystems returns a slice of available subsystems.
4750func AvailableSubsystems () ([]string , error ) {
4851 subsystems := []string {}
49- // BUG(hodgesds): this should ideally check mounts for debugfs
50- rawEvents , err := fileToStrings (TracingDir + "/available_events" )
51- // Events are colon delimited by type so parse the type and add sub
52- // events appropriately.
52+ tracefsMount , err := TraceFSMount ()
53+ if err != nil {
54+ return subsystems , err
55+ }
56+ rawEvents , err := fileToStrings (tracefsMount + "/available_events" )
5357 if err != nil {
5458 return subsystems , err
5559 }
60+ // Events are colon delimited by type so parse the type and add sub
61+ // events appropriately.
5662 for _ , rawEvent := range rawEvents {
5763 splits := strings .Split (rawEvent , ":" )
5864 if len (splits ) <= 1 {
@@ -65,22 +71,34 @@ func AvailableSubsystems() ([]string, error) {
6571
6672// AvailableTracers returns the list of available tracers.
6773func AvailableTracers () ([]string , error ) {
68- return fileToStrings (TracingDir + "/available_tracers" )
74+ tracefsMount , err := TraceFSMount ()
75+ if err != nil {
76+ return []string {}, err
77+ }
78+ return fileToStrings (tracefsMount + "/available_tracers" )
6979}
7080
7181// CurrentTracer returns the current tracer.
7282func CurrentTracer () (string , error ) {
73- res , err := fileToStrings (TracingDir + "/current_tracer" )
83+ tracefsMount , err := TraceFSMount ()
84+ if err != nil {
85+ return "" , err
86+ }
87+ res , err := fileToStrings (tracefsMount + "/current_tracer" )
7488 return res [0 ], err
7589}
7690
7791// GetTracepointConfig is used to get the configuration for a trace event.
7892func GetTracepointConfig (subsystem , event string ) (uint64 , error ) {
79- res , err := fileToStrings (
80- TracingDir + fmt .Sprintf ("/events/%s/%s/id" , subsystem , event ))
93+ tracefsMount , err := TraceFSMount ()
8194 if err != nil {
8295 return 0 , err
8396 }
97+ res , err := fileToStrings (
98+ tracefsMount + fmt .Sprintf ("/events/%s/%s/id" , subsystem , event ))
99+ if err != nil {
100+ return 0 , fmt .Errorf ("Failed to get tracepoint config for %s:%s: %q" , subsystem , event , err )
101+ }
84102 return strconv .ParseUint (res [0 ], 10 , 64 )
85103}
86104
@@ -113,7 +131,7 @@ func ProfileTracepoint(subsystem, event string, pid, cpu int, opts ...int) (BPFP
113131 eventOps ,
114132 )
115133 if err != nil {
116- return nil , err
134+ return nil , fmt . Errorf ( "Failed to open perf event for PerfEventAttr %+v: %q" , eventAttr , err )
117135 }
118136
119137 return & profiler {
0 commit comments