From af7200546c66b6e5a3529d2dfa3d9c24dcd2c566 Mon Sep 17 00:00:00 2001 From: "lijindong (C)" <2220386943@qq.com> Date: Mon, 3 Nov 2025 15:57:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9A=84period=EF=BC=8Cu=EF=BC=8Ck=E5=81=9A?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/src/libkperf/kperf/kperf.go | 39 ++++++++++- include/pmu.h | 5 ++ pmu/pfm/uncore.cpp | 4 ++ pmu/pmu.cpp | 96 +++++++++++++-------------- pmu/pmu_event.h | 1 + pmu/sampler.cpp | 1 + python/modules/_libkperf/Pmu.py | 60 ++++++++++++++--- python/modules/kperf/pmu.py | 15 +++++ test/test_perf/case/test_new_fork.cpp | 6 +- test/test_perf/test_group.cpp | 30 ++++----- 10 files changed, 178 insertions(+), 79 deletions(-) diff --git a/go/src/libkperf/kperf/kperf.go b/go/src/libkperf/kperf/kperf.go index c1e7e7c..7d5def1 100644 --- a/go/src/libkperf/kperf/kperf.go +++ b/go/src/libkperf/kperf/kperf.go @@ -85,6 +85,10 @@ void SetEnableBpf(struct PmuAttr* attr, unsigned enableBpf) { attr->enableBpf = enableBpf; } +void SetEnableHwMetric(struct PmuAttr* attr, unsigned enableHwMetric) { + attr->enableHwMetric = enableHwMetric; +} + struct PmuData* IPmuRead(int fd, int* len) { struct PmuData* pmuData = NULL; *len = PmuRead(fd, &pmuData); @@ -174,6 +178,14 @@ size_t GetPmuTraceAttrSize() { return sizeof(struct PmuTraceAttr); } +void SetExcludeUserForEvt(struct EvtAttr* attr, unsigned excludeUser) { + attr->excludeUser = excludeUser; +} + +void SetExcludeKernelForEvt(struct EvtAttr* attr, unsigned excludeKernel) { + attr->excludeKernel = excludeKernel; +} + */ import "C" import "errors" @@ -350,11 +362,18 @@ var ( var fdModeMap map[int]C.enum_PmuTaskType = make(map[int]C.enum_PmuTaskType) +type EvtAttr struct { + GroupId int // group id + Period uint32 // sample period + ExcludeUser bool // excluder user config + ExcludeKernel bool // excluder kernel config +} + type PmuAttr struct { EvtList []string // evt list PidList []int // process id list CpuList []int // cpu id list - EvtAttr []int // group id list + EvtAttr []EvtAttr // evtAttr list SampleRate uint32 // sample rate, if useFreq=true, set the freq=SampleRate UseFreq bool // Use sample frequency or not, if set to true, used frequency, otherwise, used period ExcludeUser bool // Don't count user @@ -370,6 +389,7 @@ type PmuAttr struct { CgroupNameList []string // cgroup name list, if not user cgroup function, this field will be nullptr.if use cgroup function,use the cgroup name in the cgroupList to apply all event in the Event list EnableUserAccess bool // enable user access counting for current process EnableBpf bool // enable bpf mode for counting + EnableHwMetric bool // enable hw metric } type CpuTopology struct { @@ -564,8 +584,17 @@ func ToCPmuAttr(attr PmuAttr) (*C.struct_PmuAttr, int) { evtAttrLen := len(attr.EvtAttr) if evtAttrLen > 0 { evtAttrList := make([]C.struct_EvtAttr, evtAttrLen) - for i, groupId := range attr.EvtAttr { - evtAttrList[i] = C.struct_EvtAttr{C.int(groupId)} + for i, o := range attr.EvtAttr { + evtAttrList[i] = C.struct_EvtAttr{} + evtAttrList[i].groupId = C.int(o.GroupId) + evtAttrList[i].period = C.uint32_t(o.Period) + if o.ExcludeKernel { + C.SetExcludeKernelForEvt(&evtAttrList[i], C.uint(1)) + } + + if o.ExcludeUser { + C.SetExcludeUserForEvt(&evtAttrList[i], C.uint(1)) + } } cAttr.evtAttr = &evtAttrList[0] cAttr.numGroup = C.uint32_t(evtAttrLen) @@ -622,6 +651,10 @@ func ToCPmuAttr(attr PmuAttr) (*C.struct_PmuAttr, int) { C.SetEnableBpf(cAttr, C.uint(1)) } + if attr.EnableHwMetric { + C.SetEnableHwMetric(cAttr, C.uint(1)) + } + return cAttr, 0 } diff --git a/include/pmu.h b/include/pmu.h index c8115c9..20aa989 100644 --- a/include/pmu.h +++ b/include/pmu.h @@ -94,6 +94,9 @@ enum BranchSampleFilter { struct EvtAttr { int groupId; + unsigned period; + unsigned excludeUser : 1; + unsigned excludeKernel : 1; }; struct PmuAttr { @@ -178,6 +181,8 @@ struct PmuAttr { unsigned enableUserAccess : 1; // enable bpf mode for counting unsigned enableBpf : 1; + // enable hw metric + unsigned enableHwMetric : 1; }; enum PmuTraceType { diff --git a/pmu/pfm/uncore.cpp b/pmu/pfm/uncore.cpp index e05b79d..43be674 100644 --- a/pmu/pfm/uncore.cpp +++ b/pmu/pfm/uncore.cpp @@ -394,6 +394,10 @@ struct PmuEvt* GetUncoreEvent(const char* pmuName, int collectType) delete pmuEvtPtr; return nullptr; } + // if it starts with armv8_pmuv3_0, it is a core event. + if (strstr(pmuName, "armv8_pmuv3_0")) { + pmuEvtPtr->pmuType = CORE_TYPE; + } return pmuEvtPtr; } diff --git a/pmu/pmu.cpp b/pmu/pmu.cpp index 7d234f2..59b35a3 100644 --- a/pmu/pmu.cpp +++ b/pmu/pmu.cpp @@ -40,6 +40,8 @@ static SafeHandler pdMutex; static pair uncoreEventPair; #define REQUEST_USER_ACCESS 0x2 +#define HARD_WARE_METRIC 0x1 +#define SAMPLING_RECORD_PERIOD 4000 struct PmuTaskAttr* AssignPmuTaskParam(PmuTaskType collectType, struct PmuAttr *attr); @@ -223,10 +225,6 @@ static int CheckCollectTypeConfig(enum PmuTaskType collectType, struct PmuAttr * return LIBPERF_ERR_INVALID_BLOCKED_SAMPLE; } if (collectType == SAMPLING) { - if (attr->freq == 0) { - New(LIBPERF_ERR_INVALID_EVTLIST, "Invalid frequency or period in PmuAttr."); - return LIBPERF_ERR_INVALID_EVTLIST; - } if (attr->blockedSample == 0 && attr->evtList == nullptr) { New(LIBPERF_ERR_INVALID_EVTLIST, "In sampling mode without blocked sample, the event list cannot be null."); return LIBPERF_ERR_INVALID_EVTLIST; @@ -387,39 +385,6 @@ static void CopyAttrData(PmuAttr* newAttr, PmuAttr* inputAttr, enum PmuTaskType } newAttr->evtList = newEvtList; newAttr->numEvt = inputAttr->numEvt; - - // If the event group ID is not enabled, set the groupId to -1. It indicates that the event is not grouped. - if ((collectType == SAMPLING || collectType == COUNTING) && inputAttr->evtAttr == nullptr) { - struct EvtAttr *evtAttr = new struct EvtAttr[newAttr->numEvt]; - // handle event group id. -1 means that it doesn't run event group feature. - for (int i = 0; i < newAttr->numEvt; ++i) { - evtAttr[i].groupId = -1; - } - newAttr->evtAttr = evtAttr; - } -} - -static bool FreeEvtAttr(struct PmuAttr *attr) -{ - if (attr->evtAttr == nullptr) { - return SUCCESS; - } - bool flag = false; - int notGroupId = -1; - for (int i = 0; i < attr->numEvt; ++i) { - if (attr->evtAttr[i].groupId != notGroupId ) { - flag = true; - break; - } - } - - // when the values of groupId are all -1, the applied memory is released. - if (!flag) { - delete[] attr->evtAttr; - attr->evtAttr = nullptr; - } - - return SUCCESS; } static void FreeEvtList(unsigned evtNum, char** evtList) @@ -503,7 +468,11 @@ static unsigned GenerateSplitList(unordered_map& eventSplitMap, v // according to the origin eventList, generate the new eventList and new eventAttrList for (int i = 0; i < attr->numEvt; ++i) { auto evt = attr->evtList[i]; - auto evtAttr = attr->evtAttr[i]; + EvtAttr evtAttr = {-1, 0, false, false}; + if (attr->evtAttr != nullptr && i < attr->numGroup) { + auto inputAttr = attr->evtAttr[i]; + evtAttr = {inputAttr.groupId, inputAttr.period, inputAttr.excludeUser, inputAttr.excludeKernel}; + } // If the event is in the split list, it means that it is not a child event of the aggregate event // and direct add events to the new eventList and new eventAttrList @@ -566,7 +535,6 @@ int PmuOpen(enum PmuTaskType collectType, struct PmuAttr *attr) vector newEvtlist; vector newEvtAttrList; auto numEvt = GenerateSplitList(eventSplitMap, newEvtlist, &copiedAttr, newEvtAttrList); - FreeEvtAttr(&copiedAttr); copiedAttr.numEvt = numEvt; copiedAttr.evtList = newEvtlist.data(); copiedAttr.evtAttr = newEvtAttrList.data(); @@ -966,7 +934,28 @@ int GetCgroupFd(std::string& cgroupName) { return cgroupFd; } -static struct PmuTaskAttr* AssignTaskParam(PmuTaskType collectType, PmuAttr *attr, const char* evtName, const int groupId, const char* cgroupName, int cgroupFd) +static EvtAttr ResolveEvtAttrParams(struct PmuAttr *attr, int index) { + // numEvt must be greater than numGroup.The excludeUser, excluderKernel,and period attributes in PmuAttr have higher priority than those in EvtAttr. + int groupId = index >= attr->numGroup? -1 : attr->evtAttr[index].groupId; + + bool excludeKernel = index >= attr->numGroup ? false : attr->evtAttr[index].excludeKernel; + excludeKernel = attr->excludeKernel ? true : excludeKernel; + + bool excludeUser = index >= attr->numGroup ? false : attr->evtAttr[index].excludeUser; + excludeUser = attr->excludeUser ? true : excludeUser; + + unsigned period = index >= attr->numGroup ? SAMPLING_RECORD_PERIOD : attr->evtAttr[index].period; + period = attr->period ? attr->period : period; + + if (!period) { + period = SAMPLING_RECORD_PERIOD; + } + + EvtAttr evtAttrDto = {groupId, period, excludeUser, excludeKernel}; + return evtAttrDto; +} + +static struct PmuTaskAttr* AssignTaskParam(PmuTaskType collectType, PmuAttr *attr, const char* evtName, EvtAttr &evtAttrDto, const char* cgroupName, int cgroupFd) { unique_ptr taskParam(CreateNode(), PmuTaskAttrFree); /** @@ -1002,13 +991,13 @@ static struct PmuTaskAttr* AssignTaskParam(PmuTaskType collectType, PmuAttr *att */ PrepareCpuList(attr, taskParam.get(), pmuEvt); - taskParam->groupId = groupId; + taskParam->groupId = evtAttrDto.groupId; taskParam->pmuEvt = shared_ptr(pmuEvt, PmuEvtFree); taskParam->pmuEvt->useFreq = attr->useFreq; - taskParam->pmuEvt->period = attr->period; - taskParam->pmuEvt->excludeKernel = attr->excludeKernel; - taskParam->pmuEvt->excludeUser = attr->excludeUser; + taskParam->pmuEvt->period = evtAttrDto.period; + taskParam->pmuEvt->excludeKernel = evtAttrDto.excludeKernel; + taskParam->pmuEvt->excludeUser = evtAttrDto.excludeUser; taskParam->pmuEvt->callStack = attr->callStack; taskParam->pmuEvt->blockedSample = attr->blockedSample; taskParam->pmuEvt->includeNewFork = attr->includeNewFork; @@ -1020,6 +1009,10 @@ static struct PmuTaskAttr* AssignTaskParam(PmuTaskType collectType, PmuAttr *att if (attr->enableUserAccess) { taskParam->pmuEvt->config1 = REQUEST_USER_ACCESS; } + taskParam->pmuEvt->enableHwMetric = attr->enableHwMetric; + if (attr->enableHwMetric) { + taskParam->pmuEvt->config2 = HARD_WARE_METRIC; + } taskParam->pmuEvt->numEvent = attr->numEvt; taskParam->pmuEvt->enableBpf = attr->enableBpf; return taskParam.release(); @@ -1051,15 +1044,15 @@ struct PmuTaskAttr* AssignPmuTaskParam(enum PmuTaskType collectType, struct PmuA if (collectType == SPE_SAMPLING) { std::string cgroupName(attr->cgroupNameList[0]); // evtList is nullptr, cannot loop over evtList. - taskParam = AssignTaskParam(collectType, attr, nullptr, 0, cgroupName.c_str(), cgroupFds[cgroupName]); + EvtAttr evtAttrDto = {0, attr->period, attr->excludeUser, attr->excludeKernel}; + taskParam = AssignTaskParam(collectType, attr, nullptr, evtAttrDto, cgroupName.c_str(), cgroupFds[cgroupName]); return taskParam; } for (int i = 0; i < attr->numCgroup; ++i) { - // when the numEvt > numGroup, set groupId=-1 for other events - int groupId = i >= attr->numGroup? -1 : attr->evtAttr[i].groupId; std::string cgroupName(attr->cgroupNameList[i]); for (int j = 0; j < attr->numEvt; ++j) { - struct PmuTaskAttr* current = AssignTaskParam(collectType, attr, attr->evtList[j], groupId, cgroupName.c_str(), cgroupFds[cgroupName]); + EvtAttr evtAttrDto = ResolveEvtAttrParams(attr, j); + struct PmuTaskAttr* current = AssignTaskParam(collectType, attr, attr->evtList[j], evtAttrDto, cgroupName.c_str(), cgroupFds[cgroupName]); if (current == nullptr) { return nullptr; } @@ -1068,12 +1061,13 @@ struct PmuTaskAttr* AssignPmuTaskParam(enum PmuTaskType collectType, struct PmuA } } else { if (collectType == SPE_SAMPLING) { - taskParam = AssignTaskParam(collectType, attr, nullptr, 0, nullptr, -1); + EvtAttr evtAttrDto = {-1, attr->period, attr->excludeUser, attr->excludeKernel}; + taskParam = AssignTaskParam(collectType, attr, nullptr, evtAttrDto, nullptr, -1); return taskParam; } for (int i = 0; i < attr->numEvt; ++i) { - int groupId = i >= attr->numGroup? -1 : attr->evtAttr[i].groupId; - struct PmuTaskAttr* current = AssignTaskParam(collectType, attr, attr->evtList[i], groupId, nullptr, -1); + EvtAttr evtAttrDto = ResolveEvtAttrParams(attr, i); + struct PmuTaskAttr* current = AssignTaskParam(collectType, attr, attr->evtList[i], evtAttrDto, nullptr, -1); if (current == nullptr) { return nullptr; } diff --git a/pmu/pmu_event.h b/pmu/pmu_event.h index d8cdd63..09a4a9c 100644 --- a/pmu/pmu_event.h +++ b/pmu/pmu_event.h @@ -54,6 +54,7 @@ struct PmuEvt { unsigned enableUserAccess : 1; // avoid uncore (config1 & 0x2) == 0x2 unsigned numEvent; // pmu event number for bpf cgroup init unsigned enableBpf : 1; // enable bpf mode in counting mode + unsigned enableHwMetric : 1; // enable hw_metric=1 in sampling mode }; namespace KUNPENG_PMU { diff --git a/pmu/sampler.cpp b/pmu/sampler.cpp index 202c4af..88e58f7 100644 --- a/pmu/sampler.cpp +++ b/pmu/sampler.cpp @@ -43,6 +43,7 @@ int KUNPENG_PMU::PerfSampler::MapPerfAttr(const bool groupEnable, const int grou memset(&attr, 0, sizeof(attr)); attr.type = this->evt->type; attr.config = this->evt->config; + attr.config2 = this->evt->config2; attr.size = sizeof(struct perf_event_attr); attr.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_TIME | PERF_SAMPLE_CALLCHAIN | PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD | PERF_SAMPLE_IDENTIFIER | PERF_SAMPLE_RAW; diff --git a/python/modules/_libkperf/Pmu.py b/python/modules/_libkperf/Pmu.py index b1cc94f..53ded34 100644 --- a/python/modules/_libkperf/Pmu.py +++ b/python/modules/_libkperf/Pmu.py @@ -31,17 +31,32 @@ class CtypesEvtAttr(ctypes.Structure): int groupId; }; """ - _fields_ = [('groupId', ctypes.c_int)] + _fields_ = [ + ('groupId', ctypes.c_int), + ('period', ctypes.c_uint), + ('excludeUser', ctypes.c_uint, 1), + ('excludeKernel', ctypes.c_uint, 1) + ] - def __init__(self, groupId=0, *args, **kw): + def __init__(self, groupId=0, + period=0, + excludeUser=False, + excludeKernel=False, + *args, **kw): super(CtypesEvtAttr, self).__init__(*args, **kw) self.groupId = ctypes.c_int(groupId) + self.period = ctypes.c_uint(period) + self.excludeUser = excludeUser + self.excludeKernel = excludeKernel class EvtAttr: __slots__ = ['__c_evt_attr'] - def __init__(self, groupId=0): - self.__c_evt_attr = CtypesEvtAttr(groupId) + def __init__(self, groupId=0, + period=0, + excludeUser=False, + excludeKernel=False): + self.__c_evt_attr = CtypesEvtAttr(groupId, period, excludeUser, excludeKernel) @property def c_evt_attr(self): @@ -54,6 +69,22 @@ class EvtAttr: @groupId.setter def groupId(self, groupId): self.c_evt_attr.groupId = ctypes.c_int(groupId) + + @property + def excludeUser(self): + return bool(self.c_evt_attr.excludeUser) + + @excludeUser.setter + def excludeUser(self, excludeUser): + self.c_evt_attr.excludeUser = int(excludeUser) + + @property + def excludeKernel(self): + return bool(self.c_evt_attr.excludeKernel) + + @excludeKernel.setter + def excludeKernel(self, excludeKernel): + self.c_evt_attr.excludeKernel = int(excludeKernel) @classmethod def from_c_evt_attr(cls, c_evt_attr): @@ -123,7 +154,8 @@ class CtypesPmuAttr(ctypes.Structure): ('cgroupNameList', ctypes.POINTER(ctypes.c_char_p)), ('numCgroup', ctypes.c_uint), ('enableUserAccess', ctypes.c_uint, 1), - ('enableBpf', ctypes.c_uint, 1) + ('enableBpf', ctypes.c_uint, 1), + ('enableHwMetric', ctypes.c_uint, 1), ] def __init__(self, @@ -147,6 +179,7 @@ class CtypesPmuAttr(ctypes.Structure): numCgroup=0, enableUserAccess=False, enableBpf=False, + enableHwMetric=False, *args, **kw): super(CtypesPmuAttr, self).__init__(*args, **kw) @@ -181,7 +214,7 @@ class CtypesPmuAttr(ctypes.Structure): if evtAttr: numGroup = len(evtAttr) - self.evtAttr = (CtypesEvtAttr * numGroup)(*[CtypesEvtAttr(evt) for evt in evtAttr]) + self.evtAttr = (CtypesEvtAttr * numGroup)(*[evt.c_evt_attr for evt in evtAttr]) self.numGroup = ctypes.c_uint(numGroup) else: self.evtAttr = None @@ -210,6 +243,7 @@ class CtypesPmuAttr(ctypes.Structure): self.includeNewFork = includeNewFork self.enableUserAccess = enableUserAccess self.enableBpf = enableBpf + self.enableHwMetric = enableHwMetric class PmuAttr(object): __slots__ = ['__c_pmu_attr'] @@ -233,7 +267,8 @@ class PmuAttr(object): branchSampleFilter=0, cgroupNameList=None, enableUserAccess=False, - enableBpf=False): + enableBpf=False, + enableHwMetric=False): self.__c_pmu_attr = CtypesPmuAttr( evtList=evtList, @@ -254,7 +289,8 @@ class PmuAttr(object): branchSampleFilter=branchSampleFilter, cgroupNameList=cgroupNameList, enableUserAccess=enableUserAccess, - enableBpf=enableBpf + enableBpf=enableBpf, + enableHwMetric=enableHwMetric, ) @property @@ -272,6 +308,14 @@ class PmuAttr(object): @enableBpf.setter def enableBpf(self, enableBpf): self.c_pmu_attr.enableBpf = int(enableBpf) + + @property + def enableHwMetric(self): + return bool(self.c_pmu_attr.enableHwMetric) + + @enableHwMetric.setter + def enableHwMetric(self, enableHwMetric): + self.c_pmu_attr.enableHwMetric = int(enableHwMetric) @property def c_pmu_attr(self): diff --git a/python/modules/kperf/pmu.py b/python/modules/kperf/pmu.py index 4ee579e..8f6b657 100644 --- a/python/modules/kperf/pmu.py +++ b/python/modules/kperf/pmu.py @@ -240,6 +240,20 @@ class PmuDeviceData(_libkperf.PmuDeviceData): """ pass +class EvtAttr(_libkperf.EvtAttr): + def __init__(self, groupId=0, + period=0, + excludeUser=False, + excludeKernel=False): + super(EvtAttr, self).__init__( + groupId=groupId, + period=period, + excludeUser=excludeUser, + excludeKernel=excludeKernel + ) + + + class PmuAttr(_libkperf.PmuAttr): """ Args: @@ -627,6 +641,7 @@ __all__ = [ 'HitDataSource', 'SymbolMode', 'PmuAttr', + 'EvtAttr', 'PmuDeviceMetric', 'PmuDeviceAttr', 'PmuBdfType', diff --git a/test/test_perf/case/test_new_fork.cpp b/test/test_perf/case/test_new_fork.cpp index 927dc91..0716da5 100644 --- a/test/test_perf/case/test_new_fork.cpp +++ b/test/test_perf/case/test_new_fork.cpp @@ -18,7 +18,11 @@ void sum() { - sleep(2); + int sum = 0; + for (int i = 0; i < 2000; i++) { + sleep(1000); + sum += i; + } } int main() diff --git a/test/test_perf/test_group.cpp b/test/test_perf/test_group.cpp index 6410945..c93a79b 100644 --- a/test/test_perf/test_group.cpp +++ b/test/test_perf/test_group.cpp @@ -129,7 +129,7 @@ TEST_F(TestGroup, TestCountingEventGroup) "r26", "r2d", "r17", "r11", "r8", "r22", "r24", "r10"}; attr.evtList = evtList; - struct EvtAttr groupId[numEvt] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13, 13}; + struct EvtAttr groupId[numEvt] = {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {13}, {13}, {13}}; attr.evtAttr = groupId; attr.numGroup = numEvt; @@ -157,7 +157,7 @@ TEST_F(TestGroup, TestEventGroupLessGroupId) "r26", "r2d", "r17", "r11", "r8", "r22", "r24", "r10"}; attr.evtList = evtList; - struct EvtAttr groupId[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11}; + struct EvtAttr groupId[13] = {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {11}, {11}}; attr.evtAttr = groupId; attr.numGroup = 13; @@ -189,7 +189,7 @@ TEST_F(TestGroup, TestCountingEventGroupAllUncore) "r26", "r2d", "r17", "r11", "hisi_sccl1_ddrc2/flux_rd/", "hisi_sccl1_ddrc0/flux_wr/", "hisi_sccl1_hha2/rx_wbi/", "hisi_sccl1_hha3/bi_num/"}; attr.evtList = evtList; - struct EvtAttr groupId[numEvt] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13, 13}; + struct EvtAttr groupId[numEvt] = {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {13}, {13}, {13}}; attr.evtAttr = groupId; attr.numGroup = numEvt; int pd = PmuOpen(COUNTING, &attr); @@ -206,7 +206,7 @@ TEST_F(TestGroup, TestCountingEventGroupHasAggregateUncore) "r22", "hisi_sccl1_ddrc/flux_rd/"}; attr.evtList = evtList; - struct EvtAttr groupId[numEvt] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13}; + struct EvtAttr groupId[numEvt] = {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {13}}; attr.evtAttr = groupId; attr.numGroup = numEvt; int pd = PmuOpen(COUNTING, &attr); @@ -230,7 +230,7 @@ TEST_F(TestGroup, TestCountingEventGroupHasAggregateUncoreEnd) "hisi_sccl1_ddrc/flux_rd/"}; attr.evtList = evtList; - struct EvtAttr groupId[numEvt] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13}; + struct EvtAttr groupId[numEvt] = {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {13}}; attr.evtAttr = groupId; attr.numGroup = numEvt; @@ -248,14 +248,12 @@ TEST_F(TestGroup, TestCountingEventGroupHasAggregateUncoreEnd) TEST_F(TestGroup, TestCountingEventGroupAllAggregateUncore) { auto attr = GetPmuAttribute(); - unsigned numEvt = 13; + unsigned numEvt = 2; attr.numEvt = numEvt; - char *evtList[numEvt] = {"r3", "r1", "r14", "r4", "r12", "r5", "r25", "r2", - "r26", "r2d", "r17", "r11", - "hisi_sccl1_ddrc/flux_rd/"}; + char *evtList[numEvt] = {"hisi_sccl1_ddrc/flux_wr/", "hisi_sccl1_ddrc/flux_rd/"}; attr.evtList = evtList; - struct EvtAttr groupId[numEvt] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; + struct EvtAttr groupId[numEvt] = {{1}, {1}}; attr.evtAttr = groupId; attr.numGroup = numEvt; int pd = PmuOpen(COUNTING, &attr); @@ -272,7 +270,7 @@ TEST_F(TestGroup, TestCountingEventGroupHasUncore) "r22", "r24", "hisi_sccl1_ddrc/flux_rd/", "hisi_sccl1_ddrc/flux_wr/"}; attr.evtList = evtList; - struct EvtAttr groupId[numEvt] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13, 13}; + struct EvtAttr groupId[numEvt] = {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {13}, {13}, {13}}; attr.evtAttr = groupId; attr.numGroup = numEvt; @@ -295,7 +293,7 @@ TEST_F(TestGroup, TestSamplingNoEventGroup) char *evtList[numEvt] = {"r11", "r3"}; attr.evtList = evtList; - struct EvtAttr groupId[numEvt] = {1, 2}; + struct EvtAttr groupId[numEvt] = {{1}, {2}}; attr.evtAttr = groupId; attr.numGroup = numEvt; @@ -316,7 +314,7 @@ TEST_F(TestGroup, TestSamplingEventGroup) char *evtList[numEvt] = {"r11", "r3"}; attr.evtList = evtList; - struct EvtAttr groupId[numEvt] = {2, 2}; + struct EvtAttr groupId[numEvt] = {{2}, {2}}; attr.evtAttr = groupId; attr.numGroup = numEvt; @@ -337,7 +335,7 @@ TEST_F(TestGroup, TestSamplingEventGroupHasUncore) char *evtList[numEvt] = {"hisi_sccl1_ddrc/flux_rd/", "r3"}; attr.evtList = evtList; - struct EvtAttr groupId[numEvt] = {2, 2}; + struct EvtAttr groupId[numEvt] = {{2}, {2}}; attr.evtAttr = groupId; attr.numGroup = numEvt; @@ -357,7 +355,7 @@ TEST_F(TestGroup, TestEvtGroupForkNewThread) attr.pidList[0] = pid; attr.numPid = 1; attr.includeNewFork = 1; - struct EvtAttr groupId[numEvt] = {2, 2}; + struct EvtAttr groupId[numEvt] = {{2}, {2}}; attr.evtAttr = groupId; attr.numGroup = numEvt; @@ -367,7 +365,7 @@ TEST_F(TestGroup, TestEvtGroupForkNewThread) ASSERT_EQ(ret, SUCCESS); int len = PmuRead(pd, &data); EXPECT_TRUE(data != nullptr); - ASSERT_EQ(len, 5 * 2); + ASSERT_LE(len, 5 * 2); PmuEnable(pd); sleep(3); -- Gitee