From 945f1db2929753493132f997ee2b7ef1f70ae44d Mon Sep 17 00:00:00 2001 From: "lijindong (C)" <2220386943@qq.com> Date: Tue, 9 Dec 2025 10:29:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0symMode=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=BB=B6=E8=BF=9F=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E7=AC=A6=E5=8F=B7=EF=BC=8C=E5=8E=9F=E6=9D=A5NO=5FSYMBOL=5FRESO?= =?UTF-8?q?LVE=E4=B8=8D=E5=86=8D=E5=81=9A=E4=BB=BB=E4=BD=95=E7=AC=A6?= =?UTF-8?q?=E5=8F=B7=E7=9B=B8=E5=85=B3=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/C_C++_API.md | 2 +- docs/Go_API.md | 2 +- docs/Python_API.md | 3 ++- go/src/libkperf/kperf/kperf.go | 4 +++- go/src/libkperf_test/libkperf_test.go | 2 +- include/pmu.h | 10 +++++++--- pmu/pmu_list.cpp | 5 ++++- pmu/sampler.cpp | 8 ++++---- pmu/spe.cpp | 4 ++-- python/modules/kperf/pmu.py | 11 ++++++----- tools/cache_collect/collect.cpp | 2 +- 11 files changed, 32 insertions(+), 21 deletions(-) diff --git a/docs/C_C++_API.md b/docs/C_C++_API.md index 82bd6bf..3fa8b94 100644 --- a/docs/C_C++_API.md +++ b/docs/C_C++_API.md @@ -176,7 +176,7 @@ 清理PmuData ### int ResolvePmuDataSymbol(struct PmuData* pmuData); -当SymbolMode不设置或者设置为0时,可通过该接口解析read返回的PmuData数据中的符号 +当SymbolMode设置为3或者4时,可通过该接口解析read返回的PmuData数据中的符号 ### int PmuDumpData(struct PmuData *pmuData, unsigned len, char *filepath, int dumpDwf); * pmuData diff --git a/docs/Go_API.md b/docs/Go_API.md index be9a7bb..5abc839 100644 --- a/docs/Go_API.md +++ b/docs/Go_API.md @@ -520,7 +520,7 @@ func main() { ### kperf.ResolvePmuDataSymbol -func ResolvePmuDataSymbol(dataVo PmuDataVo) error 当SymbolMode不设置或者设置为0时,可通过该接口解析PmuRead返回的PmuData数据中的符号 +func ResolvePmuDataSymbol(dataVo PmuDataVo) error 当SymbolMode设置为3或者4时,可通过该接口解析PmuRead返回的PmuData数据中的符号 ```go import "libkperf/kperf" import "fmt" diff --git a/docs/Python_API.md b/docs/Python_API.md index a822acd..7d9d7af 100644 --- a/docs/Python_API.md +++ b/docs/Python_API.md @@ -490,7 +490,7 @@ kperf.close_cpu_freq_sampling() ### kperf.resolvePmuDataSymbol -def resolvePmuDataSymbol(pmuData: PmuData) -> int: 当SymbolMode不设置或者设置为0时,可通过该接口解析read返回的PmuData数据中的符号 +def resolvePmuDataSymbol(pmuData: PmuData) -> int: 当SymbolMode设置为3或者4时,可通过该接口解析read返回的PmuData数据中的符号 ```python #python代码示例 import kperf @@ -502,6 +502,7 @@ pmu_attr = kperf.PmuAttr( sampleRate=1000, callStack=True, useFreq=True, + symMode=kperf.RESOLVE_DELAY_ELF, ) fd = kperf.open(kperf.PmuTaskType.SAMPLING, pmu_attr) if fd == -1: diff --git a/go/src/libkperf/kperf/kperf.go b/go/src/libkperf/kperf/kperf.go index 8dd4886..f006dc6 100644 --- a/go/src/libkperf/kperf/kperf.go +++ b/go/src/libkperf/kperf/kperf.go @@ -220,6 +220,8 @@ var ( var ( ELF C.enum_SymbolMode = C.RESOLVE_ELF ELF_DWARF C.enum_SymbolMode = C.RESOLVE_ELF_DWARF + DELAY_ELF C.enum_SymbolMode = C.RESOLVE_DELAY_ELF + DELAY_DWARF C.enum_SymbolMode = C.RESOLVE_DELAY_DWARF ) // spe filter, for pmuAttr.DataFilter @@ -897,7 +899,7 @@ func PmuDumpData(dataVo PmuDataVo, filePath string, dumpDwf bool) error { return nil } -// When symbol mode is SNO_SYMBOL_RESOLVE, you can use this resolve PmuData Symbol after PmuRead function +// When symbol mode is RESOLVE_DELAY_ELF or RESOLVE_DELAY_DWARF, you can use this resolve PmuData Symbol after PmuRead function // param PmuDataVo the data from PmuRead // return nil indicates resolve success, otherwise return error code func ResolvePmuDataSymbol(dataVo PmuDataVo) error { diff --git a/go/src/libkperf_test/libkperf_test.go b/go/src/libkperf_test/libkperf_test.go index dadf2e8..1f1c0d4 100644 --- a/go/src/libkperf_test/libkperf_test.go +++ b/go/src/libkperf_test/libkperf_test.go @@ -321,7 +321,7 @@ func TestPmuGetCpuFreqDetail(t *testing.T) { } func TestResolvePmuDataSymbol(t *testing.T) { - attr := kperf.PmuAttr{EvtList:[]string{"cycles"}, CallStack:true, SampleRate: 1000, UseFreq:true} + attr := kperf.PmuAttr{EvtList:[]string{"cycles"}, CallStack:true, SampleRate: 1000, UseFreq:true, SymbolMode: kperf.DELAY_DWARF} fd, err := kperf.PmuOpen(kperf.SAMPLE, attr) if err != nil { t.Fatalf("kperf pmuopen sample failed, expect err is nil, but is %v", err) diff --git a/include/pmu.h b/include/pmu.h index 076c40e..edc514c 100644 --- a/include/pmu.h +++ b/include/pmu.h @@ -56,12 +56,16 @@ enum SpeEventFilter { }; enum SymbolMode { - // in PmuData will be set to NULL. + // don't load the elf and dwarf. in PmuData will be set to NULL. NO_SYMBOL_RESOLVE = 0, // Resolve elf only. Fields except lineNum and fileName in Symbol will be valid. RESOLVE_ELF = 1, // Resolve elf and dwarf. All fields in Symbol will be valid. - RESOLVE_ELF_DWARF = 2 + RESOLVE_ELF_DWARF = 2, + // Load elf. The ResolvePmuDataSymbol can be called to obtain elf information. + RESOLVE_DELAY_ELF = 3, + // Load elf and dwarf. The ResolvePmuDataSymbol can be called to obtain elf information and dwarf information. + RESOLVE_DELAY_DWARF = 4 }; enum BranchSampleFilter { @@ -399,7 +403,7 @@ int PmuRead(int pd, struct PmuData** pmuData); /** * @brief -* When symbol mode is NO_SYMBOL_RESOLVE, you can use this resolve PmuData Symbol after PmuRead function +* When symbol mode is RESOLVE_DELAY_ELF or RESOLVE_DELAY_DWARF, you can use this resolve PmuData Symbol after PmuRead function * @param pmuData the data from PmuRead * @return 0 indicates resolve success, otherwise return error code */ diff --git a/pmu/pmu_list.cpp b/pmu/pmu_list.cpp index af9b357..6fff5d2 100644 --- a/pmu/pmu_list.cpp +++ b/pmu/pmu_list.cpp @@ -697,7 +697,10 @@ namespace KUNPENG_PMU { SymResolverRecordModuleNoDwarf(pmuData.pid); } else if (symMode == RESOLVE_ELF_DWARF) { SymResolverRecordModule(pmuData.pid); - } else if (symMode == NO_SYMBOL_RESOLVE) { + } else if (symMode == RESOLVE_DELAY_ELF) { + SymResolverRecordModuleNoDwarf(pmuData.pid); + continue; + } else if (symMode == RESOLVE_DELAY_DWARF) { SymResolverRecordModule(pmuData.pid); continue; } else { diff --git a/pmu/sampler.cpp b/pmu/sampler.cpp index 72c2017..cbca8d7 100644 --- a/pmu/sampler.cpp +++ b/pmu/sampler.cpp @@ -297,18 +297,18 @@ void KUNPENG_PMU::PerfSampler::ReadRingBuffer(EventData &eventData) } case PERF_RECORD_MMAP: { eventData.metaData.push_back(event->sample); - if (symMode == RESOLVE_ELF_DWARF || symMode == NO_SYMBOL_RESOLVE) { + if (symMode == RESOLVE_ELF_DWARF || symMode == RESOLVE_DELAY_DWARF) { SymResolverUpdateModule(event->mmap.tid, event->mmap.filename, event->mmap.addr); - } else if (symMode == RESOLVE_ELF) { + } else if (symMode == RESOLVE_ELF || symMode == RESOLVE_DELAY_ELF) { SymResolverUpdateModuleNoDwarf(event->mmap.tid, event->mmap.filename, event->mmap.addr); } break; } case PERF_RECORD_MMAP2: { eventData.metaData.push_back(event->sample); - if (symMode == RESOLVE_ELF_DWARF || symMode == NO_SYMBOL_RESOLVE) { + if (symMode == RESOLVE_ELF_DWARF || symMode == RESOLVE_DELAY_DWARF) { SymResolverUpdateModule(event->mmap2.tid, event->mmap2.filename, event->mmap2.addr); - } else if (symMode == RESOLVE_ELF) { + } else if (symMode == RESOLVE_ELF || symMode == RESOLVE_DELAY_ELF) { SymResolverUpdateModuleNoDwarf(event->mmap2.tid, event->mmap2.filename, event->mmap2.addr); } break; diff --git a/pmu/spe.cpp b/pmu/spe.cpp index 5f178cf..c55c316 100644 --- a/pmu/spe.cpp +++ b/pmu/spe.cpp @@ -418,14 +418,14 @@ int Spe::CoreDummyData(struct SpeCoreContext *context, struct ContextSwitchData if (header->type == PERF_RECORD_MMAP) { struct PerfRecordMmap *sample = (struct PerfRecordMmap *)header; - if (symbolMode == RESOLVE_ELF_DWARF || symbolMode == NO_SYMBOL_RESOLVE) { + if (symbolMode == RESOLVE_ELF_DWARF || symbolMode == RESOLVE_DELAY_DWARF) { int ret = SymResolverUpdateModule(sample->tid, sample->filename, sample->addr); if (ret != SUCCESS) { // if the module fails to be updated, a warning is recorded to overwrite the failure error code. SetWarn(ret, Perror()); New(SUCCESS); } - } else if (symbolMode == RESOLVE_ELF) { + } else if (symbolMode == RESOLVE_ELF || symbolMode == RESOLVE_DELAY_ELF) { int ret = SymResolverUpdateModuleNoDwarf(sample->tid, sample->filename, sample->addr); if (ret != SUCCESS) { // if the module fails to be updated, a warning is recorded to overwrite the failure error code. diff --git a/python/modules/kperf/pmu.py b/python/modules/kperf/pmu.py index 98033f9..a61bc81 100644 --- a/python/modules/kperf/pmu.py +++ b/python/modules/kperf/pmu.py @@ -115,11 +115,12 @@ class BranchSampleFilter: KPERF_SAMPLE_BRANCH_NO_CYCLES = 1 << 15 KPERF_SAMPLE_BRANCH_TYPE_SAVE = 1 << 16 - class SymbolMode: - NO_SYMBOL_RESOLVE = 0 # in PmuData will be set to NULL. - RESOLVE_ELF = 1 # Resolve elf only. Fields except lineNum and fileName in Symbol will be valid. - RESOLVE_ELF_DWARF = 2 # Resolve elf and dwarf. All fields in Symbol will be valid. + NO_SYMBOL_RESOLVE = 0 # don't load the elf and dwarf. in PmuData will be set to NULL. + RESOLVE_ELF = 1 # Resolve elf only. Fields except lineNum and fileName in Symbol will be valid. + RESOLVE_ELF_DWARF = 2 # Resolve elf and dwarf. All fields in Symbol will be valid. + RESOLVE_DELAY_ELF = 3 # Load elf. The ResolvePmuDataSymbol can be called to obtain elf information. + RESOLVE_DELAY_DWARF = 4 # Load elf and dwarf. The ResolvePmuDataSymbol can be called to obtain elf information and dwarf information. class PmuDeviceMetric: # Perchannel metric. @@ -481,7 +482,7 @@ def read(pd): def resolvePmuDataSymbol(pmuData): """ - when kperf symbol mode is NO_SYMBOL_RESOLVE during PmuRead(), this function can be used to resolve stack symbols + when kperf symbol mode is RESOLVE_DELAY_ELF or RESOLVE_DELAY_DWARF during PmuRead(), this function can be used to resolve stack symbols :param: pmuData :return: pmu data """ diff --git a/tools/cache_collect/collect.cpp b/tools/cache_collect/collect.cpp index 923c94c..793d892 100644 --- a/tools/cache_collect/collect.cpp +++ b/tools/cache_collect/collect.cpp @@ -359,7 +359,7 @@ void collectMiss(CollectArgs& args) attr.numEvtAttr = cfg.baseEvents.size(); attr.callStack = 1; attr.excludeKernel = true; - attr.symbolMode = NO_SYMBOL_RESOLVE; + attr.symbolMode = RESOLVE_DELAY_DWARF; attr.freq = args.frequency; attr.useFreq = 1; attr.pidList = args.pids.data(); -- Gitee