diff --git a/pmu/evt.h b/pmu/evt.h index a9e259888d3aa4822acf3a5179d4821fa4a00f04..98683081b50883df9c97ef7ac765ec93b63c2763 100644 --- a/pmu/evt.h +++ b/pmu/evt.h @@ -44,7 +44,7 @@ public: virtual int Init() = 0; - virtual int Read(std::vector &data, std::vector &sampleIps) = 0; + virtual int Read(std::vector &data, std::vector &sampleIps, std::vector &extPool) = 0; virtual int MapPerfAttr() = 0; diff --git a/pmu/evt_list.cpp b/pmu/evt_list.cpp index 5323fb73e5e7d7a7253bc6ac175f83889d6efefc..4563787d2b2763e85411c92a0d06cc72576db7e5 100644 --- a/pmu/evt_list.cpp +++ b/pmu/evt_list.cpp @@ -152,7 +152,7 @@ void KUNPENG_PMU::EvtList::FillFields( } } -int KUNPENG_PMU::EvtList::Read(vector &data, std::vector &sampleIps) +int KUNPENG_PMU::EvtList::Read(vector &data, std::vector &sampleIps, std::vector &extPool) { for (unsigned int row = 0; row < numCpu; row++) { for (unsigned int col = 0; col < numPid; col++) { @@ -168,7 +168,7 @@ int KUNPENG_PMU::EvtList::Read(vector &data, std::vector auto cpuTopo = this->cpuList[row].get(); for (unsigned int col = 0; col < numPid; col++) { auto cnt = data.size(); - int err = this->xyCounterArray[row][col]->Read(data, sampleIps); + int err = this->xyCounterArray[row][col]->Read(data, sampleIps, extPool); if (err != SUCCESS) { return err; } diff --git a/pmu/evt_list.h b/pmu/evt_list.h index 1a54b7d89a4b16c792a7530881ecd777483119e2..b507bf0acca78cd5dc39b8e55fcb2e0ee04dacb5 100644 --- a/pmu/evt_list.h +++ b/pmu/evt_list.h @@ -45,7 +45,7 @@ public: int Enable(); int Stop(); int Reset(); - int Read(std::vector &pmuData, std::vector &sampleIps); + int Read(std::vector &pmuData, std::vector &sampleIps, std::vector &extPool); void SetTimeStamp(const int64_t ×tamp) { diff --git a/pmu/perf_counter.cpp b/pmu/perf_counter.cpp index 6262003f699b7ecca854fb58be7f21ff88d6cb7d..1b5e3199fff7cdc26b3df06107308d7e1981d3aa 100644 --- a/pmu/perf_counter.cpp +++ b/pmu/perf_counter.cpp @@ -36,7 +36,7 @@ static constexpr int MAX_ATTR_SIZE = 120; * Right now we do not implement grouping logic, thus we ignore the * PERF_FORMAT_ID section for now */ -int KUNPENG_PMU::PerfCounter::Read(vector &data, std::vector &sampleIps) +int KUNPENG_PMU::PerfCounter::Read(vector &data, std::vector &sampleIps, std::vector &extPool) { struct ReadFormat perfCountValue; diff --git a/pmu/perf_counter.h b/pmu/perf_counter.h index 19628fce937d1869ba4894efccd96367d6c2555d..289a7c333fb3085784cdca1061ad4d12c611af84 100644 --- a/pmu/perf_counter.h +++ b/pmu/perf_counter.h @@ -36,7 +36,7 @@ namespace KUNPENG_PMU { ~PerfCounter() {} int Init() override; - int Read(std::vector &data, std::vector &sampleIps) override; + int Read(std::vector &data, std::vector &sampleIps, std::vector &extPool) override; int MapPerfAttr() override; }; } // namespace KUNPENG_PMU diff --git a/pmu/pmu_list.cpp b/pmu/pmu_list.cpp index 9117b7573d8501f80d07725a73a1ad76f234c49d..e85c52b400280aba8b4d2e9a70c573ff323d02e8 100644 --- a/pmu/pmu_list.cpp +++ b/pmu/pmu_list.cpp @@ -159,7 +159,7 @@ namespace KUNPENG_PMU { auto eventList = GetEvtList(pd); for (auto item : eventList) { item->SetTimeStamp(ts); - auto err = item->Read(evtData.data, evtData.sampleIps); + auto err = item->Read(evtData.data, evtData.sampleIps, evtData.extPool); if (err != SUCCESS) { return err; } @@ -403,6 +403,9 @@ namespace KUNPENG_PMU { if (findData == userDataList.end()) { return; } + for (auto &extMem : findData->second.extPool) { + delete[] extMem; + } userDataList.erase(pmuData); } @@ -587,4 +590,4 @@ namespace KUNPENG_PMU { lock_guard lg(dataListMtx); return symModeList[pd]; } -} \ No newline at end of file +} diff --git a/pmu/pmu_list.h b/pmu/pmu_list.h index 91994d85ef5108579aeaf012e1688de00b89d783..9af49061402e1d43b29a95efed4ddda0cb484967 100644 --- a/pmu/pmu_list.h +++ b/pmu/pmu_list.h @@ -82,6 +82,7 @@ private: PmuTaskType collectType; std::vector data; std::vector sampleIps; + std::vector extPool; }; void InsertEvtList(const unsigned pd, std::shared_ptr evtList); diff --git a/pmu/sampler.cpp b/pmu/sampler.cpp index f8ad789527632933ebb858d17755ef461c447ce4..73fcf41dba6d96ae4293bf88d47942a8c9675fe3 100644 --- a/pmu/sampler.cpp +++ b/pmu/sampler.cpp @@ -160,11 +160,15 @@ void KUNPENG_PMU::PerfSampler::ReadRingBuffer(vector &data, vectormmap.tid, event->mmap.filename, event->mmap.addr); + if (symMode != NO_SYMBOL_RESOLVE) { + SymResolverUpdateModule(event->mmap.tid, event->mmap.filename, event->mmap.addr); + } break; } case PERF_RECORD_MMAP2: { - SymResolverUpdateModule(event->mmap2.tid, event->mmap2.filename, event->mmap2.addr); + if (symMode != NO_SYMBOL_RESOLVE) { + SymResolverUpdateModule(event->mmap2.tid, event->mmap2.filename, event->mmap2.addr); + } break; } case PERF_RECORD_FORK: { @@ -192,7 +196,7 @@ void KUNPENG_PMU::PerfSampler::FillComm(const size_t &start, const size_t &end, } } -int KUNPENG_PMU::PerfSampler::Read(vector &data, std::vector &sampleIps) +int KUNPENG_PMU::PerfSampler::Read(vector &data, std::vector &sampleIps, std::vector &extPool) { auto err = this->ReadInit(); if (__glibc_unlikely(err != SUCCESS)) { diff --git a/pmu/sampler.h b/pmu/sampler.h index e9ab432c6b15796345c095aecb5af88f3570a9ff..3dba2d80b7dbd1e80319c4803e7e41f46126f57c 100644 --- a/pmu/sampler.h +++ b/pmu/sampler.h @@ -40,7 +40,7 @@ namespace KUNPENG_PMU { {} int Init() override; - int Read(std::vector &data, std::vector &sampleIps) override; + int Read(std::vector &data, std::vector &sampleIps, std::vector &extPool) override; int MapPerfAttr() override; diff --git a/pmu/spe.cpp b/pmu/spe.cpp index 8470edd406889d0695d36e831bc14d485f799700..81b3de66f8ab2c2426ef83e4296630f13fc77d7f 100644 --- a/pmu/spe.cpp +++ b/pmu/spe.cpp @@ -358,7 +358,7 @@ void Spe::CoreDummyData(struct SpeCoreContext *context, struct ContextSwitchData uint64_t off = dataTail % mpage->data_size; struct perf_event_header *header = (struct perf_event_header *)(ringBuf + off); - if (header->type == PERF_RECORD_MMAP) { + if (header->type == PERF_RECORD_MMAP && symbolMode != NO_SYMBOL_RESOLVE) { struct PerfRecordMmap *sample = (struct PerfRecordMmap *)header; SymResolverUpdateModule(sample->tid, sample->filename, sample->addr); dataTail += header->size; diff --git a/pmu/spe.h b/pmu/spe.h index 7e5697fd9e9453889347985f572fd386a16e1e9d..a954913830ae01abcced8d3ad07c9d89a547a3f8 100644 --- a/pmu/spe.h +++ b/pmu/spe.h @@ -128,8 +128,8 @@ struct SampleId { */ class Spe { public: - explicit Spe(int cpu, std::unordered_map> &procMap) - : cpu(cpu), procMap(procMap) + explicit Spe(int cpu, std::unordered_map> &procMap, SymbolMode symMode) + : cpu(cpu), procMap(procMap), symbolMode(symMode) {} ~Spe() @@ -209,6 +209,7 @@ private: const unsigned short READ = 1 << 3; int cpu = 0; + SymbolMode symbolMode = NO_SYMBOL_RESOLVE; SpeContext *ctx = nullptr; unsigned short status = NONE; int dummyFd = 0; diff --git a/pmu/spe_sampler.cpp b/pmu/spe_sampler.cpp index 9cca5e49e38ebaf9e6ca21c1a3464eec4cd09fdc..c1af3032d765b3ebee1c67d18565014e01ddcc3f 100644 --- a/pmu/spe_sampler.cpp +++ b/pmu/spe_sampler.cpp @@ -55,7 +55,7 @@ namespace KUNPENG_PMU { return SUCCESS; } - findSpe = speSet.emplace(this->cpu, Spe(this->cpu, procMap)).first; + findSpe = speSet.emplace(this->cpu, Spe(this->cpu, procMap, symMode)).first; auto err = findSpe->second.Open(evt); if (err != SUCCESS) { speSet.erase(this->cpu); @@ -65,7 +65,7 @@ namespace KUNPENG_PMU { return SUCCESS; } - int PerfSpe::Read(vector &data, std::vector &sampleIps) + int PerfSpe::Read(vector &data, std::vector &sampleIps, std::vector &extPool) { auto findSpe = speSet.find(this->cpu); if (findSpe == speSet.end()) { @@ -90,14 +90,14 @@ namespace KUNPENG_PMU { continue; } // Insert each spe record for each tid. - InsertSpeRecords(records.first, records.second, data, sampleIps); + InsertSpeRecords(records.first, records.second, data, sampleIps, extPool); } } else { // Loop over all tids. for (auto &proc : procMap) { // Get all spe records for tid. const auto &records = findSpe->second.GetPidRecords(proc.first); - InsertSpeRecords(proc.second->tid, records, data, sampleIps); + InsertSpeRecords(proc.second->tid, records, data, sampleIps, extPool); } } @@ -105,7 +105,7 @@ namespace KUNPENG_PMU { } void PerfSpe::InsertSpeRecords( - const int &tid, const std::vector &speRecords, vector &data, vector &sampleIps) + const int &tid, const std::vector &speRecords, vector &data, vector &sampleIps, std::vector &extPool) { ProcTopology *procTopo = nullptr; auto findProc = procMap.find(tid); @@ -187,12 +187,8 @@ namespace KUNPENG_PMU { findSpe->second.Close(); speSet.erase(this->cpu); - for (auto extPtr : extPool) { - delete[] extPtr; - } - extPool.clear(); return SUCCESS; } -} // namespace KUNPENG_PMU \ No newline at end of file +} // namespace KUNPENG_PMU diff --git a/pmu/spe_sampler.h b/pmu/spe_sampler.h index 2f503ce331ecd93ca6997ad045086989484fff63..b6c342c729c55f7b17dc0ba6cc118919e03fa662 100644 --- a/pmu/spe_sampler.h +++ b/pmu/spe_sampler.h @@ -37,7 +37,7 @@ namespace KUNPENG_PMU { {} int Init() override; - int Read(std::vector &data, std::vector &sampleIps) override; + int Read(std::vector &data, std::vector &sampleIps, std::vector &extPool) override; int MapPerfAttr() override; bool Mmap(); @@ -50,10 +50,8 @@ namespace KUNPENG_PMU { private: bool SpeExist(int cpu) const; void InsertSpeRecords(const int &tid, const std::vector &speRecords, std::vector &data, - std::vector &sampleIps); + std::vector &sampleIps, std::vector &extPool); void UpdatePidList(const Spe &spe); - - std::vector extPool; }; } // namespace KUNPENG_PMU #endif