@@ -6,7 +6,6 @@ package tracer // import "go.opentelemetry.io/ebpf-profiler/tracer"
66
77import (
88 "bufio"
9- "bytes"
109 "context"
1110 "errors"
1211 "fmt"
@@ -178,15 +177,6 @@ type progLoaderHelper struct {
178177 noTailCallTarget bool
179178}
180179
181- // Convert a C-string to Go string.
182- func goString (cstr []byte ) string {
183- index := bytes .IndexByte (cstr , byte (0 ))
184- if index < 0 {
185- index = len (cstr )
186- }
187- return strings .Clone (unsafe .String (unsafe .SliceData (cstr ), index ))
188- }
189-
190180// schedProcessFreeHookName returns the name of the tracepoint hook to use.
191181// This function requires that only one of (schedProcessFreeV1, schedProcessFreeV2)
192182// be present in progNames.
@@ -916,7 +906,7 @@ func (t *Tracer) loadBpfTrace(raw []byte, cpu int) *host.Trace {
916906 pid := libpf .PID (ptr .Pid )
917907 procMeta := t .processManager .MetaForPID (pid )
918908 trace := & host.Trace {
919- Comm : goString (ptr .Comm [:]),
909+ Comm : util . GoString (ptr .Comm [:]),
920910 ExecutablePath : procMeta .Executable ,
921911 ContainerID : procMeta .ContainerID ,
922912 ProcessName : procMeta .Name ,
@@ -947,8 +937,8 @@ func (t *Tracer) loadBpfTrace(raw []byte, cpu int) *host.Trace {
947937 trace .CustomLabels = make (map [string ]string , clLen )
948938 for i := 0 ; i < clLen ; i ++ {
949939 lbl := ptr .Custom_labels .Labels [i ]
950- key := goString (lbl .Key [:])
951- val := goString (lbl .Val [:])
940+ key := util . GoString (lbl .Key [:])
941+ val := util . GoString (lbl .Val [:])
952942 trace .CustomLabels [key ] = val
953943 }
954944 }
0 commit comments