From 885842e1a3f2db7a99d0043bcccf58b7a5ae7bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E9=BE=99?= Date: Thu, 27 Mar 2025 14:37:47 +0800 Subject: [PATCH] fix python interface can not config bool var error --- include/pmu.h | 6 +++++- pmu/pfm/uncore.cpp | 18 +++--------------- python/modules/_libkperf/Pmu.py | 30 +++++++++++++++--------------- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/include/pmu.h b/include/pmu.h index f64f303..e4ecc77 100644 --- a/include/pmu.h +++ b/include/pmu.h @@ -421,7 +421,11 @@ enum PmuDeviceMetric { // Collect pcie tx latency. PMU_PCIE_TX_LAT, // Collect smmu address transaction. - PMU_SMMU_TRAN + PMU_SMMU_TRAN, + // Collect Ring2PA_ALL bandwidth. + PMU_RING2PA_ALL_BW, + // Collect PA2Ring_ALL bandwidth. + PMU_PA2RING_ALL_BW }; struct PmuDeviceAttr { diff --git a/pmu/pfm/uncore.cpp b/pmu/pfm/uncore.cpp index 75b4200..b7e160b 100644 --- a/pmu/pfm/uncore.cpp +++ b/pmu/pfm/uncore.cpp @@ -360,21 +360,9 @@ struct PmuEvt* GetUncoreRawEvent(const char* pmuName, int collectType) } auto fieldsValues = unCoreRawFieldsValues[(std::string)pmuName]; auto* pmuEvtPtr = new PmuEvt {0}; - if (fieldsValues.find("config") == fieldsValues.end()) { - pmuEvtPtr->config = 0; - } else { - pmuEvtPtr->config = fieldsValues.at("config"); - } - if (fieldsValues.find("config1") == fieldsValues.end()) { - pmuEvtPtr->config1 = 0; - } else { - pmuEvtPtr->config1 = fieldsValues.at("config1"); - } - if (fieldsValues.find("config2") == fieldsValues.end()) { - pmuEvtPtr->config2 = 0; - } else { - pmuEvtPtr->config2 = fieldsValues.at("config2"); - } + pmuEvtPtr->config = fieldsValues.find("config") == fieldsValues.end() ? 0 : fieldsValues.at("config"); + pmuEvtPtr->config1 = fieldsValues.find("config1") == fieldsValues.end() ? 0 : fieldsValues.at("config1"); + pmuEvtPtr->config2 = fieldsValues.find("config2") == fieldsValues.end() ? 0 : fieldsValues.at("config2"); pmuEvtPtr->name = pmuName; pmuEvtPtr->pmuType = UNCORE_RAW_TYPE; diff --git a/python/modules/_libkperf/Pmu.py b/python/modules/_libkperf/Pmu.py index f6f66bc..14c06b4 100644 --- a/python/modules/_libkperf/Pmu.py +++ b/python/modules/_libkperf/Pmu.py @@ -100,15 +100,15 @@ class CtypesPmuAttr(ctypes.Structure): ('numCpu', ctypes.c_uint), ('evtAttr', ctypes.POINTER(CtypesEvtAttr)), ('sampleRate', SampleRateUnion), - ('useFreq', ctypes.c_bool), - ('excludeUser', ctypes.c_bool), - ('excludeKernel', ctypes.c_bool), + ('useFreq', ctypes.c_uint, 1), + ('excludeUser', ctypes.c_uint, 1), + ('excludeKernel', ctypes.c_uint, 1), ('symbolMode', ctypes.c_uint), - ('callStack', ctypes.c_bool), + ('callStack', ctypes.c_uint, 1), ('dataFilter', ctypes.c_uint64), # The enumeration for dataFilter will use 64 bits ('evFilter', ctypes.c_uint), ('minLatency', ctypes.c_ulong), - ('includeNewFork', ctypes.c_bool), + ('includeNewFork', ctypes.c_uint, 1), ('branchSampleFilter', ctypes.c_ulong), ] @@ -166,16 +166,16 @@ class CtypesPmuAttr(ctypes.Structure): else: self.evtAttr = None - self.useFreq = ctypes.c_bool(useFreq) - self.excludeUser = ctypes.c_bool(excludeUser) - self.excludeKernel = ctypes.c_bool(excludeKernel) + self.useFreq = useFreq + self.excludeUser = excludeUser + self.excludeKernel = excludeKernel + self.callStack = callStack + self.includeNewFork = includeNewFork self.symbolMode = ctypes.c_uint(symbolMode) - self.callStack = ctypes.c_bool(callStack) self.dataFilter = ctypes.c_uint64(dataFilter) self.evFilter = ctypes.c_uint(evFilter) self.minLatency = ctypes.c_ulong(minLatency) - self.includeNewFork = ctypes.c_bool(includeNewFork) self.branchSampleFilter = ctypes.c_ulong(branchSampleFilter) @@ -306,7 +306,7 @@ class PmuAttr: @useFreq.setter def useFreq(self, useFreq: bool) -> None: - self.c_pmu_attr.useFreq = ctypes.c_bool(useFreq) + self.c_pmu_attr.useFreq = int(useFreq) @property def excludeUser(self) -> bool: @@ -314,7 +314,7 @@ class PmuAttr: @excludeUser.setter def excludeUser(self, excludeUser: bool) -> None: - self.c_pmu_attr.excludeUser = ctypes.c_bool(excludeUser) + self.c_pmu_attr.excludeUser = int(excludeUser) @property def excludeKernel(self) -> bool: @@ -322,7 +322,7 @@ class PmuAttr: @excludeKernel.setter def excludeKernel(self, excludeKernel: bool) -> None: - self.c_pmu_attr.excludeKernel = ctypes.c_bool(excludeKernel) + self.c_pmu_attr.excludeKernel = int(excludeKernel) @property def symbolMode(self) -> int: @@ -338,7 +338,7 @@ class PmuAttr: @callStack.setter def callStack(self, callStack: bool) -> None: - self.c_pmu_attr.callStack = ctypes.c_bool(callStack) + self.c_pmu_attr.callStack = int(callStack) @property def dataFilter(self) -> int: @@ -370,7 +370,7 @@ class PmuAttr: @includeNewFork.setter def includeNewFork(self, includeNewFork: bool) -> None: - self.c_pmu_attr.includeNewFork = ctypes.c_bool(includeNewFork) + self.c_pmu_attr.includeNewFork = int(includeNewFork) @property def branchSampleFilter(self) -> int: -- Gitee