From fe38baf0e838b13f1cdf9b9b3ea153e31fc45118 Mon Sep 17 00:00:00 2001 From: "lijindong (C)" <2220386943@qq.com> Date: Fri, 26 Sep 2025 11:22:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E9=94=99=E8=AF=AF=E7=A0=81no?= =?UTF-8?q?=20such=20file=20or=20directory=EF=BC=8C=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0python=E5=AE=89=E8=A3=85=E9=83=A8=E5=88=86=E8=B5=84?= =?UTF-8?q?=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 13 +++++++++++++ README.md | 15 ++++++++++++++- pmu/evt.cpp | 9 +-------- pmu/evt_list_default.cpp | 3 +++ pmu/perf_counter_default.cpp | 1 - pmu/pmu.cpp | 2 -- pmu/pmu_event.cpp | 2 ++ pmu/pmu_metric.cpp | 3 --- pmu/sample_process.cpp | 2 -- pmu/sampler.h | 4 ---- pmu/spe_sampler.cpp | 7 ------- 11 files changed, 33 insertions(+), 28 deletions(-) diff --git a/README.en.md b/README.en.md index 6644bc3..ffc0d13 100644 --- a/README.en.md +++ b/README.en.md @@ -84,12 +84,25 @@ To build a python package: bash build.sh install_path=/path/to/install python=true ``` +If the environment contains multiple Python versions, you need to specify the Python interpreter to be installed +```shell +bash build.sh python=true python_exe=$(which python3) +``` + To uninstall python package: ```shell python3 -m pip uninstall -y libkperf ``` +If a Python module runtime error similar to the following is reported: +OSERROR: /usr/lib/python3.9/site-packages/_libkperf/libsym.so: cannot open shared object file: No such file or directory +The Python installation fails due to an incompatible setuptool version. This can be resolved by downgrading. +```shell +python3 -m pip uninstall setuptools +python3 -m pip install setuptools=58 +``` + TO build a Go package: ```shell diff --git a/README.md b/README.md index a0e33c6..c441df5 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,12 @@ bash build.sh install_path=/path/to/install build_type=debug 如果想要编译python包: ```shell -bash build.sh install_path=/path/to/install python=true +bash build.sh install_path=/path/to/install python=true +``` + +假如环境中包含多个python版本,需要指定要安装的python解释器 +```shell +bash build.sh python=true python_exe=$(which python3) ``` 安装后若需要卸载python库, 可以执行下述命令 @@ -73,6 +78,14 @@ bash build.sh install_path=/path/to/install python=true python3 -m pip uninstall -y libkperf ``` +python模块运行时报错若类似如下 +OSERROR: /usr/lib/python3.9/site-packages/_libkperf/libsym.so: cannot open shared object file: No such file or directory +python安装setuptool版本不适配问题导致安装失败,目前可采用降级的方式解决 +```shell +python3 -m pip uninstall setuptools +python3 -m pip install setuptools=58 +``` + 想要编译go的包 ```shell bash build.sh go=true diff --git a/pmu/evt.cpp b/pmu/evt.cpp index c9a27ae..9922582 100644 --- a/pmu/evt.cpp +++ b/pmu/evt.cpp @@ -22,14 +22,7 @@ #include "pcerrc.h" #include "evt.h" -enum class HEAD_SIZE { - HEAD_SIZE_ONE = 1, - HEAD_SIZE_TWO = 2, - HEAD_SIZE_FOUR = 4, - HEAD_SIZE_EIGHT = 8, -}; - -static constexpr double CUT_OFF_PERCENT = 0.05; + int KUNPENG_PMU::PerfEventOpen(struct perf_event_attr *attr, pid_t pid, int cpu, int groupFd, unsigned long flags) { return syscall(__NR_perf_event_open, attr, pid, cpu, groupFd, flags); diff --git a/pmu/evt_list_default.cpp b/pmu/evt_list_default.cpp index 6f96e88..5b050a4 100644 --- a/pmu/evt_list_default.cpp +++ b/pmu/evt_list_default.cpp @@ -71,6 +71,9 @@ void KUNPENG_PMU::EvtListDefault::AdaptErrInfo(int err, PerfEvtPtr perfEvt) case LIBPERF_ERR_COUNTER_INDEX_IS_ZERO: pcerr::SetCustomErr(err, "There are too many open events. No registers are available."); break; + case LIBPERF_ERR_OPEN_INVALID_FILE: + pcerr::SetCustomErr(err, "The kernel cannot find the corresponding file or directory when loading the event: " +perfEvt->GetEvtName()); + break; case UNKNOWN_ERROR: pcerr::SetCustomErr(err, std::string{strerror(errno)}); break; diff --git a/pmu/perf_counter_default.cpp b/pmu/perf_counter_default.cpp index 0dd1ec5..f34f23c 100644 --- a/pmu/perf_counter_default.cpp +++ b/pmu/perf_counter_default.cpp @@ -36,7 +36,6 @@ using namespace std; using namespace pcerr; -static constexpr int MAX_ATTR_SIZE = 120; struct GroupReadFormat { __u64 nr; diff --git a/pmu/pmu.cpp b/pmu/pmu.cpp index b83c4af..7d234f2 100644 --- a/pmu/pmu.cpp +++ b/pmu/pmu.cpp @@ -38,7 +38,6 @@ using namespace std; static unordered_map runningStatus; static SafeHandler pdMutex; static pair uncoreEventPair; -static std::set onLineCpuIds; #define REQUEST_USER_ACCESS 0x2 @@ -1194,4 +1193,3 @@ struct SampleRawField *PmuGetFieldExp(struct SampleRawData *rawData, const char return rt; #endif } - diff --git a/pmu/pmu_event.cpp b/pmu/pmu_event.cpp index 21324a6..046e4c5 100644 --- a/pmu/pmu_event.cpp +++ b/pmu/pmu_event.cpp @@ -20,6 +20,8 @@ namespace KUNPENG_PMU { { switch (sysErr) { case EPERM: + case ENOENT: + return LIBPERF_ERR_OPEN_INVALID_FILE; case EACCES: return LIBPERF_ERR_NO_PERMISSION; case EBUSY: diff --git a/pmu/pmu_metric.cpp b/pmu/pmu_metric.cpp index 7a99acd..22d4ae2 100644 --- a/pmu/pmu_metric.cpp +++ b/pmu/pmu_metric.cpp @@ -39,9 +39,6 @@ using namespace std; using namespace pcerr; using IdxMap = unordered_map>; -static unsigned maxCpuNum = 0; -static vector coreArray; - static std::mutex pmuBdfListMtx; static std::mutex pmuDeviceDataMtx; diff --git a/pmu/sample_process.cpp b/pmu/sample_process.cpp index 3eef6c6..57989e7 100644 --- a/pmu/sample_process.cpp +++ b/pmu/sample_process.cpp @@ -21,8 +21,6 @@ #include "sample_process.h" #define PAGE_SIZE (sysconf(_SC_PAGESIZE)) -#define MB() asm volatile("dmb ish" ::: "memory") -static constexpr int MAX_DATA_SIZE = 8192; using namespace pcerr; diff --git a/pmu/sampler.h b/pmu/sampler.h index ba0711a..af4d198 100644 --- a/pmu/sampler.h +++ b/pmu/sampler.h @@ -28,10 +28,6 @@ #include "symbol.h" namespace KUNPENG_PMU { - struct MmapParam { - int prot; - __u64 mask; - }; static constexpr int SAMPLE_PAGE_SIZE = 4096; static constexpr int DEFAULT_SAMPLE_PAGES = 128; diff --git a/pmu/spe_sampler.cpp b/pmu/spe_sampler.cpp index b316baf..253839e 100644 --- a/pmu/spe_sampler.cpp +++ b/pmu/spe_sampler.cpp @@ -24,13 +24,6 @@ #include "spe_sampler.h" #include "pcerr.h" -#define MB() asm volatile("dsb sy"); -#define rmb() asm volatile("dsb ld"); -#define wmb() asm volatile("dsb st"); - -static constexpr int CYCLES_FREQ = 100; -static constexpr int SPE_PERIOD = 100; - using namespace std; namespace KUNPENG_PMU { -- Gitee