diff --git a/docs/C_C++_API.md b/docs/C_C++_API.md index 82bd6bf20d4ea18bef44cc698ce7488854f22908..3fa8b94a2012ab4e562f4f3d55bd55c4f5f48c8b 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 be9a7bbe6dd2b72a3c52bd0324c12a22077a344c..5abc839f4d116235450568cb2beb1c1cb995dfd4 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 a822acdee8dbc7c21f1400e252e9258bc5324146..7d9d7af8a3d96571634066d162a6c3d4a9dc3efa 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 8dd4886ab0f768c086ce8ef01eed371419d6b1b4..f006dc6d84d1b059604391941a6287c70b6b780c 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 dadf2e824398f39e6c0b95cc4f1acc26da5d1d45..1f1c0d4a9375efb353b8a1e562fbc709c7d28d5a 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 076c40ec70fa7ddc936d73505e7aab9e660846b5..edc514c7688a3b1d8c5f3db0168f22d9e3bda876 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 af9b3572a520d759a85fa0a78f35d9cff8f2bb26..6fff5d2880f92fb1b4c9d50719e10870a737e7c4 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 72c201776a5da8c3a399be3d8b1018bfa22eec91..cbca8d7ab11f940e35000adecf417a8af17b325d 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 5f178cfcfbfe1320c93748529113755f6d9fc2ac..c55c3163afbf841116e7f27783c544a08086d80e 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 98033f94655682425e8575a881ca9201780c5cc8..a61bc81a19f39d9fc9ebd9687c8cf07f761dfab4 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 923c94caef34502a3d11f2391c00c04b03dfda57..793d89221086bf4b81daf6a32dcf7bf1b0468a35 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();