diff --git a/pmu/pfm/core.cpp b/pmu/pfm/core.cpp index 572a51d8a8e89789942d4718bbde3e9bd1352fe8..df0809cdcb0583d438b1d775bc11a36b28d25795 100644 --- a/pmu/pfm/core.cpp +++ b/pmu/pfm/core.cpp @@ -1124,8 +1124,7 @@ std::string GetPmuDevicePath() return pmuDevice; } - static const string DEVICE_PATH = "/sys/bus/event_source/devices/"; - DIR *dir = opendir(DEVICE_PATH.c_str()); + DIR *dir = opendir(SYS_DEVICE_PATH.c_str()); if (dir == nullptr) { return ""; } @@ -1134,7 +1133,7 @@ std::string GetPmuDevicePath() #ifdef IS_X86 // look for devices like /sys/bus/event_source/devices/cpu/events if (strcmp(dent->d_name, "cpu") == 0) { - pmuDevice = DEVICE_PATH + dent->d_name; + pmuDevice = SYS_DEVICE_PATH + dent->d_name; break; } #else @@ -1144,13 +1143,13 @@ std::string GetPmuDevicePath() // look for devices like /sys/bus/event_source/devices/armv8_pmuv3_0/cpus. // Refer to function in kernel. - string armPmuPath = DEVICE_PATH + dent->d_name + "/cpus"; + string armPmuPath = SYS_DEVICE_PATH + dent->d_name + "/cpus"; if (ExistPath(armPmuPath)) { - pmuDevice = DEVICE_PATH + dent->d_name; + pmuDevice = SYS_DEVICE_PATH + dent->d_name; break; } #endif } closedir(dir); return pmuDevice; -} \ No newline at end of file +} diff --git a/pmu/pfm/uncore.cpp b/pmu/pfm/uncore.cpp index e73eb3043069c6a4d3c5fcde53e8b772f415cdd9..e05b79db1cf440b31368b034a62b2c95c206c964 100644 --- a/pmu/pfm/uncore.cpp +++ b/pmu/pfm/uncore.cpp @@ -29,7 +29,7 @@ static std::unordered_map> unC static int GetDeviceType(const string &devName) { - string typePath = "/sys/devices/" + devName + "/type"; + string typePath = SYS_DEVICE_PATH + devName + "/type"; std::string realPath = GetRealPath(typePath); if (!IsValidPath(realPath)) { return -1; @@ -47,7 +47,7 @@ static int GetDeviceType(const string &devName) static std::vector GetCpuMask(const string &devName) { std::vector maskList; - string maskPath = "/sys/devices/" + devName + "/cpumask"; + string maskPath = SYS_DEVICE_PATH + devName + "/cpumask"; std::string realPath = GetRealPath(maskPath); if (!IsValidPath(realPath)) { return maskList; @@ -100,7 +100,7 @@ static int64_t GetUncoreEventConfig(const char* pmuName) auto findSlash = strName.find('/'); string devName = strName.substr(0, findSlash); string evtName = strName.substr(devName.size() + 1, strName.size() - 1 - (devName.size() + 1)); - string evtPath = "/sys/devices/" + devName + "/events/" + evtName; + string evtPath = SYS_DEVICE_PATH + devName + "/events/" + evtName; std::string realPath = GetRealPath(evtPath); if (!IsValidPath(realPath)) { return -1; @@ -157,7 +157,7 @@ int FillUncoreFields(const char* pmuName, PmuEvt *evt) // Read the config params bitfiled from /sys/devices//format static std::unordered_map ReadConfigFormatFiles(const string &devName) { - string formatPath = "/sys/devices/" + devName + "/format"; + string formatPath = SYS_DEVICE_PATH + devName + "/format"; std::string realPath = GetRealPath(formatPath); if (!IsValidPath(realPath)) { return {}; @@ -225,7 +225,7 @@ static std::unordered_map ReadConfigFormatFil static std::pair ReadSupportEvtValue(const string &devName, const string &evtName) { - string evtPath = "/sys/devices/" + devName + "/events/" + evtName; + string evtPath = SYS_DEVICE_PATH + devName + "/events/" + evtName; std::string realPath = GetRealPath(evtPath); if (!IsValidPath(realPath)) { return {}; @@ -419,4 +419,4 @@ struct PmuEvt* GetUncoreRawEvent(const char* pmuName, int collectType) return nullptr; } return pmuEvtPtr; -} \ No newline at end of file +} diff --git a/pmu/pmu_event_list.cpp b/pmu/pmu_event_list.cpp index 547ccb2dbb735453701a8c15f66cb2d3c089a6d6..a1577cc18e3e43185b023e3ffb5d65a1de488b57 100644 --- a/pmu/pmu_event_list.cpp +++ b/pmu/pmu_event_list.cpp @@ -32,7 +32,6 @@ using EvtQueryer = function; static const string SLASH = "/"; static const string COLON = ":"; -static const string SYS_DEVICES = "/sys/devices/"; static const string EVENT_DIR = "/events/"; static std::mutex pmuEventListMtx; @@ -51,7 +50,7 @@ static void GetEventName(const string& devName, vector& eventList) { DIR* dir; struct dirent* entry; - auto path = SYS_DEVICES + devName + EVENT_DIR; + auto path = SYS_DEVICE_PATH + devName + EVENT_DIR; dir = opendir(path.c_str()); if (dir == nullptr) { return; @@ -148,12 +147,12 @@ const char** QueryUncoreEvent(unsigned *numEvt) } DIR* dir; struct dirent* entry; - dir = opendir(SYS_DEVICES.c_str()); + dir = opendir(SYS_DEVICE_PATH.c_str()); if (dir == nullptr) { return nullptr; } while ((entry = readdir(dir)) != nullptr) { - if (entry->d_type != DT_DIR) { + if (entry->d_type != DT_DIR && entry->d_type != DT_LNK) { continue; } string folderName = entry->d_name; @@ -285,4 +284,4 @@ void PmuEventListFree() PmuEventListFreeSingle(uncoreEventList); PmuEventListFreeSingle(traceEventList); New(SUCCESS); -} \ No newline at end of file +} diff --git a/pmu/pmu_metric.cpp b/pmu/pmu_metric.cpp index 03afa42bf0a0e4f4a4dc3afd54efa2ffc6255fcf..2c694feff9d2a4b3a556dd04ce1655e7797cfe7d 100644 --- a/pmu/pmu_metric.cpp +++ b/pmu/pmu_metric.cpp @@ -45,7 +45,6 @@ static vector coreArray; static std::mutex pmuBdfListMtx; static std::mutex pmuDeviceDataMtx; -static const string SYS_DEVICES = "/sys/devices/"; static const string SYS_BUS_PCI_DEVICES = "/sys/bus/pci/devices"; static const string SYS_IOMMU_DEVICES = "/sys/class/iommu"; static const string SYS_CPU_INFO_PATH = "/sys/devices/system/cpu/cpu"; @@ -388,11 +387,11 @@ namespace KUNPENG_PMU { if (!uncoreRawDeviceList.empty()) { return SUCCESS; } - if (!ExistPath(SYS_DEVICES) || !IsDirectory(SYS_DEVICES)) { + if (!ExistPath(SYS_DEVICE_PATH) || !IsDirectory(SYS_DEVICE_PATH)) { New(LIBPERF_ERR_QUERY_EVENT_LIST_FAILED, "Query uncore evtlist falied!"); return LIBPERF_ERR_QUERY_EVENT_LIST_FAILED; } - vector entries = ListDirectoryEntries(SYS_DEVICES); + vector entries = ListDirectoryEntries(SYS_DEVICE_PATH); for (const auto& entry : entries) { for (auto devPrefix : supportedDevicePrefixes) { if (entry.find(devPrefix) == 0) { @@ -507,15 +506,15 @@ namespace KUNPENG_PMU { // build map: EP bdf number -> bus static int GeneratePcieBusToBdfMap(unordered_map& pcieBdfToBus) { - if (!ExistPath(SYS_DEVICES) || !IsDirectory(SYS_DEVICES)) { + if (!ExistPath(SYS_DEVICE_PATH) || !IsDirectory(SYS_DEVICE_PATH)) { New(LIBPERF_ERR_QUERY_EVENT_LIST_FAILED, "Query uncore evtlist falied!"); return LIBPERF_ERR_QUERY_EVENT_LIST_FAILED; } - vector entries = ListDirectoryEntries(SYS_DEVICES); + vector entries = ListDirectoryEntries(SYS_DEVICE_PATH); for (const auto& entry : entries) { if (entry.find("pci0000:") == 0) { string bus = entry.substr(strlen("pci0000:")); - FindAllSubBdfDevice(SYS_DEVICES + "/" + entry, bus, pcieBdfToBus); + FindAllSubBdfDevice(SYS_DEVICE_PATH + "/" + entry, bus, pcieBdfToBus); } } return SUCCESS; @@ -555,20 +554,20 @@ namespace KUNPENG_PMU { } auto classifiedDevices = ClassifyDevicesByPrefix(pcieConfig.devicePrefix, pcieConfig.subDeviceName, pcieConfig.splitPosition); if (classifiedDevices.empty()) { - New(LIBPERF_ERR_NOT_SUPPORT_PCIE_COUNTING, "No pcie pmu device is not exist in the " + SYS_DEVICES); + New(LIBPERF_ERR_NOT_SUPPORT_PCIE_COUNTING, "No pcie pmu device is not exist in the " + SYS_DEVICE_PATH); return LIBPERF_ERR_NOT_SUPPORT_PCIE_COUNTING; } for (const auto& device : classifiedDevices) { const auto& pcieNuma = device.first; const auto& pciePmus = device.second; for (auto& pciePmu : pciePmus) { - string bdfBusPath = SYS_DEVICES + "/" + pciePmu + "/bus"; + string bdfBusPath = SYS_DEVICE_PATH + "/" + pciePmu + "/bus"; if (!ExistPath(bdfBusPath)) { New(LIBPERF_ERR_NOT_SUPPORT_PCIE_COUNTING, "pcie pmu bus file is empty"); return LIBPERF_ERR_NOT_SUPPORT_PCIE_COUNTING; } - string bdfMinPath = SYS_DEVICES + "/" + pciePmu + "/bdf_min"; - string bdfMaxPath = SYS_DEVICES + "/" + pciePmu + "/bdf_max"; + string bdfMinPath = SYS_DEVICE_PATH + "/" + pciePmu + "/bdf_min"; + string bdfMaxPath = SYS_DEVICE_PATH + "/" + pciePmu + "/bdf_max"; string bdfBusStr = ReadFileContent(bdfBusPath); int bus = 0; diff --git a/pmu/sampler.cpp b/pmu/sampler.cpp index 28931478500a13b2a0e88e989cb3aaf8f2fa1b22..8dcb759e0429a34075621196779d061c8ec201ad 100644 --- a/pmu/sampler.cpp +++ b/pmu/sampler.cpp @@ -107,7 +107,10 @@ union KUNPENG_PMU::PerfEvent *KUNPENG_PMU::PerfSampler::SampleReadEvent() int KUNPENG_PMU::PerfSampler::Mmap() { - int mmapLen = (SAMPLE_PAGES + 1) * SAMPLE_PAGE_SIZE; + // determines size of ring buffer on each core. + // For normal sampling, size of each packet is around 0x38;For brbe sampling, size of each packet is around 0x330 which requires more buffer size. + int samplePages = branchSampleFilter == KPERF_NO_BRANCH_SAMPLE ? DEFAULT_SAMPLE_PAGES : BRBE_SAMPLE_PAGES; + int mmapLen = (samplePages + 1) * SAMPLE_PAGE_SIZE; auto mask = mmapLen - SAMPLE_PAGE_SIZE - 1; this->sampleMmap->prev = 0; this->sampleMmap->mask = static_cast<__u64>(mask); diff --git a/pmu/sampler.h b/pmu/sampler.h index e4dc0d7e05d7d5d9293f318a3762f9e7e6866a3d..ba0711a95aa73d3c1fff0e1daa75a6013de4cecc 100644 --- a/pmu/sampler.h +++ b/pmu/sampler.h @@ -34,7 +34,8 @@ namespace KUNPENG_PMU { }; static constexpr int SAMPLE_PAGE_SIZE = 4096; - static constexpr int SAMPLE_PAGES = 128; + static constexpr int DEFAULT_SAMPLE_PAGES = 128; + static constexpr int BRBE_SAMPLE_PAGES = 1024; class PerfSampler : public PerfEvt { public: diff --git a/test/test_perf/case/test_100000thread.cpp b/test/test_perf/case/test_10000thread.cpp similarity index 93% rename from test/test_perf/case/test_100000thread.cpp rename to test/test_perf/case/test_10000thread.cpp index e43d52901b51b3714a772b54cb7bed676e2c017e..9d74f2376507d86a8e67d6078aed427645339466 100644 --- a/test/test_perf/case/test_100000thread.cpp +++ b/test/test_perf/case/test_10000thread.cpp @@ -38,7 +38,7 @@ void *ThreadFunc(void *data) int main() { - const int threadNum = 100000; + const int threadNum = 10000; pthread_t threads[threadNum]; for (int i = 0; i < threadNum; i++) { @@ -54,6 +54,5 @@ int main() void *retval; pthread_join(threads[i], &retval); } - cout << "compilte" << endl; return 0; -} \ No newline at end of file +} diff --git a/test/test_perf/test_api.cpp b/test/test_perf/test_api.cpp index b3d9668c0d44a9588b1be0a0a03e88a76b8ae7bb..a08152091c22a62f5ea5b23391a4c74324ee2c49 100644 --- a/test/test_perf/test_api.cpp +++ b/test/test_perf/test_api.cpp @@ -33,7 +33,6 @@ public: // Create a simple process. demoPid = RunTestApp(exePath); - cout << "pid: " << demoPid << endl; } static void TearDownTestCase() @@ -226,6 +225,9 @@ TEST_F(TestAPI, SampleOnlyElf) TEST_F(TestAPI, SpeNoSymbol) { + if (!HasSpeDevice()) { + GTEST_SKIP(); + } auto attr = GetSpeAttribute(); attr.symbolMode = NO_SYMBOL_RESOLVE; pd = PmuOpen(SPE_SAMPLING, &attr); @@ -240,6 +242,9 @@ TEST_F(TestAPI, SpeNoSymbol) TEST_F(TestAPI, SpeInitSuccess) { + if (!HasSpeDevice()) { + GTEST_SKIP(); + } auto attr = GetSpeAttribute(); pd = PmuOpen(SPE_SAMPLING, &attr); ASSERT_TRUE(pd != -1); @@ -247,6 +252,9 @@ TEST_F(TestAPI, SpeInitSuccess) TEST_F(TestAPI, SpeCollectSuccess) { + if (!HasSpeDevice()) { + GTEST_SKIP(); + } auto attr = GetSpeAttribute(); pd = PmuOpen(SPE_SAMPLING, &attr); ASSERT_TRUE(pd != -1); @@ -256,6 +264,9 @@ TEST_F(TestAPI, SpeCollectSuccess) TEST_F(TestAPI, SpeReadSuccess) { + if (!HasSpeDevice()) { + GTEST_SKIP(); + } auto attr = GetSpeAttribute(); pd = PmuOpen(SPE_SAMPLING, &attr); int ret = PmuCollect(pd, 3000, collectInterval); @@ -321,6 +332,9 @@ TEST_F(TestAPI, SampleCollectBadPd) TEST_F(TestAPI, SpeInitBusy) { + if (!HasSpeDevice()) { + GTEST_SKIP(); + } auto attr = GetSpeAttribute(); pd = PmuOpen(SPE_SAMPLING, &attr); ASSERT_TRUE(pd != -1); @@ -344,6 +358,9 @@ TEST_F(TestAPI, SampleSystem) TEST_F(TestAPI, SpeSystem) { + if (!HasSpeDevice()) { + GTEST_SKIP(); + } auto attr = GetSpeAttribute(); attr.pidList = nullptr; attr.numPid = 0; @@ -405,12 +422,10 @@ TEST_F(TestAPI, TestRaiseNumFd) auto pid = RunTestApp("test_12threads"); attr.pidList[0] = pid; attr.numPid = 1; - std::cout << "pid:" << attr.pidList[0] << std::endl; sleep(1); // Wait for all threads to start int numChildTid = 0; int* childTidList = GetChildTid(attr.pidList[0], &numChildTid); int numCpu = attr.cpuList == nullptr ? sysconf(_SC_NPROCESSORS_ONLN) : attr.numCpu; - std::cout << "required fd:" << numCpu * numChildTid << std::endl; unsigned long setNumFd = numCpu * numChildTid - 100; struct rlimit currentlim; @@ -418,12 +433,6 @@ TEST_F(TestAPI, TestRaiseNumFd) struct rlimit rlim { .rlim_cur = setNumFd, .rlim_max = currentlim.rlim_max, }; - if (setrlimit(RLIMIT_NOFILE, &rlim) == 0) { - std::cout << "setrlimit rlim_cur:" << setNumFd << std::endl; - } else { - std::cout << "currentlim rlim_cur:" << currentlim.rlim_cur << std::endl; - std::cout << "currentlim rlim_max:" << currentlim.rlim_max << std::endl; - } int pd = PmuOpen(SAMPLING, &attr); std::cout << "pd:" << pd << std::endl; @@ -434,7 +443,6 @@ TEST_F(TestAPI, TestRaiseNumFd) // When (execution) struct PmuData* pmuData = nullptr; int len = PmuRead(pd, &pmuData); - std::cout << "len:" << len << std::endl; // Then (verification) ASSERT_GT(len, 0); @@ -596,6 +604,9 @@ TEST_F(TestAPI, TestShortChild) TEST_F(TestAPI, TestSPEEventGroup) { + if (!HasSpeDevice()) { + GTEST_SKIP(); + } auto attr = GetSpeAttribute(); unsigned numEvt = 16; struct EvtAttr groupId[numEvt] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13, 13}; @@ -723,4 +734,4 @@ TEST_F(TestAPI, InvalidCgroupNameListSPE) attr.numCgroup = 2; auto pd = PmuOpen(SPE_SAMPLING, &attr); ASSERT_EQ(pd, -1); -} \ No newline at end of file +} diff --git a/test/test_perf/test_cgroup.cpp b/test/test_perf/test_cgroup.cpp index f68db1771e7139706b6b7a62ff1745f147b75c2e..484a966d6cda7292b34ce0fffd734ac22299575a 100644 --- a/test/test_perf/test_cgroup.cpp +++ b/test/test_perf/test_cgroup.cpp @@ -56,6 +56,8 @@ protected: PmuAttr attr = {0}; attr.evtList = evtList; attr.numEvt = numEvt; + attr.freq = 1000; + attr.useFreq = 1; attr.symbolMode = RESOLVE_ELF_DWARF; return attr; } @@ -151,6 +153,9 @@ TEST_F(TestCgroup, TestCgroupSampling) TEST_F(TestCgroup, TestCgroupSPE) { + if (!HasSpeDevice()) { + GTEST_SKIP(); + } cgroupPath += "/cgroupSPE"; ASSERT_EQ(mkdir(cgroupPath.c_str(), 0755), 0); const string cgroupProc = cgroupPath + "/cgroup.procs"; @@ -176,4 +181,4 @@ TEST_F(TestCgroup, TestCgroupSPE) ASSERT_GT(len, 0); ASSERT_STREQ(data[0].cgroupName, "cgroupSPE"); ASSERT_GT(data[0].period, 0); -} \ No newline at end of file +} diff --git a/test/test_perf/test_common.cpp b/test/test_perf/test_common.cpp index 786b0629b8da039b994d61ee2948c71a1201656a..29fb5d2b555f69d3b60d55440d05cd1722ced2df 100644 --- a/test/test_perf/test_common.cpp +++ b/test/test_perf/test_common.cpp @@ -20,6 +20,7 @@ #include #include #include "process_map.h" +#include "common.h" #include "test_common.h" using namespace std; @@ -32,7 +33,9 @@ pid_t RunTestApp(const string &name) // Bind test_perf to cpu 0 and bind test app to cpu 1. cpu_set_t mask; CPU_ZERO(&mask); - CPU_SET(1, &mask); + for (int i = 1;i < 16; ++i) { + CPU_SET(i, &mask); + } sched_setaffinity(0, sizeof(mask), &mask); setpgid(0, 0); string fullPath = string(dirname(myDir)) + "/case/" + name; @@ -87,8 +90,11 @@ bool FoundAllTids(PmuData *data, int len, pid_t pid) vector GetChildPid(pid_t pid) { string childPath = "/proc/" + to_string(pid) + "/task/" + to_string(pid) + "/children"; - ifstream in(childPath); vector ret; + ifstream in(childPath); + if (!in.is_open()) { + return ret; + } while (!in.eof()) { string pidStr; in >> pidStr; @@ -236,4 +242,16 @@ bool HasEvent(PmuData *data, int len, std::string evt) } } return false; -} \ No newline at end of file +} + +bool HasSpeDevice() +{ + auto devices = ListDirectoryEntries("/sys/devices"); + for (auto &dev : devices) { + if (dev == "arm_spe_0") { + return true; + } + } + return false; +} + diff --git a/test/test_perf/test_common.h b/test/test_perf/test_common.h index 0cbf1585ac383dc1c0694329d66313ad1db1819e..96c8b002639605d7b32cc18f11ad3ca30788bc57 100644 --- a/test/test_perf/test_common.h +++ b/test/test_perf/test_common.h @@ -45,4 +45,7 @@ bool CheckDataPid(PmuData *data, int len, int pid); // Check whether at least one event name of data is . bool HasEvent(PmuData *data, int len, std::string evt); -#endif \ No newline at end of file +// Check whether there is arm_spe_0 device. +bool HasSpeDevice(); + +#endif diff --git a/test/test_perf/test_count.cpp b/test/test_perf/test_count.cpp index bbfa70ae1cdee1adc214277198989f6ebc1e0952..380ceb9919ea1c2253017fafcf69d37538b9faaf 100644 --- a/test/test_perf/test_count.cpp +++ b/test/test_perf/test_count.cpp @@ -427,7 +427,7 @@ TEST_F(TestCount, SimdRatio) static std::vector GetHHADirs() { vector hhaEvents; - unique_ptr dir(opendir("/sys/devices"), &closedir); + unique_ptr dir(opendir(SYS_DEVICE_PATH.c_str()), &closedir); if(!dir) { return hhaEvents; } @@ -439,7 +439,7 @@ static std::vector GetHHADirs() { continue; } - if(dt->d_type == DT_DIR && strstr(name.c_str(), "hha") != nullptr) { + if((dt->d_type == DT_DIR || dt->d_type == DT_LNK) && strstr(name.c_str(), "hha") != nullptr) { hhaEvents.push_back(name + "/"); } } @@ -447,7 +447,7 @@ static std::vector GetHHADirs() { } -TEST_F(TestCount, DeleteEvtAfterOpenPmuu) { +TEST_F(TestCount, DeleteEvtAfterOpenPmu) { struct PmuAttr attr = {nullptr}; vector hhaEvents = GetHHADirs(); ASSERT_TRUE(hhaEvents.size() > 0); @@ -483,7 +483,7 @@ TEST_F(TestCount, DeleteEvtAfterOpenPmuu) { TEST_F(TestCount, Test100000ThreadInCountingMode) { // Count a process with one event. - appPid = RunTestApp("test_100000thread"); + appPid = RunTestApp("test_10000thread"); sleep(1); int pidList[1] = {appPid}; int cpuList[1] = {1}; @@ -504,4 +504,4 @@ TEST_F(TestCount, Test100000ThreadInCountingMode) { ASSERT_GT(len, 0); PmuDataFree(data); PmuClose(pd); -} \ No newline at end of file +} diff --git a/test/test_perf/test_group.cpp b/test/test_perf/test_group.cpp index f40e6829fdc67f8966d50d78c36f3c2ee7a28c46..74d0577cf9422d2923c03950e6c0a879dde1d568 100644 --- a/test/test_perf/test_group.cpp +++ b/test/test_perf/test_group.cpp @@ -256,10 +256,6 @@ TEST_F(TestGroup, TestSamplingNoEventGroup) char *evtList[numEvt] = {"r11", "r3"}; attr.evtList = evtList; - int cpuList[1] = {1}; - attr.cpuList = cpuList; - attr.numCpu = 1; - struct EvtAttr groupId[numEvt] = {1, 2}; attr.evtAttr = groupId; @@ -280,9 +276,6 @@ TEST_F(TestGroup, TestSamplingEventGroup) char *evtList[numEvt] = {"r11", "r3"}; attr.evtList = evtList; - int cpuList[1] = {1}; - attr.cpuList = cpuList; - attr.numCpu = 1; struct EvtAttr groupId[numEvt] = {2, 2}; attr.evtAttr = groupId; @@ -303,9 +296,6 @@ TEST_F(TestGroup, TestSamplingEventGroupHasUncore) char *evtList[numEvt] = {"hisi_sccl1_ddrc/flux_rd/", "r3"}; attr.evtList = evtList; - int cpuList[1] = {1}; - attr.cpuList = cpuList; - attr.numCpu = 1; struct EvtAttr groupId[numEvt] = {2, 2}; attr.evtAttr = groupId; @@ -347,4 +337,4 @@ TEST_F(TestGroup, TestEvtGroupForkNewThread) PmuClose(pd); kill(pid, SIGTERM); -} \ No newline at end of file +} diff --git a/test/test_perf/test_pmu.cpp b/test/test_perf/test_pmu.cpp index 20d6d6cc7d43a7ceb2efbdc7538b72cdde645bd8..7897ded688a54f346d6ee36f6441abae81d2b4f4 100644 --- a/test/test_perf/test_pmu.cpp +++ b/test/test_perf/test_pmu.cpp @@ -183,15 +183,12 @@ TEST_F(TestPMU, NoDataAfterDisable) ASSERT_EQ(len, 0); } -TEST_F(TestPMU, TestSampling100000ThreadCase) +TEST_F(TestPMU, TestSampling10000ThreadCase) { - appPid = RunTestApp("test_100000thread"); + appPid = RunTestApp("test_10000thread"); sleep(1); pid_t pidList[1] = {appPid}; - int cpuList[1] = {1}; auto attr = GetProcAttribute(pidList, 1); - attr.cpuList = cpuList; - attr.numCpu = 1; auto pd = PmuOpen(SAMPLING, &attr); PmuEnable(pd); sleep(3); @@ -200,4 +197,4 @@ TEST_F(TestPMU, TestSampling100000ThreadCase) ASSERT_GT(len, 0); PmuDataFree(data); PmuClose(pd); -} \ No newline at end of file +} diff --git a/test/test_perf/test_spe.cpp b/test/test_perf/test_spe.cpp index d42cffa56617037f3a3dafb9e9889151d69f7369..84beb6365536d50b45d8f513c31e647f52db0167 100644 --- a/test/test_perf/test_spe.cpp +++ b/test/test_perf/test_spe.cpp @@ -19,6 +19,12 @@ using namespace std; class TestSPE : public testing::Test { public: + void SetUp() { + if (!HasSpeDevice()) { + GTEST_SKIP(); + } + } + void TearDown() { if (appPid != 0) { KillApp(appPid); @@ -180,4 +186,4 @@ TEST_F(TestSPE, SpeProcCollect100000threadCase) ASSERT_GT(len, 0); PmuDataFree(data); PmuClose(pd); -} \ No newline at end of file +} diff --git a/test/test_perf/test_trace_analysis.cpp b/test/test_perf/test_trace_analysis.cpp index 5abec52e319946bab28fd11acca4303f631545b6..d9beb69c863dca992f5d7f6c1e69c503d411a680 100644 --- a/test/test_perf/test_trace_analysis.cpp +++ b/test/test_perf/test_trace_analysis.cpp @@ -13,11 +13,17 @@ * Description: test for analyszing the trace data ******************************************************************************/ #include "test_common.h" +#include "common.h" using namespace std; class TestAnaylzeData : public testing::Test { public: + void SetUp() { + if (GetTraceEventDir() == "") { + GTEST_SKIP(); + } + } void TearDown() { if (appPid != 0) { KillApp(appPid); @@ -151,4 +157,4 @@ TEST_F(TestAnaylzeData, collect_all_trace_data_success) { int len = PmuTraceRead(pd, &data); EXPECT_TRUE(data != nullptr); EXPECT_TRUE(data[len - 1].funcs != nullptr); -} \ No newline at end of file +} diff --git a/test/test_perf/test_trace_pointer.cpp b/test/test_perf/test_trace_pointer.cpp index 430f3945e78cde205bff09ffa3fcfc8a54e32a7e..24f390bf3e73413387276768744a72c201627f7d 100644 --- a/test/test_perf/test_trace_pointer.cpp +++ b/test/test_perf/test_trace_pointer.cpp @@ -13,11 +13,18 @@ * Description: test for trace pointer event. ******************************************************************************/ #include "test_common.h" +#include "common.h" using namespace std; class TestTraceRaw : public testing::Test { public: + void SetUp() { + if (GetTraceEventDir() == "") { + GTEST_SKIP(); + } + } + void TearDown() { if (appPid != 0) { KillApp(appPid); @@ -214,4 +221,4 @@ TEST_F(TestTraceRaw, trace_pointer_for_get_exp) { ASSERT_EQ(name_1, nullptr); ASSERT_STREQ(Perror(), "invalid fieldName, can't find it in format data."); } -} \ No newline at end of file +} diff --git a/util/common.h b/util/common.h index 7279b5a4ce285fe6d323e0bdd3d29a74dae3e8ea..3af3c4eec60f3c649a493f80237dce2b0708f8c1 100644 --- a/util/common.h +++ b/util/common.h @@ -35,6 +35,7 @@ const std::string TRACE_EVENT_PATH = "/sys/kernel/tracing/events/"; const std::string TRACE_DEBUG_EVENT_PATH = "/sys/kernel/debug/tracing/events/"; const std::string PERF_EVENT_PARANOID_PATH = "/proc/sys/kernel/perf_event_paranoid"; +const std::string SYS_DEVICE_PATH = "/sys/bus/event_source/devices/"; inline bool IsValidIp(unsigned long ip) {