Skip to content

Commit

Permalink
Merge pull request #3346 from Rouzip/fix-cgo
Browse files Browse the repository at this point in the history
  • Loading branch information
iwankgb authored Jul 18, 2023
2 parents 0f004a2 + 4852908 commit 248756c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions perf/collector_libpfm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ type group struct {

var (
isLibpfmInitialized = false
libpmfMutex = sync.Mutex{}
libpfmMutex = sync.Mutex{}
)

const (
groupLeaderFileDescriptor = -1
)

func init() {
libpmfMutex.Lock()
defer libpmfMutex.Unlock()
libpfmMutex.Lock()
defer libpfmMutex.Unlock()
pErr := C.pfm_initialize()
if pErr != C.PFM_SUCCESS {
klog.Errorf("unable to initialize libpfm: %d", int(pErr))
Expand Down Expand Up @@ -266,10 +266,12 @@ func readPerfEventAttr(name string, pfmGetOsEventEncoding func(string, unsafe.Po
func pfmGetOsEventEncoding(name string, perfEventAttrMemory unsafe.Pointer) error {
event := pfmPerfEncodeArgT{}
fstr := C.CString("")
defer C.free(unsafe.Pointer(fstr))
event.fstr = unsafe.Pointer(fstr)
event.attr = perfEventAttrMemory
event.size = C.ulong(unsafe.Sizeof(event))
cSafeName := C.CString(name)
defer C.free(unsafe.Pointer(cSafeName))
pErr := C.pfm_get_os_event_encoding(cSafeName, C.PFM_PLM0|C.PFM_PLM3, C.PFM_OS_PERF_EVENT, unsafe.Pointer(&event))
if pErr != C.PFM_SUCCESS {
return fmt.Errorf("unable to transform event name %s to perf_event_attr: %d", name, int(pErr))
Expand Down Expand Up @@ -409,8 +411,8 @@ func (c *collector) Destroy() {

// Finalize terminates libpfm4 to free resources.
func Finalize() {
libpmfMutex.Lock()
defer libpmfMutex.Unlock()
libpfmMutex.Lock()
defer libpfmMutex.Unlock()

klog.V(1).Info("Attempting to terminate libpfm4")
if !isLibpfmInitialized {
Expand Down

0 comments on commit 248756c

Please sign in to comment.