@@ -11,7 +11,7 @@ import (
1111 "k8s.io/klog/v2"
1212)
1313
14- func (t * Tracer ) AttachNodejsProbes (pid uint32 , exe string ) []link. Link {
14+ func (t * Tracer ) AttachNodejsProbes (pid uint32 , exe string ) * UprobeKey {
1515 log := func (libPath , msg string , err error ) {
1616 if err != nil {
1717 for _ , s := range []string {"no such file or directory" , "no such process" , "permission denied" } {
@@ -26,17 +26,23 @@ func (t *Tracer) AttachNodejsProbes(pid uint32, exe string) []link.Link {
2626 }
2727
2828 for _ , libPath := range append (getLibuv (pid ), proc .Path (pid , "root" , exe )) {
29- if links , err := t .attachNodejsUprobes (libPath , pid ); err == nil {
29+ key , ok := t .AcquireGlobalUprobe (libPath , func () []link.Link {
30+ links , err := t .attachNodejsUprobes (libPath )
31+ if err != nil {
32+ log (libPath , "failed to attach nodejs uprobes" , err )
33+ return nil
34+ }
3035 log (libPath , "nodejs uprobes attached" , nil )
3136 return links
32- } else {
33- log (libPath , "failed to attach nodejs uprobes" , err )
37+ })
38+ if ok {
39+ return & key
3440 }
3541 }
3642 return nil
3743}
3844
39- func (t * Tracer ) attachNodejsUprobes (libPath string , pid uint32 ) ([]link.Link , error ) {
45+ func (t * Tracer ) attachNodejsUprobes (libPath string ) ([]link.Link , error ) {
4046 exe , err := link .OpenExecutable (libPath )
4147 if err != nil {
4248 return nil , err
@@ -51,14 +57,14 @@ func (t *Tracer) attachNodejsUprobes(libPath string, pid uint32) ([]link.Link, e
5157 if err != nil {
5258 return nil , err
5359 }
54- l , err := s .AttachUprobe (exe , t .uprobes ["uv_io_poll_enter" ], pid )
60+ l , err := s .AttachUprobe (exe , t .uprobes ["uv_io_poll_enter" ], 0 )
5561 if err != nil {
5662 return nil , err
5763 }
5864 var links []link.Link
5965 links = append (links , l )
6066
61- ls , err := s .AttachUretprobes (exe , t .uprobes ["uv_io_poll_exit" ], pid )
67+ ls , err := s .AttachUretprobes (exe , t .uprobes ["uv_io_poll_exit" ], 0 )
6268 links = append (links , ls ... )
6369 if err != nil {
6470 for _ , l := range links {
@@ -72,12 +78,12 @@ func (t *Tracer) attachNodejsUprobes(libPath string, pid uint32) ([]link.Link, e
7278 if err != nil {
7379 break
7480 }
75- l , err = s .AttachUprobe (exe , t .uprobes ["uv_io_cb_enter" ], pid )
81+ l , err = s .AttachUprobe (exe , t .uprobes ["uv_io_cb_enter" ], 0 )
7682 if err != nil {
7783 break
7884 }
7985 links = append (links , l )
80- ls , err = s .AttachUretprobes (exe , t .uprobes ["uv_io_cb_exit" ], pid )
86+ ls , err = s .AttachUretprobes (exe , t .uprobes ["uv_io_cb_exit" ], 0 )
8187 links = append (links , ls ... )
8288 if err != nil {
8389 break
0 commit comments